@enonic/js-utils
Version:
Enonic XP JavaScript Utils
103 lines (102 loc) • 3.59 kB
JavaScript
;
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);
};
// value/isLocalDateTimeString.ts
var isLocalDateTimeString_exports = {};
__export(isLocalDateTimeString_exports, {
isLocalDateTimeString: function() {
return isLocalDateTimeString;
}
});
module.exports = __toCommonJS(isLocalDateTimeString_exports);
// 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/isLocalDateTimeString.ts
var REGEXP_DATE = /^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}(:\d{2}(\.\d{0,9})?)?$/;
function isLocalDateTimeString(v) {
if (!isString(v)) {
return false;
}
var matches = v.match(REGEXP_DATE);
if (matches) {
var localDateTimeStringToParse = "".concat(matches[0].substring(0, 19), "Z");
try {
var d = new Date(Date.parse(localDateTimeStringToParse));
var inputTrimmed = v.substring(0, 19);
if (inputTrimmed.length === 16) {
inputTrimmed += ":00";
}
var parsedTrimmed = d.toJSON().substring(0, 19);
if (inputTrimmed === parsedTrimmed) {
return true;
}
return false;
} catch (e) {}
}
return false;
}