UNPKG

@zohodesk/client_build_tool

Version:

A CLI tool to build web applications and client libraries

34 lines (26 loc) 843 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getArrayWithDefault = getArrayWithDefault; exports.updateArrayWithDefault = updateArrayWithDefault; function updateArrayWithDefault(array, defaultoptions = []) { const index = array.indexOf('...'); if (index === -1) { return array; } const newArray = [...array]; newArray.splice(index, 1, ...defaultoptions); return newArray; } const isEqualVal = (a, b) => a === b; function getArrayWithDefault(array, defaultoptions = [], isEqual = isEqualVal) { const index = array.indexOf('...'); if (index === -1) { return array; } const filteredDefaultOptions = defaultoptions.filter(v => !array.some(v1 => isEqual(v, v1))); const newArray = [...array]; newArray.splice(index, 1, ...filteredDefaultOptions); return newArray; }