/**
 * @license
 * Copyright 2019 Red Hat
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
var JsonCompat = /** @class */ (function () {
    function JsonCompat() {
    }
    /****** Utility ******/
    JsonCompat.stringify = function (json) {
        return JSON.stringify(json);
    };
    JsonCompat.parseJSON = function (jsonString) {
        return JSON.parse(jsonString);
    };
    JsonCompat.clone = function (json) {
        return JSON.parse(JSON.stringify(json));
    };
    JsonCompat.objectNode = function () {
        return {};
    };
    JsonCompat.arrayNode = function () {
        return [];
    };
    JsonCompat.nullNode = function () {
        return null;
    };
    JsonCompat.isPropertyDefined = function (json, propertyName) {
        return json && json[propertyName] != null && json[propertyName] != undefined;
    };
    JsonCompat.parseObject = function (json) {
        return json;
    };
    JsonCompat.removeNullProperties = function (object) {
        if (object instanceof Array) {
            for (var _i = 0, _a = object; _i < _a.length; _i++) {
                var item = _a[_i];
                this.removeNullProperties(item);
            }
        }
        else if (object instanceof Object) {
            for (var key in object) {
                if (object[key] == null) {
                    delete object[key];
                }
                else {
                    this.removeNullProperties(object[key]);
                }
            }
        }
        return object;
    };
    JsonCompat.isString = function (json) {
        return typeof json === "string";
    };
    JsonCompat.isNumber = function (json) {
        return typeof json === "number";
    };
    JsonCompat.isObject = function (json) {
        if (json == null || json == undefined) {
            return false;
        }
        return typeof json === "object";
    };
    JsonCompat.isNull = function (json) {
        return json == null || json == undefined;
    };
    JsonCompat.isBoolean = function (json) {
        return typeof json === "boolean";
    };
    JsonCompat.toBoolean = function (json) {
        return json;
    };
    JsonCompat.toString = function (json) {
        return json;
    };
    JsonCompat.toNumber = function (json) {
        return json;
    };
    JsonCompat.isArray = function (json) {
        if (!json) {
            return false;
        }
        return Array.isArray(json);
    };
    JsonCompat.toList = function (json) {
        return json;
    };
    /****** Getters ******/
    JsonCompat.keys = function (json) {
        if (!json) {
            return [];
        }
        return Object.keys(json);
    };
    JsonCompat.getProperty = function (json, propertyName) {
        var rval = json[propertyName];
        if (rval === undefined) {
            rval = null;
        }
        return rval;
    };
    JsonCompat.consumeProperty = function (json, propertyName) {
        var rval = JsonCompat.getProperty(json, propertyName);
        delete json[propertyName];
        return rval;
    };
    JsonCompat.getPropertyObject = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyObject = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    JsonCompat.getPropertyArray = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyArray = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    JsonCompat.getPropertyString = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyString = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    JsonCompat.getPropertyBoolean = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyBoolean = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    JsonCompat.getPropertyNumber = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyNumber = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    JsonCompat.getPropertyStringArray = function (json, propertyName) {
        return JsonCompat.getProperty(json, propertyName);
    };
    JsonCompat.consumePropertyStringArray = function (json, propertyName) {
        return JsonCompat.consumeProperty(json, propertyName);
    };
    /****** Setters ******/
    JsonCompat.setPropertyNull = function (json, propertyName) {
        json[propertyName] = null;
    };
    JsonCompat.setProperty = function (json, propertyName, propertyValue) {
        json[propertyName] = propertyValue;
    };
    JsonCompat.setPropertyString = function (json, propertyName, propertyValue) {
        JsonCompat.setProperty(json, propertyName, propertyValue);
    };
    JsonCompat.setPropertyBoolean = function (json, propertyName, propertyValue) {
        JsonCompat.setProperty(json, propertyName, propertyValue);
    };
    JsonCompat.setPropertyNumber = function (json, propertyName, propertyValue) {
        JsonCompat.setProperty(json, propertyName, propertyValue);
    };
    JsonCompat.setPropertyStringArray = function (json, propertyName, propertyValue) {
        JsonCompat.setProperty(json, propertyName, propertyValue);
    };
    JsonCompat.appendToArrayProperty = function (json, arrayPropertyName, propertyValue) {
        if (!JsonCompat.isPropertyDefined(json, arrayPropertyName)) {
            JsonCompat.setProperty(json, arrayPropertyName, [propertyValue]);
        }
        else {
            var array = json[arrayPropertyName];
            array.push(propertyValue);
        }
    };
    JsonCompat.appendToArray = function (jsonArray, propertyValue) {
        jsonArray.push(propertyValue);
        return jsonArray;
    };
    JsonCompat.setToArrayIndex = function (jsonArray, index, propertyValue) {
        jsonArray[index] = propertyValue;
    };
    JsonCompat.mapToList = function (items) {
        var res = ([]);
        if (items) {
            Object.getOwnPropertyNames(items).forEach(function (key) {
                var e = items[key];
                if (e) {
                    res.push(e);
                }
            });
        }
        return res;
    };
    return JsonCompat;
}());
export { JsonCompat };
//# sourceMappingURL=JsonCompat.js.map