UNPKG

@kontent-ai/model-generator

Version:

This utility generates strongly-typed models for Delivery JS SDK, Migration toolkit or just general scripting to improve the experience when referencing Kontent.ai related objects.

36 lines 1.26 kB
export function uniqueFilter(value, index, self) { return self.indexOf(value) === index; } export const isNotUndefined = (item) => item !== undefined; export function getFileNameWithoutExtension(filePath) { if (!filePath.includes(".")) { return filePath; } return filePath.substring(0, filePath.lastIndexOf(".")); } export function sortAlphabetically(arrayToSort, propertySelector) { return arrayToSort.toSorted((a, b) => propertySelector(a).toLowerCase().localeCompare(propertySelector(b).toLowerCase())); } export function getStringOrUndefinedAsPropertyValue(text) { return text ? `'${text}'` : "undefined"; } export function toSafePropertyValue(value) { return value.replace(/'/g, ""); } export function toOutputDirPath(outputDir) { return outputDir ? `${outputDir}/`.replaceAll("//", "/") : "./"; } export function singleItemToArray(item) { return item ? [item] : []; } export function findRequired(array, predicate, errorMessage) { const item = array.find(predicate); if (item) { return item; } if (typeof errorMessage === "string" || errorMessage instanceof String) { throw new Error(errorMessage.toString()); } return errorMessage(); } //# sourceMappingURL=core.utils.js.map