@agnostack/verifyd
Version:
Please contact agnoStack via info@agnostack.com for any questions
513 lines • 26.6 kB
JavaScript
;
/* eslint-disable no-use-before-define */
// #region lib-core
// TODO!!!: keep in sync between next-shopify and lib-core (AND lib-utils-js at bottom)
Object.defineProperty(exports, "__esModule", { value: true });
exports.snakecase = exports.undashcase = exports.dashcase = exports.zencase = exports.replaceSpaces = exports.freeze = exports.isHTML = exports.objectToSortedString = exports.compareEntryKeys = exports.compareString = exports.compareNumber = exports.stringEmpty = exports.stringNotEmpty = exports.stringEmptyOnly = exports.stringNotEmptyOnly = exports.cleanObject = exports.cleanObjectKeys = exports.objectContainsAnyValue = exports.nullable = exports.objectNotEmpty = exports.objectEmpty = exports.ensureObject = exports.findLastMatch = exports.arrayNotEmpty = exports.arrayEmpty = exports.ensureArraySet = exports.ensureArray = exports.ensureNumericConstrained = exports.ensureNumericNegatable = exports.ensureNumericOnly = exports.ensureNumeric = exports.isNumericNegatable = exports.isNumericOnly = exports.ensureAlphaNumeric = exports.ensureStringClean = exports.ensureStringAscii = exports.ensureStringOnly = exports.ensureString = exports.safeParse = exports.isParseable = exports.safeTrim = exports.isTypeEnhanced = exports.isString = exports.isType = exports.isSet = exports.isArray = exports.arrayRandomItem = exports.arrayRandom = exports.nextRandom = exports.random = void 0;
exports.appendParams = exports.appendQuery = exports.arraysMatch = exports.arrayIncludesAll = exports.querystringToObject = exports.querystringToParams = exports.parseKeywordGroups = exports.parseCommaGroups = exports.parseKeywords = exports.getBaseDomain = exports.isBoolean = exports.isUndefinedOrTrue = exports.isTrue = exports.arrayToObject = exports.normalizeArray = exports.combineCommas = exports.splitCommas = exports.wrappedEncode = exports.ensureExtension = exports.ensureTrailingQuestion = exports.ensureTrailingSlash = exports.ensureLeadingSlash = exports.removeLeadingTrailingSlash = exports.removeTrailingSlash = exports.removeLeadingTrailingQuotes = exports.removeLeadingSlash = exports.titleCase = exports.camelCase = exports.capitalize = exports.slugify = exports.isLowercase = exports.lowercase = exports.uppercase = exports.unsnakecase = void 0;
const REACT_SYMBOL = Symbol.for('react.element');
const random = (max = 100, min = 1) => {
const floor = Math.min(max, min);
return Math.floor(Math.random() * (max - floor + 1)) + floor;
};
exports.random = random;
const nextRandom = (max = 100, min = 1) => {
const maximum = Math.max(max, 0);
const minimum = Math.max(min, 0);
let randomNumber = maximum;
if (maximum > minimum) {
do {
randomNumber = (0, exports.random)(maximum, minimum);
} while (randomNumber === exports.nextRandom.last);
exports.nextRandom.last = randomNumber;
}
return randomNumber;
};
exports.nextRandom = nextRandom;
const arrayRandom = (_values, _max = 1) => {
const values = (0, exports.ensureArray)(_values);
const valuesLength = values.length;
const maxLength = Math.min(_max, valuesLength);
if (valuesLength <= maxLength) {
return values;
}
const arrayLength = valuesLength - 1;
const randomValues = [];
do {
const newVal = values[(0, exports.nextRandom)(arrayLength, 0)];
if (!randomValues.includes(newVal)) {
randomValues.push(newVal);
}
} while (randomValues.length < maxLength);
return randomValues;
};
exports.arrayRandom = arrayRandom;
const arrayRandomItem = (_values) => ((0, exports.arrayRandom)(_values)[0]);
exports.arrayRandomItem = arrayRandomItem;
const isArray = (value) => (
// eslint-disable-next-line eqeqeq
(value != undefined) && Array.isArray(value));
exports.isArray = isArray;
const isSet = (value) => (
// eslint-disable-next-line eqeqeq
(value != undefined) && (value instanceof Set));
exports.isSet = isSet;
const isType = (value, type) => (
// eslint-disable-next-line eqeqeq, valid-typeof
(value != undefined) && (typeof value === type));
exports.isType = isType;
const isString = (value) => ((0, exports.isType)(value, 'string') ||
(value instanceof String));
exports.isString = isString;
const isReact = (value) => ((0, exports.isType)(value, 'object') &&
((value === null || value === void 0 ? void 0 : value.$$typeof) === REACT_SYMBOL));
const isClass = (value) => ((0, exports.isType)(value, 'object') &&
(Object.getPrototypeOf(value) !== Object.prototype) &&
!isReact(value));
const isTypeEnhanced = (value, type) => {
switch (true) {
case (type === 'boolean'): {
return (0, exports.isType)(value, type) || ['true', 'false'].includes(value);
}
case (type === 'string'): {
return (0, exports.isString)(value);
}
case (type === 'set'): {
return (0, exports.isSet)(value);
}
case (type === 'react'): {
return isReact(value);
}
case (type === 'class'): {
return isClass(value);
}
case (type === 'array'): {
return ((0, exports.isArray)(value) &&
!(0, exports.isSet)(value));
}
case (type === 'object'): {
return ((0, exports.isType)(value, type) &&
!(0, exports.isArray)(value) &&
!isClass(value) &&
!(0, exports.isString)(value) &&
!isReact(value));
}
default: {
return (0, exports.isType)(value, type);
}
}
};
exports.isTypeEnhanced = isTypeEnhanced;
const safeTrim = (value) => {
if ((0, exports.isTypeEnhanced)(value, 'string')) {
// eslint-disable-next-line no-param-reassign
value = value.trim();
}
return value;
};
exports.safeTrim = safeTrim;
const isParseable = (value, trim, matchQuoted) => {
if (!(0, exports.isTypeEnhanced)(value, 'string')) {
return false;
}
if (trim) {
// eslint-disable-next-line no-param-reassign
value = (0, exports.safeTrim)(value);
}
return (0, exports.isTrue)(value.startsWith('{') || value.startsWith('[') || (matchQuoted && value.startsWith('"')));
};
exports.isParseable = isParseable;
const safeParse = (value, trim) => {
switch (true) {
case (0, exports.isTypeEnhanced)(value, 'object'):
case (0, exports.isTypeEnhanced)(value, 'array'): {
return value;
}
case (0, exports.isParseable)(value, trim, true): {
if (trim) {
// eslint-disable-next-line no-param-reassign
value = (0, exports.safeTrim)(value);
}
try {
return JSON.parse(value);
}
catch (_ignore) {
console.info('Ignoring error parsing', _ignore);
// TODO: should this be value ?? {}
return value;
}
}
default: {
// TODO: should this be value ?? {}
return value;
}
}
};
exports.safeParse = safeParse;
const ensureString = (string) => (string ? `${string}` : '');
exports.ensureString = ensureString;
// HMMM: what if 'string' is an object?
const ensureStringOnly = (string) => (
// eslint-disable-next-line eqeqeq
(string != undefined) ? `${string}` : '');
exports.ensureStringOnly = ensureStringOnly;
const ensureStringAscii = (string) => (
// eslint-disable-next-line no-control-regex
(0, exports.ensureStringOnly)(string).replace(/[^\x00-\x7F]/g, ''));
exports.ensureStringAscii = ensureStringAscii;
const ensureStringClean = (string) => (
// eslint-disable-next-line no-control-regex
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9_-]/gi, ''));
exports.ensureStringClean = ensureStringClean;
const ensureAlphaNumeric = (string) => (
// eslint-disable-next-line no-control-regex
(0, exports.ensureStringOnly)(string).replace(/[^a-z0-9]/gi, ''));
exports.ensureAlphaNumeric = ensureAlphaNumeric;
const isNumericOnly = (value) => {
var _a;
const [matched] = (_a = `${value}`.match(/^([0-9]+)$/)) !== null && _a !== void 0 ? _a : [];
// eslint-disable-next-line eqeqeq
return (matched != undefined);
};
exports.isNumericOnly = isNumericOnly;
const isNumericNegatable = (value) => {
var _a;
const [matched] = (_a = `${value}`.match(/^(-?[0-9]+(\.[0-9]+)?)?$/)) !== null && _a !== void 0 ? _a : [];
// eslint-disable-next-line eqeqeq
return (matched != undefined);
};
exports.isNumericNegatable = isNumericNegatable;
// TODO: explore places using ensureNumeric to move to isNumericNegatable
const ensureNumeric = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.]/gi, '')));
exports.ensureNumeric = ensureNumeric;
const ensureNumericOnly = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9]/gi, '')));
exports.ensureNumericOnly = ensureNumericOnly;
// TODO: update regex to handle negative number returns negative. Something like (?!\d\.)(-?\d+(\.\d)?)
const ensureNumericNegatable = (string) => (Number((0, exports.ensureString)(string).replace(/[^0-9.-]/gi, '')));
exports.ensureNumericNegatable = ensureNumericNegatable;
const ensureNumericConstrained = (value, { min: _min = 0, max: _max = 100 } = {}) => {
const min = (0, exports.ensureNumericNegatable)(_min);
const max = (0, exports.ensureNumericNegatable)(_max);
return Math.max(min, Math.min((0, exports.ensureNumeric)(value), max));
};
exports.ensureNumericConstrained = ensureNumericConstrained;
const ensureArray = (array = []) => (
// eslint-disable-next-line no-nested-ternary
!array ? [] : Array.isArray(array) ? array : [array]);
exports.ensureArray = ensureArray;
const ensureArraySet = (arrayOrSet) => ((0, exports.ensureArray)((0, exports.isSet)(arrayOrSet) ? [...arrayOrSet] : arrayOrSet));
exports.ensureArraySet = ensureArraySet;
const arrayEmpty = (array, disableEmptyString = false) => (
// eslint-disable-next-line eqeqeq
!array || !array.length || (array.length === 1 && (array[0] == undefined || (disableEmptyString && (0, exports.stringEmpty)(array[0])))));
exports.arrayEmpty = arrayEmpty;
const arrayNotEmpty = (array, disableEmptyString = false) => (
// eslint-disable-next-line eqeqeq
!(0, exports.arrayEmpty)(array) && array[0] != undefined && (!disableEmptyString || (0, exports.stringNotEmpty)(array[0])));
exports.arrayNotEmpty = arrayNotEmpty;
const findLastMatch = (array, filterCallback = (value) => (value)) => ((0, exports.ensureArray)(array).filter(filterCallback).slice(-1)[0]);
exports.findLastMatch = findLastMatch;
const ensureObject = (object) => (object !== null && object !== void 0 ? object : {});
exports.ensureObject = ensureObject;
// NOTE: this does not ensure !isType(string)
const objectEmpty = (object) => (!object || !Object.keys(object).length);
exports.objectEmpty = objectEmpty;
const objectNotEmpty = (object) => (!(0, exports.objectEmpty)(object));
exports.objectNotEmpty = objectNotEmpty;
const nullable = (object) => ((!object || (object === 'null') || (object === undefined) || (object === null))
? null // TODO: explore undefined here??
: object);
exports.nullable = nullable;
const objectContainsAnyValue = (object) => (Object.values((0, exports.ensureObject)(object)).some((value) => (0, exports.nullable)(value)));
exports.objectContainsAnyValue = objectContainsAnyValue;
const isUndefined = (value) => (
// eslint-disable-next-line eqeqeq
value == undefined);
const cleanObjectKeys = (object, _removeKeyNames) => {
const removeKeyNames = (0, exports.ensureArray)(_removeKeyNames);
return Object.fromEntries(Object.entries((0, exports.ensureObject)(object)).filter(([key]) => !removeKeyNames.includes(key)));
};
exports.cleanObjectKeys = cleanObjectKeys;
const cleanObject = (object, allowEmptyLeafs, isEmptyCallback) => (Object.entries((0, exports.ensureObject)(object)).reduce((_cleanedObject, [key, _value]) => {
var _a, _b;
if (!allowEmptyLeafs && ((_a = isEmptyCallback === null || isEmptyCallback === void 0 ? void 0 : isEmptyCallback(_value)) !== null && _a !== void 0 ? _a : isUndefined(_value))) {
return _cleanedObject; // skip key if null or undefined
}
const value = !Array.isArray(_value)
? cleanObjectValue(_value, allowEmptyLeafs, isEmptyCallback)
: _value.reduce((_data, __value) => ([
..._data,
cleanObjectValue(__value, allowEmptyLeafs, isEmptyCallback)
]), []);
if (!allowEmptyLeafs && ((_b = isEmptyCallback === null || isEmptyCallback === void 0 ? void 0 : isEmptyCallback(value)) !== null && _b !== void 0 ? _b : isUndefined(value))) {
return _cleanedObject; // skip key if null or undefined
}
return Object.assign(Object.assign({}, _cleanedObject), { [key]: value });
}, {}));
exports.cleanObject = cleanObject;
const cleanObjectValue = (value, allowEmptyLeafs, isEmptyCallback) => {
switch (true) {
case isClass(value): {
return undefined;
}
case (0, exports.isTypeEnhanced)(value, 'object'): {
return (0, exports.cleanObject)(value, allowEmptyLeafs, isEmptyCallback);
}
default: {
return value;
}
}
};
const stringNotEmptyOnly = (stringable) => {
const string = (0, exports.ensureStringOnly)(stringable);
return ((string.length > 0) && !['null', 'undefined'].includes(string));
};
exports.stringNotEmptyOnly = stringNotEmptyOnly;
const stringEmptyOnly = (stringable) => (!(0, exports.stringNotEmptyOnly)(stringable));
exports.stringEmptyOnly = stringEmptyOnly;
const stringNotEmpty = (stringable) => {
const string = (0, exports.ensureString)(stringable);
return ((string.length > 0) && !['null', 'undefined'].includes(string));
};
exports.stringNotEmpty = stringNotEmpty;
const stringEmpty = (stringable) => (!(0, exports.stringNotEmpty)(stringable));
exports.stringEmpty = stringEmpty;
const splitString = (splitting, index = splitting.length) => {
const string = (0, exports.ensureString)(splitting);
return [string.slice(0, index), string.slice(index)];
};
const compareNumber = (number1 = 0, number2 = 0) => (number1 - number2);
exports.compareNumber = compareNumber;
const compareString = (string1, string2) => {
if ((0, exports.stringEmpty)(string1)) {
return 1;
}
if ((0, exports.stringEmpty)(string2)) {
return -1;
}
return (0, exports.ensureString)(string1).localeCompare(string2);
};
exports.compareString = compareString;
const compareEntryKeys = ([string1], [string2]) => ((0, exports.compareString)(string1, string2));
exports.compareEntryKeys = compareEntryKeys;
const objectToSortedString = (object, separator = '') => (Object.entries((0, exports.ensureObject)(object))
.sort(exports.compareEntryKeys)
.map(([key, value]) => `${key}=${value}`)
.join(separator));
exports.objectToSortedString = objectToSortedString;
const isHTML = (string) => {
var _a, _b, _c;
return ((_c = (((_a = string === null || string === void 0 ? void 0 : string.startsWith) === null || _a === void 0 ? void 0 : _a.call(string, '<')) || ((_b = string === null || string === void 0 ? void 0 : string.startsWith) === null || _b === void 0 ? void 0 : _b.call(string, '\n<')))) !== null && _c !== void 0 ? _c : false);
};
exports.isHTML = isHTML;
const freeze = (logMessage, object, type = 'log') => {
console[type](logMessage, !object ? object : JSON.parse(JSON.stringify((0, exports.ensureObject)(object))));
};
exports.freeze = freeze;
const replaceSpaces = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
? ''
: string.replace(/\s/g, replacement));
exports.replaceSpaces = replaceSpaces;
const recase = (string, replacement = '') => (!(0, exports.isType)(string, 'string')
? ''
: string
.replace(/[^a-zA-Z0-9]+/g, replacement)
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(/([0-9])([^0-9])/g, '$1-$2')
.replace(/([^0-9])([0-9])/g, '$1-$2')
.replace(/[-_]+/g, replacement)
.replace(new RegExp(`${replacement}$`), '')
.toLowerCase());
const zencase = (string, replacement = '-') => (!(0, exports.isType)(string, 'string')
? ''
: (0, exports.replaceSpaces)(string, replacement)
.replace(/([A-Z]+)([A-Z][a-z])/g, '$1-$2')
.replace(/([a-z])([A-Z])/g, '$1-$2')
.replace(new RegExp(`${replacement}$`), '')
.toLowerCase());
exports.zencase = zencase;
const dashcase = (string) => (recase(string, '-'));
exports.dashcase = dashcase;
const undashcase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/-/g, replacement).trim());
exports.undashcase = undashcase;
const snakecase = (string) => (recase(string, '_'));
exports.snakecase = snakecase;
const unsnakecase = (string, replacement = ' ') => ((0, exports.ensureString)(string).replace(/_/g, replacement).trim());
exports.unsnakecase = unsnakecase;
const uppercase = (string) => ((0, exports.ensureString)(string).toUpperCase());
exports.uppercase = uppercase;
const lowercase = (string, defaultValue = '') => (!(0, exports.stringNotEmpty)(string)
? defaultValue
: (0, exports.ensureString)(string).toLowerCase());
exports.lowercase = lowercase;
const isLowercase = (string) => ((0, exports.stringNotEmpty)(string) && /^[^A-Z]*$/.test(string));
exports.isLowercase = isLowercase;
const slugify = (string) => ((0, exports.lowercase)((0, exports.dashcase)(string)));
exports.slugify = slugify;
const capitalize = (string) => {
const parts = splitString(string, 1);
return `${(0, exports.uppercase)(parts[0])}${parts[1]}`;
};
exports.capitalize = capitalize;
const camelCase = (string) => ((0, exports.stringEmpty)(string)
? ''
: (0, exports.unsnakecase)((0, exports.undashcase)(string)).replace(/\w\S*/g, (word, charIndex) => {
if (charIndex === 0) {
return (0, exports.lowercase)(word);
}
return `${(0, exports.uppercase)(word.charAt(0))}${(0, exports.lowercase)(word.substr(1))}`;
}).split(' ').join(''));
exports.camelCase = camelCase;
const titleCase = (_string, _overrides) => {
if ((0, exports.stringEmpty)(_string)) {
return '';
}
const overrides = Object.assign({ 'add-ons': 'Add-Ons', agnostack: 'agnoStack', ai: 'AI', 'ai for commerce': 'AI for Commerce', "'ai for commerce'": "'AI For Commerce'", b2b: 'B2B', b2c: 'B2C', cartcollab: 'CartCollab', 'cartcollab(sm)': 'CartCollab(SM)', chatgpt: 'ChatGPT', covid: 'COVID', covid19: 'COVID-19', 'covid-19': 'COVID-19', crm: 'CRM', elasticpath: 'Elastic Path', ecommerce: 'eCommerce', 'e-commerce': 'eCommerce', faqs: 'FAQs', gpt: 'GPT', ipaas: 'iPaaS', 'ltv.ai': 'LTV.ai', 'smile.io': 'Smile.io', 'stamped.io': 'Stamped.io', 'judge.me': 'Judge.me', 'influence.io': 'Influence.io', keepsmallstrong: 'KeepSmallStrong', loyaltylion: 'LoyaltyLion', 'mach alliance': 'MACH Alliance', openai: 'OpenAI', paypal: 'PayPal', 'postscript.io': 'Postscript.io', recharge: 'Recharge', 'stay.ai': 'Stay Ai', 'stay ai': 'Stay Ai', shipengine: 'ShipEngine', shipperhq: 'ShipperHQ', shipstation: 'ShipStation', taxjar: 'TaxJar', vs: 'vs', 'vs.': 'vs.', yotpo: 'YotPo', "zendesk 'ai for commerce'": "Zendesk 'AI For Commerce'" }, _overrides);
const string = (0, exports.lowercase)(_string);
if (overrides[string]) {
return overrides[string];
}
const stringParts = string
.split(' ')
.reduce((_stringParts, _stringPart) => {
var _a;
const stringPart = (_a = overrides[_stringPart]) !== null && _a !== void 0 ? _a : _stringPart
.replace(/([A-Z]+)/g, ' $1')
.replace(/\s\s+/g, ' ')
.replace(/(\b[a-z](?!\s)*)/g, (firstChar) => (0, exports.uppercase)(firstChar));
return [
..._stringParts,
...(0, exports.stringNotEmpty)(stringPart) ? [stringPart] : []
];
}, []);
return stringParts.join(' ');
};
exports.titleCase = titleCase;
const removeLeadingSlash = (string) => ((0, exports.ensureString)(string).replace(/^\//, ''));
exports.removeLeadingSlash = removeLeadingSlash;
const removeLeadingTrailingQuotes = (string) => ((0, exports.ensureString)(string).replace(/^"|"$/g, ''));
exports.removeLeadingTrailingQuotes = removeLeadingTrailingQuotes;
// TODO: not sure if this should remove multipel at end or just one (as it does now)?
const removeTrailingSlash = (string) => ((0, exports.ensureString)(string).replace(/\/$/, ''));
exports.removeTrailingSlash = removeTrailingSlash;
const removeLeadingTrailingSlash = (string) => ((0, exports.removeTrailingSlash)((0, exports.removeLeadingSlash)(string)));
exports.removeLeadingTrailingSlash = removeLeadingTrailingSlash;
const ensureLeadingSlash = (string) => (`/${(0, exports.removeLeadingSlash)(string)}`);
exports.ensureLeadingSlash = ensureLeadingSlash;
const ensureTrailingSlash = (string) => (`${(0, exports.removeTrailingSlash)(string)}/`);
exports.ensureTrailingSlash = ensureTrailingSlash;
const ensureTrailingQuestion = (string) => {
if (!(0, exports.isString)(string)) {
return string;
}
return string.endsWith('?') ? string : `${string}?`;
};
exports.ensureTrailingQuestion = ensureTrailingQuestion;
const ensureExtension = (string, extension) => {
var _a, _b;
if ((0, exports.stringEmpty)(extension)) {
return string;
}
const filePath = (_b = (_a = string.match(/(.*)\..+$/)) === null || _a === void 0 ? void 0 : _a[1]) !== null && _b !== void 0 ? _b : string;
return `${filePath}.${extension}`;
};
exports.ensureExtension = ensureExtension;
const wrappedEncode = (basePath, _wrappingPath) => {
const wrappingPath = (0, exports.ensureString)(_wrappingPath);
if ((0, exports.stringEmpty)(basePath)) {
return wrappingPath;
}
return `${basePath}${encodeURIComponent(wrappingPath)}`;
};
exports.wrappedEncode = wrappedEncode;
const splitCommas = (value) => ((0, exports.ensureString)(value)
.replace(/, /g, ',')
.split(',')
.reduce((_values, _value) => {
const __value = (0, exports.safeTrim)(_value);
return [
..._values,
...(0, exports.stringNotEmpty)(__value) ? [__value] : [] // TODO: explore stringEmptyOnly?
];
}, []));
exports.splitCommas = splitCommas;
const combineCommas = (values) => ([...new Set((0, exports.ensureArray)(values).reduce((_combined, value) => ([
..._combined,
...(0, exports.splitCommas)(value)
]), []))]);
exports.combineCommas = combineCommas;
const normalizeArray = (input, separator = ' ') => {
const inputArray = (0, exports.ensureArray)(input);
return inputArray.reduce((normalized, _ignore, index) => ([
...normalized,
inputArray.slice(0, index + 1).join(separator)
]), []).reverse();
};
exports.normalizeArray = normalizeArray;
const arrayToObject = (arrayable, key) => ((0, exports.ensureArray)(arrayable).reduce((_object, item) => (Object.assign(Object.assign({}, _object), { [item === null || item === void 0 ? void 0 : item[key]]: item })), {}));
exports.arrayToObject = arrayToObject;
const isTrue = (value, falsy) => {
const string = (0, exports.ensureString)(value);
return ![...(0, exports.ensureArray)(falsy), '', 'false'].includes(string);
};
exports.isTrue = isTrue;
const isUndefinedOrTrue = (value, falsy) => (isUndefined(value) || (0, exports.isTrue)(value, falsy));
exports.isUndefinedOrTrue = isUndefinedOrTrue;
const isBoolean = (value) => ([true, false, 'true', 'false'].includes(value));
exports.isBoolean = isBoolean;
const getBaseDomain = (baseUrl) => ((baseUrl === null || baseUrl === void 0 ? void 0 : baseUrl.match(/^(?:https?:\/\/)?([^/:]+)(?::(\d+))?/).slice(1, 3).filter(exports.stringNotEmpty).join(':')) || undefined);
exports.getBaseDomain = getBaseDomain;
// TODO: move all uses of parseKeywords to parseKeywordGroups
const parseKeywords = (keywordGroup, previous) => ([...new Set((0, exports.ensureArray)(keywordGroup).reduce((_parsedKeywords, keyword) => {
const keywords = (0, exports.splitCommas)(keyword);
return [
..._parsedKeywords,
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
];
}, (0, exports.ensureArray)(previous)))].join(', '));
exports.parseKeywords = parseKeywords;
const parseCommaGroups = (commaGroups) => {
const parsedGroups = (0, exports.ensureArray)(commaGroups).reduce((_parsedGroups, commaGroup) => ([
..._parsedGroups,
...(0, exports.ensureArray)(commaGroup).reduce((_parsedCommaKeywords, keyword) => {
const keywords = (0, exports.splitCommas)(keyword);
return [
..._parsedCommaKeywords,
...keywords.filter((_keyword) => (0, exports.stringNotEmpty)(_keyword))
];
}, [])
]), []);
return [...new Set(parsedGroups)];
};
exports.parseCommaGroups = parseCommaGroups;
const parseKeywordGroups = (keywordGroups) => ((0, exports.parseCommaGroups)(keywordGroups).join(', '));
exports.parseKeywordGroups = parseKeywordGroups;
// #endregion lib-core
// #region lib-utils-js
const querystringToParams = (queryString) => {
const urlParams = new URLSearchParams((0, exports.ensureString)(queryString));
return [Object.fromEntries(urlParams), urlParams];
};
exports.querystringToParams = querystringToParams;
const querystringToObject = (queryString) => ((0, exports.querystringToParams)(queryString)[0]);
exports.querystringToObject = querystringToObject;
const arrayIncludesAll = (_values, comparison) => {
const values = (0, exports.ensureArray)(_values);
return (0, exports.ensureArray)(comparison).every((value) => ((0, exports.stringNotEmpty)(value) && values.includes(value)));
};
exports.arrayIncludesAll = arrayIncludesAll;
const arraysMatch = (array1, array2) => ((0, exports.arrayIncludesAll)(array1, array2) && (0, exports.arrayIncludesAll)(array2, array1));
exports.arraysMatch = arraysMatch;
const appendQuery = (_basePath, queryString) => {
const basePath = (0, exports.ensureString)(_basePath);
if ((0, exports.stringEmpty)(queryString)) {
return basePath;
}
return `${basePath}${basePath.includes('?') ? '&' : '?'}${queryString}`;
};
exports.appendQuery = appendQuery;
const appendParams = (basePath, params) => ((0, exports.appendQuery)(basePath, (0, exports.ensureArray)(params).join('&')));
exports.appendParams = appendParams;
// #endregion lib-utils-js
//# sourceMappingURL=display.js.map