UNPKG

semantic-network

Version:

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

54 lines 1.94 kB
export const defaultOptions = {}; let optionsInstance; export const createInstance = (options) => { if (!optionsInstance) { optionsInstance = Object.assign(Object.assign({}, defaultOptions), options); } return optionsInstance; }; export const options = createInstance(); /** * A helper class for manipulating items in a {@link SingletonRepresentation}. */ export class 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 */ static merge(target, source, options) { const { set = optionsInstance.set } = Object.assign({}, options); if (set) { for (const 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 */ static add(target, prop, resource, options) { const { set = optionsInstance.set } = Object.assign({}, options); if (set) { set(target, prop, resource); } else { /** ensure that the original object (and bindings) are returned—ie don't use spread */ Object.assign(target, { [prop]: resource }); } return target; } } //# sourceMappingURL=singletonMerger.js.map