@tmagic/utils 1.0.0-beta.1 → 1.0.0-beta.12

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -54,7 +54,7 @@ function isUndefined(input) {
54
54
  return input === void 0;
55
55
  }
56
56
 
57
- function isNumber(input) {
57
+ function isNumber$1(input) {
58
58
  return (
59
59
  typeof input === 'number' ||
60
60
  Object.prototype.toString.call(input) === '[object Number]'
@@ -825,7 +825,7 @@ function addParseToken(token, callback) {
825
825
  if (typeof token === 'string') {
826
826
  token = [token];
827
827
  }
828
- if (isNumber(callback)) {
828
+ if (isNumber$1(callback)) {
829
829
  func = function (input, array) {
830
830
  array[callback] = toInt(input);
831
831
  };
@@ -1095,7 +1095,7 @@ function setMonth(mom, value) {
1095
1095
  } else {
1096
1096
  value = mom.localeData().monthsParse(value);
1097
1097
  // TODO: Another silent failure?
1098
- if (!isNumber(value)) {
1098
+ if (!isNumber$1(value)) {
1099
1099
  return mom;
1100
1100
  }
1101
1101
  }
@@ -2976,7 +2976,7 @@ function configFromInput(config) {
2976
2976
  configFromArray(config);
2977
2977
  } else if (isObject(input)) {
2978
2978
  configFromObject(config);
2979
- } else if (isNumber(input)) {
2979
+ } else if (isNumber$1(input)) {
2980
2980
  // from milliseconds
2981
2981
  config._d = new Date(input);
2982
2982
  } else {
@@ -3450,7 +3450,7 @@ function createDuration(input, key) {
3450
3450
  d: input._days,
3451
3451
  M: input._months,
3452
3452
  };
3453
- } else if (isNumber(input) || !isNaN(+input)) {
3453
+ } else if (isNumber$1(input) || !isNaN(+input)) {
3454
3454
  duration = {};
3455
3455
  if (key) {
3456
3456
  duration[key] = +input;
@@ -3617,7 +3617,7 @@ function isMomentInput(input) {
3617
3617
  isMoment(input) ||
3618
3618
  isDate(input) ||
3619
3619
  isString(input) ||
3620
- isNumber(input) ||
3620
+ isNumber$1(input) ||
3621
3621
  isNumberOrStringArray(input) ||
3622
3622
  isMomentInputObject(input) ||
3623
3623
  input === null ||
@@ -3671,7 +3671,7 @@ function isNumberOrStringArray(input) {
3671
3671
  if (arrayTest) {
3672
3672
  dataTypeTest =
3673
3673
  input.filter(function (item) {
3674
- return !isNumber(item) && isString(input);
3674
+ return !isNumber$1(item) && isString(input);
3675
3675
  }).length === 0;
3676
3676
  }
3677
3677
  return arrayTest && dataTypeTest;
@@ -5031,7 +5031,7 @@ function get$1(format, index, field, setter) {
5031
5031
  }
5032
5032
 
5033
5033
  function listMonthsImpl(format, index, field) {
5034
- if (isNumber(format)) {
5034
+ if (isNumber$1(format)) {
5035
5035
  index = format;
5036
5036
  format = undefined;
5037
5037
  }
@@ -5060,7 +5060,7 @@ function listMonthsImpl(format, index, field) {
5060
5060
  // (true, fmt)
5061
5061
  function listWeekdaysImpl(localeSorted, format, index, field) {
5062
5062
  if (typeof localeSorted === 'boolean') {
5063
- if (isNumber(format)) {
5063
+ if (isNumber$1(format)) {
5064
5064
  index = format;
5065
5065
  format = undefined;
5066
5066
  }
@@ -5071,7 +5071,7 @@ function listWeekdaysImpl(localeSorted, format, index, field) {
5071
5071
  index = format;
5072
5072
  localeSorted = false;
5073
5073
 
5074
- if (isNumber(format)) {
5074
+ if (isNumber$1(format)) {
5075
5075
  index = format;
5076
5076
  format = undefined;
5077
5077
  }
@@ -5659,6 +5659,13 @@ hooks.HTML5_FMT = {
5659
5659
  MONTH: 'YYYY-MM', // <input type="month" />
5660
5660
  };
5661
5661
 
5662
+ var NodeType = /* @__PURE__ */ ((NodeType2) => {
5663
+ NodeType2["CONTAINER"] = "container";
5664
+ NodeType2["PAGE"] = "page";
5665
+ NodeType2["ROOT"] = "app";
5666
+ return NodeType2;
5667
+ })(NodeType || {});
5668
+
5662
5669
  const sleep = (ms) => new Promise((resolve) => {
5663
5670
  const timer = setTimeout(() => {
5664
5671
  clearTimeout(timer);
@@ -5689,22 +5696,22 @@ const datetimeFormatter = (v, defaultValue = "-", f = "YYYY-MM-DD HH:mm:ss") =>
5689
5696
  };
5690
5697
  const asyncLoadJs = (() => {
5691
5698
  const documentMap = /* @__PURE__ */ new Map();
5692
- return (url, crossOrigin, document2 = globalThis.document) => {
5693
- let loaded = documentMap.get(document2);
5699
+ return (url, crossOrigin, document = globalThis.document) => {
5700
+ let loaded = documentMap.get(document);
5694
5701
  if (!loaded) {
5695
5702
  loaded = /* @__PURE__ */ new Map();
5696
- documentMap.set(document2, loaded);
5703
+ documentMap.set(document, loaded);
5697
5704
  }
5698
5705
  if (loaded.get(url))
5699
5706
  return loaded.get(url);
5700
5707
  const load = new Promise((resolve, reject) => {
5701
- const script = document2.createElement("script");
5708
+ const script = document.createElement("script");
5702
5709
  script.type = "text/javascript";
5703
5710
  if (crossOrigin) {
5704
5711
  script.crossOrigin = crossOrigin;
5705
5712
  }
5706
5713
  script.src = url;
5707
- document2.body.appendChild(script);
5714
+ document.body.appendChild(script);
5708
5715
  script.onload = () => {
5709
5716
  resolve();
5710
5717
  };
@@ -5722,21 +5729,38 @@ const asyncLoadJs = (() => {
5722
5729
  return loaded.get(url);
5723
5730
  };
5724
5731
  })();
5725
- const asyncLoadCss = function(url) {
5726
- return new Promise((resolve, reject) => {
5727
- const hasLoaded = globalThis.document.querySelector(`link[href="${url}"]`);
5728
- if (hasLoaded) {
5729
- resolve(void 0);
5730
- return;
5731
- }
5732
- const node = document.createElement("link");
5733
- node.rel = "stylesheet";
5734
- node.href = url;
5735
- document.getElementsByTagName("head")[0].appendChild(node);
5736
- node.onload = resolve;
5737
- node.onerror = reject;
5738
- });
5739
- };
5732
+ const asyncLoadCss = (() => {
5733
+ const documentMap = /* @__PURE__ */ new Map();
5734
+ return (url, document = globalThis.document) => {
5735
+ let loaded = documentMap.get(document);
5736
+ if (!loaded) {
5737
+ loaded = /* @__PURE__ */ new Map();
5738
+ documentMap.set(document, loaded);
5739
+ }
5740
+ if (loaded.get(url))
5741
+ return loaded.get(url);
5742
+ const load = new Promise((resolve, reject) => {
5743
+ const node = document.createElement("link");
5744
+ node.rel = "stylesheet";
5745
+ node.href = url;
5746
+ document.head.appendChild(node);
5747
+ node.onload = () => {
5748
+ resolve();
5749
+ };
5750
+ node.onerror = () => {
5751
+ reject(new Error("\u52A0\u8F7D\u5931\u8D25"));
5752
+ };
5753
+ setTimeout(() => {
5754
+ reject(new Error("timeout"));
5755
+ }, 60 * 1e3);
5756
+ }).catch((err) => {
5757
+ loaded.delete(url);
5758
+ throw err;
5759
+ });
5760
+ loaded.set(url, load);
5761
+ return loaded.get(url);
5762
+ };
5763
+ })();
5740
5764
  const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
5741
5765
  const toHump = (name = "") => name.replace(/-(\w)/g, (all, letter) => letter.toUpperCase());
5742
5766
  const emptyFn = () => void 0;
@@ -5780,7 +5804,9 @@ const getUrlParam = (param, url) => {
5780
5804
  }
5781
5805
  return "";
5782
5806
  };
5783
- const isPop = (node) => node.type.toLowerCase().endsWith("pop");
5807
+ const isPop = (node) => Boolean(node.type?.toLowerCase().endsWith("pop"));
5808
+ const isPage = (node) => Boolean(node.type?.toLowerCase() === NodeType.PAGE);
5809
+ const isNumber = (value) => /^(\d|\.)+$/.test(value);
5784
5810
 
5785
- export { asyncLoadCss, asyncLoadJs, datetimeFormatter, emptyFn, filterXSS, getNodePath, getUrlParam, isPop, sleep, toHump, toLine };
5811
+ export { asyncLoadCss, asyncLoadJs, datetimeFormatter, emptyFn, filterXSS, getNodePath, getUrlParam, isNumber, isPage, isPop, sleep, toHump, toLine };
5786
5812
  //# sourceMappingURL=tmagic-utils.es.js.map