sculp-js 1.7.1 → 1.8.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.
- package/README.md +5 -3
- package/lib/cjs/array.js +1 -1
- package/lib/cjs/async.js +1 -1
- package/lib/cjs/base64.js +1 -1
- package/lib/cjs/clipboard.js +1 -1
- package/lib/cjs/cookie.js +1 -1
- package/lib/cjs/date.js +1 -1
- package/lib/cjs/dom.js +1 -28
- package/lib/cjs/download.js +1 -1
- package/lib/cjs/easing.js +1 -1
- package/lib/cjs/file.js +1 -1
- package/lib/cjs/func.js +1 -1
- package/lib/cjs/index.js +3 -4
- package/lib/cjs/math.js +1 -1
- package/lib/cjs/number.js +1 -1
- package/lib/cjs/object.js +190 -24
- package/lib/cjs/path.js +1 -1
- package/lib/cjs/qs.js +1 -1
- package/lib/cjs/random.js +1 -1
- package/lib/cjs/string.js +1 -1
- package/lib/cjs/tooltip.js +1 -1
- package/lib/cjs/tree.js +30 -96
- package/lib/cjs/type.js +11 -4
- package/lib/cjs/unique.js +1 -1
- package/lib/cjs/url.js +1 -1
- package/lib/cjs/validator.js +1 -1
- package/lib/cjs/variable.js +1 -1
- package/lib/cjs/watermark.js +1 -1
- package/lib/cjs/we-decode.js +1 -1
- package/lib/es/array.js +1 -1
- package/lib/es/async.js +1 -1
- package/lib/es/base64.js +1 -1
- package/lib/es/clipboard.js +1 -1
- package/lib/es/cookie.js +1 -1
- package/lib/es/date.js +1 -1
- package/lib/es/dom.js +2 -27
- package/lib/es/download.js +1 -1
- package/lib/es/easing.js +1 -1
- package/lib/es/file.js +1 -1
- package/lib/es/func.js +1 -1
- package/lib/es/index.js +5 -5
- package/lib/es/math.js +1 -1
- package/lib/es/number.js +1 -1
- package/lib/es/object.js +190 -25
- package/lib/es/path.js +1 -1
- package/lib/es/qs.js +1 -1
- package/lib/es/random.js +1 -1
- package/lib/es/string.js +1 -1
- package/lib/es/tooltip.js +1 -1
- package/lib/es/tree.js +31 -96
- package/lib/es/type.js +11 -5
- package/lib/es/unique.js +1 -1
- package/lib/es/url.js +1 -1
- package/lib/es/validator.js +1 -1
- package/lib/es/variable.js +1 -1
- package/lib/es/watermark.js +1 -1
- package/lib/es/we-decode.js +1 -1
- package/lib/index.d.ts +52 -54
- package/lib/umd/index.js +228 -149
- package/package.json +3 -10
package/lib/index.d.ts
CHANGED
|
@@ -24,11 +24,15 @@ declare function objectHas<T extends AnyObject>(obj: T, key: keyof T): boolean;
|
|
|
24
24
|
*/
|
|
25
25
|
declare function arrayLike(any: unknown): boolean;
|
|
26
26
|
/**
|
|
27
|
-
*
|
|
27
|
+
* 判断任意值的数据类型,检查非对象时不如typeof、instanceof的性能高
|
|
28
|
+
*
|
|
29
|
+
* 当检查类对象时是不可靠的,对象可以通过定义 Symbol.toStringTag 属性来更改检查结果
|
|
30
|
+
*
|
|
31
|
+
* 详见:https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Object/toString
|
|
28
32
|
* @param {unknown} any
|
|
29
|
-
* @returns
|
|
33
|
+
* @returns
|
|
30
34
|
*/
|
|
31
|
-
declare
|
|
35
|
+
declare function typeIs(any: unknown): 'Null' | 'Undefined' | 'Symbol' | 'Boolean' | 'Number' | 'String' | 'Function' | 'Date' | 'RegExp' | 'Map' | 'Set' | 'ArrayBuffer' | 'Object' | 'Array' | 'Error' | 'BigInt' | 'Promise' | 'AsyncFunction' | string;
|
|
32
36
|
declare const isString: (any: unknown) => any is string;
|
|
33
37
|
declare const isBoolean: (any: unknown) => any is boolean;
|
|
34
38
|
declare const isSymbol: (any: unknown) => any is symbol;
|
|
@@ -38,6 +42,7 @@ declare const isUndefined: (any: unknown) => any is undefined;
|
|
|
38
42
|
declare const isNull: (any: unknown) => any is null;
|
|
39
43
|
declare const isPrimitive: (any: unknown) => boolean;
|
|
40
44
|
declare function isNullOrUnDef(val: unknown): val is null | undefined;
|
|
45
|
+
|
|
41
46
|
declare const isObject: (any: unknown) => any is Record<string, unknown>;
|
|
42
47
|
declare const isArray: (any: unknown) => any is unknown[];
|
|
43
48
|
/**
|
|
@@ -268,9 +273,6 @@ interface SmoothScrollOptions {
|
|
|
268
273
|
easing: EasingName;
|
|
269
274
|
}
|
|
270
275
|
declare function smoothScroll(options?: Partial<SmoothScrollOptions>): Promise<void>;
|
|
271
|
-
type ReadyCallback = () => void;
|
|
272
|
-
declare function isDomReady(): boolean;
|
|
273
|
-
declare function onDomReady(callback: ReadyCallback): void;
|
|
274
276
|
/**
|
|
275
277
|
* 获取元素样式属性的计算值
|
|
276
278
|
* @param {HTMLElement} el
|
|
@@ -380,7 +382,7 @@ declare function objectMap<O extends AnyObject, T>(obj: O, iterator: (val: O[key
|
|
|
380
382
|
*/
|
|
381
383
|
declare function objectPick<O extends AnyObject, K extends Extract<keyof O, string>[]>(obj: O, keys: K): Pick<O, ArrayElements<K>>;
|
|
382
384
|
/**
|
|
383
|
-
*
|
|
385
|
+
* 对象去除
|
|
384
386
|
* @param {O} obj
|
|
385
387
|
* @param {K} keys
|
|
386
388
|
* @returns {Pick<O, ArrayElements<K>>}
|
|
@@ -403,6 +405,13 @@ declare function objectAssign<R = AnyObject | AnyArray>(source: ObjectAssignItem
|
|
|
403
405
|
* @returns {R}
|
|
404
406
|
*/
|
|
405
407
|
declare function objectFill<R extends AnyObject = AnyObject>(source: Partial<R>, target: Partial<R>, fillable?: (s: typeof source, t: typeof target, key: keyof R) => boolean): R;
|
|
408
|
+
/**
|
|
409
|
+
* 获取对象指定层级下的属性值(现在可用ES6+的可选链?.来替代)
|
|
410
|
+
* @param {AnyObject} obj
|
|
411
|
+
* @param {string} path
|
|
412
|
+
* @param {boolean} strict
|
|
413
|
+
* @returns
|
|
414
|
+
*/
|
|
406
415
|
declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
407
416
|
p: any | undefined;
|
|
408
417
|
k: string | undefined;
|
|
@@ -410,11 +419,23 @@ declare function objectGet(obj: AnyObject, path: string, strict?: boolean): {
|
|
|
410
419
|
};
|
|
411
420
|
/**
|
|
412
421
|
* 深拷贝堪称完全体 即:任何类型的数据都会被深拷贝
|
|
422
|
+
*
|
|
423
|
+
* 包含对null、原始值、对象循环引用的处理
|
|
424
|
+
*
|
|
425
|
+
* 对Map、Set、ArrayBuffer、Date、RegExp、Array、Object及原型链属性方法执行深拷贝
|
|
413
426
|
* @param {T} source
|
|
414
427
|
* @param {WeakMap} map
|
|
415
428
|
* @returns {T}
|
|
416
429
|
*/
|
|
417
430
|
declare function cloneDeep<T>(source: T, map?: WeakMap<any, any>): T;
|
|
431
|
+
type Comparable = null | undefined | boolean | number | string | Date | RegExp | Map<any, any> | Set<any> | ArrayBuffer | object | Array<any>;
|
|
432
|
+
/**
|
|
433
|
+
* 比较两值是否相等,适用所有数据类型
|
|
434
|
+
* @param {Comparable} a
|
|
435
|
+
* @param {Comparable} b
|
|
436
|
+
* @returns {boolean}
|
|
437
|
+
*/
|
|
438
|
+
declare function isEqual(a: Comparable, b: Comparable): boolean;
|
|
418
439
|
|
|
419
440
|
/**
|
|
420
441
|
* 标准化路径
|
|
@@ -762,7 +783,12 @@ interface IFieldOptions {
|
|
|
762
783
|
interface ISearchTreeOpts {
|
|
763
784
|
childField: string;
|
|
764
785
|
nameField: string;
|
|
765
|
-
|
|
786
|
+
removeEmptyChild: boolean;
|
|
787
|
+
ignoreCase: boolean;
|
|
788
|
+
}
|
|
789
|
+
interface IFilterCondition<V> {
|
|
790
|
+
keyword?: string;
|
|
791
|
+
filter?: (args: V) => boolean;
|
|
766
792
|
}
|
|
767
793
|
/**
|
|
768
794
|
* 深度优先遍历函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
|
|
@@ -774,14 +800,18 @@ interface ISearchTreeOpts {
|
|
|
774
800
|
*/
|
|
775
801
|
declare function forEachDeep<V>(tree: ArrayLike<V>, iterator: (val: V, i: number, currentArr: ArrayLike<V>, tree: ArrayLike<V>, parent: V | null, level: number) => boolean | void, children?: string, isReverse?: boolean): void;
|
|
776
802
|
/**
|
|
777
|
-
* 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
|
|
803
|
+
* 创建一个新数组, 深度优先遍历的Map函数(支持continue和break操作), 可用于insert tree item 和 remove tree item
|
|
804
|
+
*
|
|
805
|
+
* 可遍历任何带有 length 属性和数字键的类数组对象
|
|
778
806
|
* @param {ArrayLike<V>} tree 树形数据
|
|
779
807
|
* @param {Function} iterator 迭代函数, 返回值为true时continue, 返回值为false时break
|
|
780
808
|
* @param {string} children 定制子元素的key
|
|
781
809
|
* @param {boolean} isReverse 是否反向遍历
|
|
782
810
|
* @returns {any[]} 新的一棵树
|
|
783
811
|
*/
|
|
784
|
-
declare function mapDeep<
|
|
812
|
+
declare function mapDeep<T>(tree: T[], iterator: (val: T, i: number, currentArr: T[], tree: T[], parent: T | null, level: number) => {
|
|
813
|
+
[k: string | number]: any;
|
|
814
|
+
} | boolean, children?: string, isReverse?: boolean): any[];
|
|
785
815
|
type IdLike = number | string;
|
|
786
816
|
interface ITreeConf {
|
|
787
817
|
id: string | number;
|
|
@@ -796,45 +826,6 @@ interface ITreeConf {
|
|
|
796
826
|
* @returns {[IdLike[], ITreeItem<V>[]]} - 由parentId...childId, parentObject-childObject组成的二维数组
|
|
797
827
|
*/
|
|
798
828
|
declare function searchTreeById<V>(tree: ArrayLike<V>, nodeId: IdLike, config?: ITreeConf): [IdLike[], ArrayLike<V>[]];
|
|
799
|
-
type WithChildren<T> = T & {
|
|
800
|
-
children?: WithChildren<T>[];
|
|
801
|
-
};
|
|
802
|
-
/**
|
|
803
|
-
* 根据 idProp 与 parentIdProp 从对象数组中构建对应的树
|
|
804
|
-
* 当 A[parentIdProp] === B[idProp] 时,对象A会被移动到对象B的children。
|
|
805
|
-
* 当一个对象的 parentIdProp 不与其他对象的 idProp 字段相等时,该对象被作为树的顶层节点
|
|
806
|
-
* @param {string} idProp 元素ID
|
|
807
|
-
* @param {string} parentIdProp 父元素ID
|
|
808
|
-
* @param {object[]} items 一维数组
|
|
809
|
-
* @returns {WithChildren<T>[]} 树
|
|
810
|
-
* @example
|
|
811
|
-
* const array = [
|
|
812
|
-
* { id: 'node-1', parent: 'root' },
|
|
813
|
-
* { id: 'node-2', parent: 'root' },
|
|
814
|
-
* { id: 'node-3', parent: 'node-2' },
|
|
815
|
-
* { id: 'node-4', parent: 'node-2' },
|
|
816
|
-
* { id: 'node-5', parent: 'node-4' },
|
|
817
|
-
* ]
|
|
818
|
-
* const tree = buildTree('id', 'parent', array)
|
|
819
|
-
* expect(tree).toEqual([
|
|
820
|
-
* { id: 'node-1', parent: 'root' },
|
|
821
|
-
* {
|
|
822
|
-
* id: 'node-2',
|
|
823
|
-
* parent: 'root',
|
|
824
|
-
* children: [
|
|
825
|
-
* { id: 'node-3', parent: 'node-2' },
|
|
826
|
-
* {
|
|
827
|
-
* id: 'node-4',
|
|
828
|
-
* parent: 'node-2',
|
|
829
|
-
* children: [{ id: 'node-5', parent: 'node-4' }],
|
|
830
|
-
* },
|
|
831
|
-
* ],
|
|
832
|
-
* },
|
|
833
|
-
* ])
|
|
834
|
-
*/
|
|
835
|
-
declare function buildTree<ID extends string, PID extends string, T extends {
|
|
836
|
-
[key in ID | PID]: string;
|
|
837
|
-
}>(idProp: ID, parentIdProp: PID, items: T[]): WithChildren<T>[];
|
|
838
829
|
/**
|
|
839
830
|
* 扁平化数组转换成树(效率高于buildTree)
|
|
840
831
|
* @param {any[]} list
|
|
@@ -851,12 +842,19 @@ declare function formatTree(list: any[], options?: IFieldOptions): any[];
|
|
|
851
842
|
declare function flatTree(treeList: any[], options?: IFieldOptions): any[];
|
|
852
843
|
/**
|
|
853
844
|
* 模糊搜索函数,返回包含搜索字符的节点及其祖先节点, 适用于树型组件的字符过滤功能
|
|
854
|
-
*
|
|
855
|
-
*
|
|
845
|
+
* 以下搜索条件二选一,按先后优先级处理:
|
|
846
|
+
* 1. 过滤函数filter, 返回true/false
|
|
847
|
+
* 2. 匹配关键词,支持是否启用忽略大小写来判断
|
|
848
|
+
*
|
|
849
|
+
* 有以下特性:
|
|
850
|
+
* 1. 可配置removeEmptyChild字段,来决定是否移除搜索结果中的空children字段
|
|
851
|
+
* 2. 若无任何过滤条件或keyword模式匹配且keyword为空串,返回原对象;其他情况返回新数组
|
|
852
|
+
* @param {V[]} nodes
|
|
853
|
+
* @param {IFilterCondition} filterCondition
|
|
856
854
|
* @param {ISearchTreeOpts} options
|
|
857
|
-
* @returns {
|
|
855
|
+
* @returns {V[]}
|
|
858
856
|
*/
|
|
859
|
-
declare function fuzzySearchTree(nodes:
|
|
857
|
+
declare function fuzzySearchTree<V>(nodes: V[], filterCondition: IFilterCondition<V>, options?: ISearchTreeOpts): V[];
|
|
860
858
|
|
|
861
859
|
/**
|
|
862
860
|
* 数值安全乘法
|
|
@@ -1057,4 +1055,4 @@ declare function replaceVarFromString(sourceStr: string, targetObj: Record<strin
|
|
|
1057
1055
|
*/
|
|
1058
1056
|
declare function executeInScope(code: string, scope?: Record<string, any>): any;
|
|
1059
1057
|
|
|
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
|
|
1058
|
+
export { type AnyArray, type AnyFunc, type AnyObject, type ArrayElements, type Comparable, type DateObj, type DateValue, type DebounceFunc, EMAIL_REGEX, type FileType, HEX_POOL, HTTP_URL_REGEX, type ICanvasWM, type ICompressOptions, type IFieldOptions, type IFilterCondition, 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 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, add, addClass, arrayEach, arrayEachAsync, arrayInsertBefore, arrayLike, arrayRemove, asyncMap, 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, formatDate, formatNumber, formatTree, fuzzySearchTree, genCanvasWM, getComputedCssVal, getGlobal, getStrWidthPx, getStyle, hasClass, isArray, isBigInt, isBoolean, isDate, isDigit, isEmail, isEmpty, isEqual, isError, isFloat, isFunction, isIdNo, isInteger, isIpV4, isIpV6, isJsonString, isNaN, isNull, isNullOrUnDef, isNullOrUnDef as isNullish, isNumber, isNumerical, isObject, isPhone, isPlainObject, isPrimitive, isRegExp, isString, isSymbol, isUndefined, isUrl, isValidDate, mapDeep, multiply, numberAbbr, numberToHex, objectAssign, objectEach, objectEachAsync, objectFill, objectGet, objectHas, objectMap, objectAssign as objectMerge, objectOmit, objectPick, 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 };
|