UNPKG

lincd

Version:

LINCD is a JavaScript library for building user interfaces with linked data (also known as 'structured data', or RDF)

101 lines 4.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CoreMap = void 0; class CoreMap extends Map { createNew(...args) { return new this.constructor(...args); } /** * Determines whether all the members of an array satisfy the specified test. * @param callbackfn A function that accepts up to three arguments. The every method calls the callbackfn function for each element in array1 until the callbackfn returns false, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ every(callbackfn, thisArg) { for (let [key, value] of this) { if (!callbackfn.apply(thisArg, [value, key, this])) { return false; } } return true; } /** * Determines whether the specified callback function returns true for any element of an array. * @param callbackfn A function that accepts up to three arguments. The some method calls the callbackfn function for each element in array1 until the callbackfn returns true, or until the end of the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ some(callbackfn, thisArg) { for (let [key, value] of this) { if (callbackfn.apply(thisArg, [value, key, this])) { return true; } } return false; } /** * Calls a defined callback function on each element of an array, and returns an array that contains the results. * @param callbackfn A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ map(callbackfn, thisArg) { //create the result map, whos values will be 'mapped' into new values from the current values of this map //var mappedMap = new (<any> this.constructor)() as CoreMap<K,U>; var mappedMap = new this.constructor(); // as CoreMap<K,U>; for (let [key, value] of this) { //do the mapping mappedMap.set(key, callbackfn.apply(thisArg, [value, key, this])); } return mappedMap; } /** * Returns the elements of an array that meet the condition specified in a callback function. * @param callbackfn A function that accepts up to three arguments. The filter method calls the callbackfn function one time for each element in the array. * @param thisArg An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. */ filter(callbackfn, thisArg) { //create the result map, whos values will be 'mapped' into new values from the current values of this map var filteredMap = new this.constructor(); //this.createNew();//new Map<K,V>(); for (let [key, value] of this) { //do the mapping if (callbackfn.apply(thisArg, [value, key, this])) { filteredMap.set(key, value); } } return filteredMap; } first() { return this.values().next().value; } /** * Returns the value of the first element in the Set where predicate is true, and undefined * otherwise. */ find(predicate, thisArg) { for (let [key, value] of this) { if (predicate.apply(thisArg, [value, key, this])) { return value; } } return undefined; } merge(...maps) { var res = this.createNew(this); for (var map of maps) { map.forEach((value, index) => { res.set(index, value); }); } return res; } toString() { let res = 'Map:\n'; for (let [key, value] of this) { res += '\t[' + key.toString() + '] => ' + value.toString() + '\n'; } return res; } print() { console.log(this.toString()); } } exports.CoreMap = CoreMap; //# sourceMappingURL=CoreMap.js.map