sculp-js 1.5.1 → 1.7.0

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.
Files changed (61) hide show
  1. package/README.md +10 -1
  2. package/lib/cjs/array.js +2 -21
  3. package/lib/cjs/async.js +2 -2
  4. package/lib/cjs/base64.js +62 -0
  5. package/lib/cjs/clipboard.js +2 -2
  6. package/lib/cjs/cookie.js +2 -2
  7. package/lib/cjs/date.js +2 -3
  8. package/lib/cjs/dom.js +2 -2
  9. package/lib/cjs/download.js +2 -2
  10. package/lib/cjs/easing.js +2 -2
  11. package/lib/cjs/file.js +2 -2
  12. package/lib/cjs/func.js +3 -3
  13. package/lib/cjs/index.js +37 -4
  14. package/lib/cjs/math.js +88 -0
  15. package/lib/cjs/number.js +2 -2
  16. package/lib/cjs/object.js +10 -20
  17. package/lib/cjs/path.js +2 -2
  18. package/lib/cjs/qs.js +2 -2
  19. package/lib/cjs/random.js +2 -2
  20. package/lib/cjs/string.js +3 -3
  21. package/lib/cjs/tooltip.js +2 -2
  22. package/lib/cjs/tree.js +4 -4
  23. package/lib/cjs/type.js +69 -3
  24. package/lib/cjs/unique.js +2 -2
  25. package/lib/cjs/url.js +2 -2
  26. package/lib/cjs/validator.js +147 -0
  27. package/lib/cjs/variable.js +118 -0
  28. package/lib/cjs/watermark.js +2 -2
  29. package/lib/cjs/we-decode.js +4 -4
  30. package/lib/es/array.js +3 -21
  31. package/lib/es/async.js +2 -2
  32. package/lib/es/base64.js +59 -0
  33. package/lib/es/clipboard.js +2 -2
  34. package/lib/es/cookie.js +2 -2
  35. package/lib/es/date.js +2 -3
  36. package/lib/es/dom.js +2 -2
  37. package/lib/es/download.js +2 -2
  38. package/lib/es/easing.js +2 -2
  39. package/lib/es/file.js +2 -2
  40. package/lib/es/func.js +3 -3
  41. package/lib/es/index.js +9 -5
  42. package/lib/es/math.js +82 -0
  43. package/lib/es/number.js +2 -2
  44. package/lib/es/object.js +9 -18
  45. package/lib/es/path.js +2 -2
  46. package/lib/es/qs.js +2 -2
  47. package/lib/es/random.js +2 -2
  48. package/lib/es/string.js +3 -3
  49. package/lib/es/tooltip.js +2 -2
  50. package/lib/es/tree.js +4 -4
  51. package/lib/es/type.js +67 -4
  52. package/lib/es/unique.js +2 -2
  53. package/lib/es/url.js +2 -2
  54. package/lib/es/validator.js +130 -0
  55. package/lib/es/variable.js +112 -0
  56. package/lib/es/watermark.js +2 -2
  57. package/lib/es/we-decode.js +4 -4
  58. package/lib/index.d.ts +236 -21
  59. package/lib/tsdoc-metadata.json +11 -0
  60. package/lib/umd/index.js +571 -155
  61. package/package.json +2 -2
package/lib/index.d.ts CHANGED
@@ -9,6 +9,20 @@ type AnyObject = Record<string | number, any>;
9
9
  type PartialDeep<T> = {
10
10
  [P in keyof T]?: PartialDeep<T[P]>;
11
11
  };
12
+ /**
13
+ * 判断对象内是否有该静态属性
14
+ * @param {object} obj
15
+ * @param {string} key
16
+ * @returns {boolean}
17
+ */
18
+ declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
19
+ /**
20
+ * 判断一个对象是否为类数组
21
+ *
22
+ * @param any
23
+ * @returns {boolean}
24
+ */
25
+ declare function arrayLike(any: unknown): boolean;
12
26
  /**
13
27
  * 判断任意值的数据类型
14
28
  * @param {unknown} any
@@ -39,17 +53,40 @@ declare const isRegExp: (any: unknown) => any is RegExp;
39
53
  /**
40
54
  * 判断一个字符串是否为有效的 JSON, 若有效则返回有效的JSON对象,否则false
41
55
  * @param {string} str
42
- * @return {Object | boolean}
56
+ * @returns {Object | boolean}
43
57
  */
44
58
  declare function isJsonString(str: string): Object | boolean;
45
-
46
59
  /**
47
- * 判断一个对象是否为类数组
60
+ * Checks if `value` is an empty object, collection, map, or set.
48
61
  *
49
- * @param any
50
- * @returns {boolean}
62
+ * Objects are considered empty if they have no own enumerable string keyed
63
+ * properties.
64
+ *
65
+ * Array-like values such as `arguments` objects, arrays, buffers, strings, or
66
+ * jQuery-like collections are considered empty if they have a `length` of `0`.
67
+ * Similarly, maps and sets are considered empty if they have a `size` of `0`.
68
+ *
69
+ * @param {*} value The value to check.
70
+ * @returns {boolean} Returns `true` if `value` is empty, else `false`.
71
+ * @example
72
+ *
73
+ * isEmpty(null);
74
+ * // => true
75
+ *
76
+ * isEmpty(true);
77
+ * // => true
78
+ *
79
+ * isEmpty(1);
80
+ * // => true
81
+ *
82
+ * isEmpty([1, 2, 3]);
83
+ * // => false
84
+ *
85
+ * isEmpty({ 'a': 1 });
86
+ * // => false
51
87
  */
52
- declare function arrayLike(any: unknown): boolean;
88
+ declare function isEmpty(value: any): boolean;
89
+
53
90
  /**
54
91
  * 遍历数组,返回 false 中断遍历(支持continue和break操作)
55
92
  *
@@ -156,7 +193,6 @@ declare function dateToEnd(value: DateValue): Date;
156
193
  * - DD:日
157
194
  * - dd: 日
158
195
  * - HH:时(24 小时制)
159
- * - hh:时(12 小时制)
160
196
  * - mm:分
161
197
  * - ss:秒
162
198
  * - SSS:毫秒
@@ -317,13 +353,6 @@ declare function downloadData(data: AnyObject | AnyObject[], fileType: FileType,
317
353
  * @returns {boolean}
318
354
  */
319
355
  declare const isPlainObject: (obj: unknown) => boolean;
320
- /**
321
- * 判断对象内是否有该静态属性
322
- * @param {object} obj
323
- * @param {string} key
324
- * @returns {boolean}
325
- */
326
- declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
327
356
  /**
328
357
  * 遍历对象,返回 false 中断遍历
329
358
  * @param {O} obj
@@ -463,7 +492,7 @@ declare const stringFill: (length: number, value?: string) => string;
463
492
  /**
464
493
  * 解析URL查询参数
465
494
  * @param {string} searchStr
466
- * @return {Record<string, string | string[]>}
495
+ * @returns {Record<string, string | string[]>}
467
496
  */
468
497
  declare function parseQueryParams(searchStr?: string): Record<string, string | string[]>;
469
498
 
@@ -616,7 +645,7 @@ declare const once: <F extends AnyFunc = AnyFunc>(func: F) => OnceFunc<F>;
616
645
  */
617
646
  declare function setGlobal(key: string | number | symbol, val?: any): void;
618
647
  /**
619
- * 设置全局变量
648
+ * 获取全局变量
620
649
  * @param {string | number | symbol} key
621
650
  * @param val
622
651
  */
@@ -817,7 +846,7 @@ declare function formatTree(list: any[], options?: IFieldOptions): any[];
817
846
  * 树形结构转扁平化
818
847
  * @param {any} treeList
819
848
  * @param {IFieldOptions} options
820
- * @return {*}
849
+ * @returns {*}
821
850
  */
822
851
  declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
823
852
  /**
@@ -825,21 +854,207 @@ declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
825
854
  * @param {any[]} nodes
826
855
  * @param {string} query
827
856
  * @param {ISearchTreeOpts} options
828
- * @return {any[]}
857
+ * @returns {any[]}
829
858
  */
830
859
  declare function fuzzySearchTree(nodes: any[], query: string, options?: ISearchTreeOpts): any[];
831
860
 
861
+ /**
862
+ * 数值安全乘法
863
+ * @param arg1 数值1
864
+ * @param arg2 数值2
865
+ */
866
+ declare const multiply: (arg1: number, arg2: number) => number;
867
+ /**
868
+ * 数值安全加法
869
+ * @param arg1 数值1
870
+ * @param arg2 数值2
871
+ */
872
+ declare const add: (arg1: number, arg2: number) => number;
873
+ /**
874
+ * 数值安全减法
875
+ * @param arg1 数值1
876
+ * @param arg2 数值2
877
+ */
878
+ declare const subtract: (arg1: number, arg2: number) => number;
879
+ /**
880
+ * 数值安全除法
881
+ * @param arg1 数值1
882
+ * @param arg2 数值2
883
+ */
884
+ declare const divide: (arg1: number, arg2: number) => number;
885
+ type NumberType = number | string;
886
+ /**
887
+ * Correct the given number to specifying significant digits.
888
+ *
889
+ * @param num The input number
890
+ * @param precision An integer specifying the number of significant digits
891
+ *
892
+ * @example strip(0.09999999999999998) === 0.1 // true
893
+ */
894
+ declare function strip(num: NumberType, precision?: number): number;
895
+
832
896
  /**
833
897
  * 字符串编码成Base64 (适用于任何环境,包括小程序)
834
898
  * @param {string} string
835
- * @return {string}
899
+ * @returns {string}
836
900
  */
837
901
  declare function weBtoa(string: string): string;
838
902
  /**
839
903
  * Base64解码为原始字符串(适用于任何环境,包括小程序)
840
904
  * @param {string} string
841
- * @return {string}
905
+ * @returns {string}
842
906
  */
843
907
  declare function weAtob(string: string): string;
844
908
 
845
- export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, type FileType, HEX_POOL, type ICanvasWM, type ICompressOptions, type IFieldOptions, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, type UniqueString, type Url, type WithChildren, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, downloadBlob, downloadData, downloadHref, downloadURL, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDomReady, isError, isFunction, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isObject, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isValidDate, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
909
+ /**
910
+ * 将base64编码的字符串转换为原始字符串,包括对中文内容的处理(高性能,且支持Web、Node、小程序等任意平台)
911
+ * @param base64 base64编码的字符串
912
+ * @returns 原始字符串,包括中文内容
913
+ */
914
+ declare function decodeFromBase64(base64: string): string;
915
+ /**
916
+ * 将原始字符串,包括中文内容,转换为base64编码的字符串(高性能,且支持Web、Node、小程序等任意平台)
917
+ * @param rawStr 原始字符串,包括中文内容
918
+ * @returns base64编码的字符串
919
+ */
920
+ declare function encodeToBase64(rawStr: string): string;
921
+
922
+ declare const EMAIL_REGEX: RegExp;
923
+ /**
924
+ * 判断字符串是否为邮箱格式,不对邮箱真实性做验证,如域名是否正确等
925
+ * @param {string} value
926
+ * @returns {boolean}
927
+ */
928
+ declare const isEmail: (value: string) => boolean;
929
+ declare const PHONE_REGEX: RegExp;
930
+ /**
931
+ * 判断字符串是否为宽松手机格式,即首位为 1 的 11 位数字都属于手机号
932
+ * @param {string} value
933
+ * @returns {boolean}
934
+ */
935
+ declare const isPhone: (value: string) => boolean;
936
+ /**
937
+ * 判断字符串是否为身份证号码格式
938
+ * @param {string} value
939
+ * @returns {boolean}
940
+ */
941
+ declare const isIdNo: (value: string) => boolean;
942
+ declare const URL_REGEX: RegExp;
943
+ declare const HTTP_URL_REGEX: RegExp;
944
+ /**
945
+ * 判断字符串是否为 url 格式,支持 http、https、ftp 协议,支持域名或者 ipV4
946
+ * @param {string} value
947
+ * @returns {boolean}
948
+ */
949
+ declare const isUrl: (url: string, includeFtp?: boolean) => boolean;
950
+ declare const IPV4_REGEX: RegExp;
951
+ declare const IPV6_REGEX: RegExp;
952
+ /**
953
+ * 判断字符串是否为 IPV4 格式,不对 ip 真实性做验证
954
+ * @param {string} value
955
+ * @returns {boolean}
956
+ */
957
+ declare const isIpV4: (value: string) => boolean;
958
+ /**
959
+ * 判断字符串是否为 IPV6 格式,不对 ip 真实性做验证
960
+ * @param {string} value
961
+ * @returns {boolean}
962
+ */
963
+ declare const isIpV6: (value: string) => boolean;
964
+ /**
965
+ * 判断字符串是否为整数(自然数),即 ...,-3,-2,-1,0,1,2,3,...
966
+ * @param {string} value
967
+ * @returns {boolean}
968
+ */
969
+ declare const isInteger: (value: string) => boolean;
970
+ /**
971
+ * 判断字符串是否为浮点数,即必须有小数点的有理数
972
+ * @param {string} value
973
+ * @returns {boolean}
974
+ */
975
+ declare const isFloat: (value: string) => boolean;
976
+ /**
977
+ * 判断字符串是否为正确数值,包括整数和浮点数
978
+ * @param {string} value
979
+ * @returns {boolean}
980
+ */
981
+ declare const isNumerical: (value: string) => boolean;
982
+ /**
983
+ * 判断字符串是否为数字,例如六位数字短信验证码(093031)
984
+ * @param {string} value
985
+ * @returns {boolean}
986
+ */
987
+ declare const isDigit: (value: string) => boolean;
988
+
989
+ /**
990
+ * 去除字符串中重复字符
991
+ * @param {string} str
992
+ * @returns string
993
+ * @example
994
+ *
995
+ * uniqueSymbol('1a1bac');
996
+ * // => '1abc'
997
+ */
998
+ declare function uniqueSymbol(str: string): string;
999
+ /**
1000
+ * 转义所有特殊字符
1001
+ * @param {string} str 原字符串
1002
+ * reference: https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Guide/Regular_expressions
1003
+ * @returns string
1004
+ */
1005
+ declare function escapeRegExp(str: string): string;
1006
+ /**
1007
+ * 解析字符串的插值变量
1008
+ * @param {string} str 字符串
1009
+ * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
1010
+ * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
1011
+ * @returns string[]
1012
+ * @example
1013
+ *
1014
+ * default match symbol {} same as /{\s*([^{}\s]*)\s*}/g
1015
+ */
1016
+ declare function parseVarFromString(str: string, leftMatchSymbol?: string, rightMatchSymbol?: string): string[];
1017
+ /**
1018
+ * 替换字符串中的插值变量
1019
+ * @param {string} sourceStr
1020
+ * @param {Record<string, any>} targetObj
1021
+ * @param {string} leftMatchSymbol 变量左侧匹配符号,默认:{
1022
+ * @param {string} rightMatchSymbol 变量右侧匹配符号,默认:}
1023
+ * @returns string
1024
+ */
1025
+ declare function replaceVarFromString(sourceStr: string, targetObj: Record<string, any>, leftMatchSymbol?: string, rightMatchSymbol?: string): string;
1026
+ /**
1027
+ * 在指定作用域中执行代码
1028
+ * @param {string} code 要执行的代码(需包含 return 语句或表达式)
1029
+ * @param {Object} scope 作用域对象(键值对形式的变量环境)
1030
+ * @returns 代码执行结果
1031
+ *
1032
+ * @example
1033
+ * // 测试用例 1: 基本变量访问
1034
+ * executeInScope("return a + b;", { a: 1, b: 2 });
1035
+ * // 3
1036
+ *
1037
+ * // 测试用例 2: 支持复杂表达式和运算
1038
+ * executeInScope(
1039
+ * "return Array.from({ length: 3 }, (_, i) => base + i);",
1040
+ * { base: 100 }
1041
+ * );
1042
+ * // [100, 101, 102]
1043
+ *
1044
+ * // 支持外传函数作用域执行
1045
+ * const scope = {
1046
+ * $: {
1047
+ * fun: {
1048
+ * time: {
1049
+ * now: function () {
1050
+ * return new Date();
1051
+ * },
1052
+ * },
1053
+ * },
1054
+ * },
1055
+ * };
1056
+ * executeInScope("return $.fun.time.now()", scope)
1057
+ */
1058
+ declare function executeInScope(code: string, scope?: Record<string, any>): any;
1059
+
1060
+ export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, IPV4_REGEX, IPV6_REGEX, type ISearchTreeOpts, type ITreeConf, type IdLike, type LooseParamValue, type LooseParams, type ObjectAssignItem, type OnceFunc, PHONE_REGEX, type Params, type PartialDeep, type RandomString, type ReadyCallback, type Replacer, STRING_ARABIC_NUMERALS, STRING_LOWERCASE_ALPHA, STRING_POOL, STRING_UPPERCASE_ALPHA, type SetStyle, type SmoothScrollOptions, type Style, type ThrottleFunc, UNIQUE_NUMBER_SAFE_LENGTH, URL_REGEX, type UniqueString, type Url, type WithChildren, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, buildTree, calculateDate, calculateDateTime, chooseLocalFile, cloneDeep, compressImg, cookieDel, cookieGet, cookieSet, copyText, crossOriginDownload, dateParse, dateToEnd, dateToStart, debounce, decodeFromBase64, divide, downloadBlob, downloadData, downloadHref, downloadURL, encodeToBase64, escapeRegExp, executeInScope, flatTree, forEachDeep, forEachMap, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDigit, isDomReady, isEmail, isEmpty, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, onDomReady, once, parseQueryParams, parseVarFromString, pathJoin, pathNormalize, qsParse, qsStringify, randomNumber, randomString, randomUuid, removeClass, replaceVarFromString, searchTreeById, setGlobal, setStyle, smoothScroll, stringAssign, stringCamelCase, stringEscapeHtml, stringFill, stringFormat, stringKebabCase, strip, subtract, supportCanvas, throttle, tooltipEvent, typeIs, uniqueNumber, uniqueString, uniqueSymbol, urlDelParams, urlParse, urlSetParams, urlStringify, wait, weAtob, weBtoa };
@@ -0,0 +1,11 @@
1
+ // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
+ // It should be published with your NPM package. It should not be tracked by Git.
3
+ {
4
+ "tsdocVersion": "0.12",
5
+ "toolPackages": [
6
+ {
7
+ "packageName": "@microsoft/api-extractor",
8
+ "packageVersion": "7.38.3"
9
+ }
10
+ ]
11
+ }