@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.
@@ -60,7 +60,7 @@
60
60
  return input === void 0;
61
61
  }
62
62
 
63
- function isNumber(input) {
63
+ function isNumber$1(input) {
64
64
  return (
65
65
  typeof input === 'number' ||
66
66
  Object.prototype.toString.call(input) === '[object Number]'
@@ -831,7 +831,7 @@
831
831
  if (typeof token === 'string') {
832
832
  token = [token];
833
833
  }
834
- if (isNumber(callback)) {
834
+ if (isNumber$1(callback)) {
835
835
  func = function (input, array) {
836
836
  array[callback] = toInt(input);
837
837
  };
@@ -1101,7 +1101,7 @@
1101
1101
  } else {
1102
1102
  value = mom.localeData().monthsParse(value);
1103
1103
  // TODO: Another silent failure?
1104
- if (!isNumber(value)) {
1104
+ if (!isNumber$1(value)) {
1105
1105
  return mom;
1106
1106
  }
1107
1107
  }
@@ -2982,7 +2982,7 @@
2982
2982
  configFromArray(config);
2983
2983
  } else if (isObject(input)) {
2984
2984
  configFromObject(config);
2985
- } else if (isNumber(input)) {
2985
+ } else if (isNumber$1(input)) {
2986
2986
  // from milliseconds
2987
2987
  config._d = new Date(input);
2988
2988
  } else {
@@ -3456,7 +3456,7 @@
3456
3456
  d: input._days,
3457
3457
  M: input._months,
3458
3458
  };
3459
- } else if (isNumber(input) || !isNaN(+input)) {
3459
+ } else if (isNumber$1(input) || !isNaN(+input)) {
3460
3460
  duration = {};
3461
3461
  if (key) {
3462
3462
  duration[key] = +input;
@@ -3623,7 +3623,7 @@
3623
3623
  isMoment(input) ||
3624
3624
  isDate(input) ||
3625
3625
  isString(input) ||
3626
- isNumber(input) ||
3626
+ isNumber$1(input) ||
3627
3627
  isNumberOrStringArray(input) ||
3628
3628
  isMomentInputObject(input) ||
3629
3629
  input === null ||
@@ -3677,7 +3677,7 @@
3677
3677
  if (arrayTest) {
3678
3678
  dataTypeTest =
3679
3679
  input.filter(function (item) {
3680
- return !isNumber(item) && isString(input);
3680
+ return !isNumber$1(item) && isString(input);
3681
3681
  }).length === 0;
3682
3682
  }
3683
3683
  return arrayTest && dataTypeTest;
@@ -5037,7 +5037,7 @@
5037
5037
  }
5038
5038
 
5039
5039
  function listMonthsImpl(format, index, field) {
5040
- if (isNumber(format)) {
5040
+ if (isNumber$1(format)) {
5041
5041
  index = format;
5042
5042
  format = undefined;
5043
5043
  }
@@ -5066,7 +5066,7 @@
5066
5066
  // (true, fmt)
5067
5067
  function listWeekdaysImpl(localeSorted, format, index, field) {
5068
5068
  if (typeof localeSorted === 'boolean') {
5069
- if (isNumber(format)) {
5069
+ if (isNumber$1(format)) {
5070
5070
  index = format;
5071
5071
  format = undefined;
5072
5072
  }
@@ -5077,7 +5077,7 @@
5077
5077
  index = format;
5078
5078
  localeSorted = false;
5079
5079
 
5080
- if (isNumber(format)) {
5080
+ if (isNumber$1(format)) {
5081
5081
  index = format;
5082
5082
  format = undefined;
5083
5083
  }
@@ -5665,6 +5665,13 @@
5665
5665
  MONTH: 'YYYY-MM', // <input type="month" />
5666
5666
  };
5667
5667
 
5668
+ var NodeType = /* @__PURE__ */ ((NodeType2) => {
5669
+ NodeType2["CONTAINER"] = "container";
5670
+ NodeType2["PAGE"] = "page";
5671
+ NodeType2["ROOT"] = "app";
5672
+ return NodeType2;
5673
+ })(NodeType || {});
5674
+
5668
5675
  const sleep = (ms) => new Promise((resolve) => {
5669
5676
  const timer = setTimeout(() => {
5670
5677
  clearTimeout(timer);
@@ -5695,22 +5702,22 @@
5695
5702
  };
5696
5703
  const asyncLoadJs = (() => {
5697
5704
  const documentMap = /* @__PURE__ */ new Map();
5698
- return (url, crossOrigin, document2 = globalThis.document) => {
5699
- let loaded = documentMap.get(document2);
5705
+ return (url, crossOrigin, document = globalThis.document) => {
5706
+ let loaded = documentMap.get(document);
5700
5707
  if (!loaded) {
5701
5708
  loaded = /* @__PURE__ */ new Map();
5702
- documentMap.set(document2, loaded);
5709
+ documentMap.set(document, loaded);
5703
5710
  }
5704
5711
  if (loaded.get(url))
5705
5712
  return loaded.get(url);
5706
5713
  const load = new Promise((resolve, reject) => {
5707
- const script = document2.createElement("script");
5714
+ const script = document.createElement("script");
5708
5715
  script.type = "text/javascript";
5709
5716
  if (crossOrigin) {
5710
5717
  script.crossOrigin = crossOrigin;
5711
5718
  }
5712
5719
  script.src = url;
5713
- document2.body.appendChild(script);
5720
+ document.body.appendChild(script);
5714
5721
  script.onload = () => {
5715
5722
  resolve();
5716
5723
  };
@@ -5728,21 +5735,38 @@
5728
5735
  return loaded.get(url);
5729
5736
  };
5730
5737
  })();
5731
- const asyncLoadCss = function(url) {
5732
- return new Promise((resolve, reject) => {
5733
- const hasLoaded = globalThis.document.querySelector(`link[href="${url}"]`);
5734
- if (hasLoaded) {
5735
- resolve(void 0);
5736
- return;
5737
- }
5738
- const node = document.createElement("link");
5739
- node.rel = "stylesheet";
5740
- node.href = url;
5741
- document.getElementsByTagName("head")[0].appendChild(node);
5742
- node.onload = resolve;
5743
- node.onerror = reject;
5744
- });
5745
- };
5738
+ const asyncLoadCss = (() => {
5739
+ const documentMap = /* @__PURE__ */ new Map();
5740
+ return (url, document = globalThis.document) => {
5741
+ let loaded = documentMap.get(document);
5742
+ if (!loaded) {
5743
+ loaded = /* @__PURE__ */ new Map();
5744
+ documentMap.set(document, loaded);
5745
+ }
5746
+ if (loaded.get(url))
5747
+ return loaded.get(url);
5748
+ const load = new Promise((resolve, reject) => {
5749
+ const node = document.createElement("link");
5750
+ node.rel = "stylesheet";
5751
+ node.href = url;
5752
+ document.head.appendChild(node);
5753
+ node.onload = () => {
5754
+ resolve();
5755
+ };
5756
+ node.onerror = () => {
5757
+ reject(new Error("\u52A0\u8F7D\u5931\u8D25"));
5758
+ };
5759
+ setTimeout(() => {
5760
+ reject(new Error("timeout"));
5761
+ }, 60 * 1e3);
5762
+ }).catch((err) => {
5763
+ loaded.delete(url);
5764
+ throw err;
5765
+ });
5766
+ loaded.set(url, load);
5767
+ return loaded.get(url);
5768
+ };
5769
+ })();
5746
5770
  const toLine = (name = "") => name.replace(/\B([A-Z])/g, "-$1").toLowerCase();
5747
5771
  const toHump = (name = "") => name.replace(/-(\w)/g, (all, letter) => letter.toUpperCase());
5748
5772
  const emptyFn = () => void 0;
@@ -5786,7 +5810,9 @@
5786
5810
  }
5787
5811
  return "";
5788
5812
  };
5789
- const isPop = (node) => node.type.toLowerCase().endsWith("pop");
5813
+ const isPop = (node) => Boolean(node.type?.toLowerCase().endsWith("pop"));
5814
+ const isPage = (node) => Boolean(node.type?.toLowerCase() === NodeType.PAGE);
5815
+ const isNumber = (value) => /^(\d|\.)+$/.test(value);
5790
5816
 
5791
5817
  exports.asyncLoadCss = asyncLoadCss;
5792
5818
  exports.asyncLoadJs = asyncLoadJs;
@@ -5795,6 +5821,8 @@
5795
5821
  exports.filterXSS = filterXSS;
5796
5822
  exports.getNodePath = getNodePath;
5797
5823
  exports.getUrlParam = getUrlParam;
5824
+ exports.isNumber = isNumber;
5825
+ exports.isPage = isPage;
5798
5826
  exports.isPop = isPop;
5799
5827
  exports.sleep = sleep;
5800
5828
  exports.toHump = toHump;