UNPKG

semantic-network

Version:

A utility library for manipulating a list of links that form a semantic interface to a network of resources.

74 lines 2.78 kB
"use strict"; var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SingletonMerger = exports.options = exports.createInstance = exports.defaultOptions = void 0; exports.defaultOptions = {}; var optionsInstance; var createInstance = function (options) { if (!optionsInstance) { optionsInstance = __assign(__assign({}, exports.defaultOptions), options); } return optionsInstance; }; exports.createInstance = createInstance; exports.options = (0, exports.createInstance)(); /** * A helper class for manipulating items in a {@link SingletonRepresentation}. */ var SingletonMerger = /** @class */ (function () { function SingletonMerger() { } /** * Copy the values of all the enumerable own properties from one or more source objects to a target object. * Returns the target object. * * @param target The target object to copy to * @param source The source object from which to copy properties * @param options */ SingletonMerger.merge = function (target, source, options) { var _a = __assign({}, options).set, set = _a === void 0 ? optionsInstance.set : _a; if (set) { for (var key in source) { set(target, key, source[key]); } return target; } /** ensure that the original object (and bindings) are returned—ie don't use spread */ return Object.assign(target, source); }; /** * Adds a resource object to the target object on the named property. * Returns the target object * * @param target The target object to add a resource to * @param prop The property name to be added to the target * @param resource The resource object that is added to the target * @param options */ SingletonMerger.add = function (target, prop, resource, options) { var _a; var _b = __assign({}, options).set, set = _b === void 0 ? optionsInstance.set : _b; if (set) { set(target, prop, resource); } else { /** ensure that the original object (and bindings) are returned—ie don't use spread */ Object.assign(target, (_a = {}, _a[prop] = resource, _a)); } return target; }; return SingletonMerger; }()); exports.SingletonMerger = SingletonMerger; //# sourceMappingURL=singletonMerger.js.map