UNPKG

@enonic/js-utils

Version:
59 lines (51 loc) 1.71 kB
// value/isFunction.ts function isFunction(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Function"; } // value/isStringLiteral.ts var isStringLiteral = (value) => typeof value === "string"; // value/isStringObject.ts var isStringObject = (value) => value instanceof String; // value/isString.ts var isString = (value) => isStringLiteral(value) || isStringObject(value); // value/isInt.ts function isInt(value) { return typeof value === "number" && isFinite(value) && // TODO Is isFinite() available in Enonic XP? Math.floor(value) === value; } // value/isInteger.ts var isInteger = "isInteger" in Number && isFunction(Number.isInteger) ? Number.isInteger : isInt; // value/toStr.ts function toStr(value, replacer, space = 4) { return JSON.stringify(value, replacer, space); } // storage/repo/index.ts function validateRepoId(repoId) { if (!isString(repoId)) { return "repoId must be a string!"; } if (repoId === "") { return "repoId can't be an empty string!"; } const firstChar = repoId.charAt(0); if (firstChar === "_") { return "repoId can't start with an underscore!"; } if (firstChar === ".") { return "repoId can't start with a dot!"; } if (repoId.toLowerCase() !== repoId) { return "repoId can't contain uppercase letters!"; } for (let i = 0; i < repoId.length; i++) { const char = repoId.charAt(i); const code = char.charCodeAt(0); if (!(code === 45 || code === 46 || code >= 48 && code <= 58 || code === 95 || code >= 97 && code <= 122)) { return `char:${toStr(char)} with charCode:${code} is illegal! repoId can only contain - . 1-9 : _ a-z`; } } return null; } export { validateRepoId };