UNPKG

@minionorg/share

Version:
83 lines (82 loc) 2.28 kB
var s = Object.defineProperty; var f = (r, t, e) => t in r ? s(r, t, { enumerable: !0, configurable: !0, writable: !0, value: e }) : r[t] = e; var n = (r, t, e) => (f(r, typeof t != "symbol" ? t + "" : t, e), e); function u(r) { return r.charAt(0).toUpperCase() + r.slice(1); } function a(r) { if (!r) throw new SyntaxError("type is must"); return function(t) { return Object.prototype.toString.call(t) === `[object ${u(r)}]`; }; } function o(r) { if (!r) throw new SyntaxError("type is must"); return function(t) { return Object.prototype.toString.call(t) === `[object ${u(r)}]`; }; } o("Function"); o("Object"); class i { constructor() { } static notNull(t, e) { if (t === null) throw new SyntaxError(e || "The value must not be empty"); } static notEmpty(t, e) { if (t.length === 0) throw new SyntaxError(e || "The String must not be empty"); } static errMsg(t) { return function(e) { return `${t}: ${e}`; }; } static isString(t) { if (t === null) return null; if (a("string")(t)) return t; throw new TypeError("The parameter type is string"); } static isValidDateFormat(t) { return /(^(y{4}|y{2})[.\u002f-](m{1,2})[.\u002f-](d{1,2})$)|(^(m{1,2})[.\u002f-](d{1,2})[.\u002f-]((y{4}|y{2})$))|(^(d{1,2})[.\u002f-](m{1,2})[.\u002f-]((y{4}|y{2})$))/gi.test( t ); } static isTimeFormat(t) { return /(^(h{1,2}):(m{1,2}):(s{1,2})$)|(^(h{1,2}):(m{1,2})$)/gi.test(t); } } n(i, "DEFAULT_NOT_NAN_EX_MESSAGE", "\u9A8C\u8BC1\u7684\u503C\u4E0D\u662F\u6570\u5B57"); const m = { 24: { default: /^([01]?\d|2[0-3]):([0-5]\d)$/, hasSecond: /^([01]?\d|2[0-3]):([0-5]\d):([0-5]\d)$/ }, 12: { default: /^(0?\d|1[0-2]):([0-5]\d) (A|P)M$/, hasSecond: /^(0?\d|1[0-2]):([0-5]\d):([0-5]\d) (A|P)M$/ } }; function l(r, t) { if (!a("String")(r)) return !1; if (t = { format: "HH:MM:SS", mode: 24, ...t }, !i.isTimeFormat(t.format)) throw new SyntaxError(`${t.format} is not valid format`); if (![24, 12].includes(t.mode)) throw new SyntaxError(`${t.mode} is not valid mode`); const e = t.format.match(/s/ig), c = e && e.length > 0; return m[t.mode][c ? "hasSecond" : "default"].test(r); } export { l as default };