UNPKG

@wizard9/json-patch-apply

Version:

A library for describing, calculating, and applying patches to Javascript Objects.

53 lines (50 loc) 1.84 kB
"use strict"; /** This file is part of json-patch-apply. json-patch-apply is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version. json-patch-apply is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with json-patch-apply. If not, see <https://www.gnu.org/licenses/>. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.ValueType = exports.getValueType = exports.firstElement = exports.getValue = exports.hasKey = void 0; function hasKey(obj, k) { return k in obj; } exports.hasKey = hasKey; function getValue(obj, key) { return hasKey(obj, key) ? obj[key] : undefined; } exports.getValue = getValue; function firstElement(ops) { let first = ops.shift(); if (first == undefined) { throw new Error("cannot get first of empty list"); } return first; } exports.firstElement = firstElement; function getValueType(target) { let type = ValueType.primitive; if (target instanceof Array) { type = ValueType.array; } else if (target instanceof Object) { type = ValueType.object; } return type; } exports.getValueType = getValueType; var ValueType; (function (ValueType) { ValueType[ValueType["primitive"] = 0] = "primitive"; ValueType[ValueType["array"] = 1] = "array"; ValueType[ValueType["object"] = 2] = "object"; })(ValueType = exports.ValueType || (exports.ValueType = {})); //# sourceMappingURL=common.js.map