UNPKG

@enonic/js-utils

Version:
122 lines (121 loc) 4.29 kB
"use strict"; function _instanceof(left, right) { if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) { return !!right[Symbol.hasInstance](left); } else { return left instanceof right; } } function _type_of(obj) { "@swc/helpers - typeof"; return obj && typeof Symbol !== "undefined" && obj.constructor === Symbol ? "symbol" : typeof obj; } var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = function(target, all) { for(var name in all)__defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = function(to, from, except, desc) { if (from && (typeof from === "undefined" ? "undefined" : _type_of(from)) === "object" || typeof from === "function") { var _iteratorNormalCompletion = true, _didIteratorError = false, _iteratorError = undefined; try { var _loop = function() { var key = _step.value; if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: function() { return from[key]; }, enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); }; for(var _iterator = __getOwnPropNames(from)[Symbol.iterator](), _step; !(_iteratorNormalCompletion = (_step = _iterator.next()).done); _iteratorNormalCompletion = true)_loop(); } catch (err) { _didIteratorError = true; _iteratorError = err; } finally{ try { if (!_iteratorNormalCompletion && _iterator.return != null) { _iterator.return(); } } finally{ if (_didIteratorError) { throw _iteratorError; } } } } return to; }; var __toCommonJS = function(mod) { return __copyProps(__defProp({}, "__esModule", { value: true }), mod); }; // storage/repo/index.ts var repo_exports = {}; __export(repo_exports, { validateRepoId: function() { return validateRepoId; } }); module.exports = __toCommonJS(repo_exports); // value/isFunction.ts function isFunction(value) { return Object.prototype.toString.call(value).slice(8, -1) === "Function"; } // value/isStringLiteral.ts var isStringLiteral = function(value) { return typeof value === "string"; }; // value/isStringObject.ts var isStringObject = function(value) { return _instanceof(value, String); }; // value/isString.ts var isString = function(value) { return 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) { var space = arguments.length > 2 && arguments[2] !== void 0 ? arguments[2] : 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!"; } var 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(var i = 0; i < repoId.length; i++){ var char = repoId.charAt(i); var code = char.charCodeAt(0); if (!(code === 45 || code === 46 || code >= 48 && code <= 58 || code === 95 || code >= 97 && code <= 122)) { return "char:".concat(toStr(char), " with charCode:").concat(code, " is illegal! repoId can only contain - . 1-9 : _ a-z"); } } return null; }