confinode
Version:
Node application configuration reader
36 lines • 1.17 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
/**
* Push the item in the array if the item is defined and not already in the array.
*
* @param array - The array in which item is to be pushed.
* @param item - The item to push.
* @param predicate - The predicate to see if item is already in the array.
*/
function pushIfNew(array, item, predicate) {
!!item && !array.find(arrayItem => predicate(arrayItem)) && array.push(item);
}
exports.pushIfNew = pushIfNew;
/**
* A predicate to use as an array filter in order to remove duplicates.
*
* @param value - The value to test.
* @param index - The index of the current value.
* @param array - The array.
* @returns True if value is unique.
*/
function unique(value, index, array) {
return array.indexOf(value) === index;
}
exports.unique = unique;
/**
* Ensure that the given parameter is an array. If not, put it in an array.
*
* @param value - Either an array or a single item to convert.
* @returns The parameter in an array.
*/
function ensureArray(value) {
return new Array().concat(value);
}
exports.ensureArray = ensureArray;
//# sourceMappingURL=array.js.map