@villedemontreal/workit-core
Version:
This package provides default and no-op implementations of the WorkIt types for client packages.
36 lines • 1.6 kB
JavaScript
;
/*
* Copyright (c) 2025 Ville de Montreal. All rights reserved.
* Licensed under the MIT license.
* See LICENSE file in the project root for full license information.
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.parseCommaSeparatedBaggage = exports.isEmptyArray = exports.isArrayOfFunctions = exports.andArrayWith = exports.isObject = exports.isFunction = void 0;
const isFunction = (f) => typeof f === 'function';
exports.isFunction = isFunction;
const isObject = (o) => typeof o === 'object';
exports.isObject = isObject;
/**
* Applied test function on each element on the array and ANDs the results
*/
const andArrayWith = (arr, test) => arr.reduce((bool, current) => bool && test(current), true);
exports.andArrayWith = andArrayWith;
/**
* Checks if parameter is an array of functions
*/
const isArrayOfFunctions = (a) => Array.isArray(a) && a.length > 0 && (0, exports.andArrayWith)(a, exports.isFunction);
exports.isArrayOfFunctions = isArrayOfFunctions;
const isEmptyArray = (a) => Array.isArray(a) && a.length === 0;
exports.isEmptyArray = isEmptyArray;
function parseCommaSeparatedBaggage(baggage, values) {
values.split(',').forEach((keyVal) => {
const splitKeyVal = keyVal.trim().split('=');
if (splitKeyVal.length === 2) {
const [key, val] = splitKeyVal;
// eslint-disable-next-line no-param-reassign, @typescript-eslint/no-unsafe-member-access
baggage[key] = val;
}
});
}
exports.parseCommaSeparatedBaggage = parseCommaSeparatedBaggage;
//# sourceMappingURL=utils.js.map