@tmagic/utils 1.7.3 → 1.7.5

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.
@@ -259,7 +259,7 @@ const isPageFragment = (node) => {
259
259
  if (!node) return false;
260
260
  return Boolean(node.type?.toLowerCase() === NodeType.PAGE_FRAGMENT);
261
261
  };
262
- const isNumber = (value) => /^(-?\d+)(\.\d+)?$/.test(value);
262
+ const isNumber = (value) => typeof value === "number" && !isNaN(value) || /^(-?\d+)(\.\d+)?$/.test(`${value}`);
263
263
  const getHost = (targetUrl) => targetUrl.match(/\/\/([^/]+)/)?.[1];
264
264
  const isSameDomain = (targetUrl = "", source = globalThis.location.host) => {
265
265
  const isHttpUrl = /^(http[s]?:)?\/\//.test(targetUrl);
@@ -520,5 +520,6 @@ const isValueIncludeDataSource = (value) => {
520
520
  }
521
521
  return false;
522
522
  };
523
+ const removeDataSourceFieldPrefix = (id) => id?.replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, "") || "";
523
524
 
524
- export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
525
+ export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, removeDataSourceFieldPrefix, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
@@ -2632,7 +2632,7 @@
2632
2632
  if (!node) return false;
2633
2633
  return Boolean(node.type?.toLowerCase() === schema.NodeType.PAGE_FRAGMENT);
2634
2634
  };
2635
- const isNumber = (value) => /^(-?\d+)(\.\d+)?$/.test(value);
2635
+ const isNumber = (value) => typeof value === "number" && !isNaN(value) || /^(-?\d+)(\.\d+)?$/.test(`${value}`);
2636
2636
  const getHost = (targetUrl) => targetUrl.match(/\/\/([^/]+)/)?.[1];
2637
2637
  const isSameDomain = (targetUrl = "", source = globalThis.location.host) => {
2638
2638
  const isHttpUrl = /^(http[s]?:)?\/\//.test(targetUrl);
@@ -2893,6 +2893,7 @@
2893
2893
  }
2894
2894
  return false;
2895
2895
  };
2896
+ const removeDataSourceFieldPrefix = (id) => id?.replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, "") || "";
2896
2897
 
2897
2898
  exports.DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX = DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX;
2898
2899
  exports.DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX = DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX;
@@ -2942,6 +2943,7 @@
2942
2943
  exports.isValueIncludeDataSource = isValueIncludeDataSource;
2943
2944
  exports.removeClassName = removeClassName;
2944
2945
  exports.removeClassNameByClassName = removeClassNameByClassName;
2946
+ exports.removeDataSourceFieldPrefix = removeDataSourceFieldPrefix;
2945
2947
  exports.replaceChildNode = replaceChildNode;
2946
2948
  exports.setDslDomRelateConfig = setDslDomRelateConfig;
2947
2949
  exports.setIdToEl = setIdToEl;
package/package.json CHANGED
@@ -1,5 +1,5 @@
1
1
  {
2
- "version": "1.7.3",
2
+ "version": "1.7.5",
3
3
  "name": "@tmagic/utils",
4
4
  "type": "module",
5
5
  "main": "dist/tmagic-utils.umd.cjs",
@@ -34,7 +34,7 @@
34
34
  },
35
35
  "peerDependencies": {
36
36
  "typescript": "^5.9.3",
37
- "@tmagic/schema": "1.7.3"
37
+ "@tmagic/schema": "1.7.5"
38
38
  },
39
39
  "peerDependenciesMeta": {
40
40
  "typescript": {
package/src/index.ts CHANGED
@@ -270,7 +270,8 @@ export const isPageFragment = (node?: MComponent | null): boolean => {
270
270
  return Boolean(node.type?.toLowerCase() === NodeType.PAGE_FRAGMENT);
271
271
  };
272
272
 
273
- export const isNumber = (value: string) => /^(-?\d+)(\.\d+)?$/.test(value);
273
+ export const isNumber = (value: any) =>
274
+ (typeof value === 'number' && !isNaN(value)) || /^(-?\d+)(\.\d+)?$/.test(`${value}`);
274
275
 
275
276
  export const getHost = (targetUrl: string) => targetUrl.match(/\/\/([^/]+)/)?.[1];
276
277
 
@@ -634,3 +635,6 @@ export const isValueIncludeDataSource = (value: any) => {
634
635
  }
635
636
  return false;
636
637
  };
638
+
639
+ export const removeDataSourceFieldPrefix = (id?: string) =>
640
+ id?.replace(DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, '') || '';
package/types/index.d.ts CHANGED
@@ -62,7 +62,7 @@ declare const isObject: (obj: any) => boolean;
62
62
  declare const isPop: (node: MComponent | null) => boolean;
63
63
  declare const isPage: (node?: MComponent | null) => boolean;
64
64
  declare const isPageFragment: (node?: MComponent | null) => boolean;
65
- declare const isNumber: (value: string) => boolean;
65
+ declare const isNumber: (value: any) => boolean;
66
66
  declare const getHost: (targetUrl: string) => string | undefined;
67
67
  declare const isSameDomain: (targetUrl?: string, source?: string) => boolean;
68
68
  /**
@@ -111,6 +111,7 @@ interface NodeItem {
111
111
  }
112
112
  declare const traverseNode: <T extends NodeItem = NodeItem>(node: T, cb: (node: T, parents: T[]) => void, parents?: T[], evalCbAfter?: boolean) => void;
113
113
  declare const isValueIncludeDataSource: (value: any) => boolean;
114
+ declare const removeDataSourceFieldPrefix: (id?: string) => string;
114
115
 
115
- export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
116
+ export { DATA_SOURCE_FIELDS_CHANGE_EVENT_PREFIX, DATA_SOURCE_FIELDS_SELECT_VALUE_PREFIX, DSL_NODE_KEY_COPY_PREFIX, IS_DSL_NODE_KEY, PAGE_FRAGMENT_CONTAINER_ID_KEY, addClassName, addParamToUrl, asyncLoadCss, asyncLoadJs, calcValueByFontsize, calculatePercentage, compiledCond, compiledNode, convertToNumber, createDiv, dataSourceTemplateRegExp, delQueStr, emptyFn, filterXSS, getDefaultValueFromFields, getDepKeys, getDepNodeIds, getDocument, getElById, getGlobalThis, getHost, getIdFromEl, getKeys, getKeysArray, getNodeInfo, getNodePath, getNodes, getSearchObj, getUrlParam, getValueByKeyPath, guid, injectStyle, isDslNode, isNumber, isObject, isPage, isPageFragment, isPercentage, isPop, isSameDomain, isValueIncludeDataSource, removeClassName, removeClassNameByClassName, removeDataSourceFieldPrefix, replaceChildNode, setDslDomRelateConfig, setIdToEl, setUrlParam, setValueByKeyPath, sleep, toHump, toLine, traverseNode };
116
117
  export type { NodeItem };