@fast-china/utils 2.1.6 → 2.1.7
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/CHANGELOG.md +7 -0
- package/README.md +2 -0
- package/README.zh.md +2 -0
- package/THIRD_PARTY_LICENSES.md +26 -0
- package/dist/crypto/index.mjs +2240 -33
- package/dist/crypto/index.mjs.map +1 -1
- package/dist/dom/index.mjs +2 -0
- package/dist/index.d.mts +1918 -32
- package/dist/index.global.min.js.map +1 -1
- package/dist/index.mjs +2 -0
- package/dist/vue/index.mjs +15 -0
- package/package.json +4 -6
- package/dist/array/index.d.mts +0 -94
- package/dist/async/index.d.mts +0 -145
- package/dist/base64/index.d.mts +0 -106
- package/dist/color/index.d.mts +0 -89
- package/dist/crypto/index.d.mts +0 -327
- package/dist/date/index.d.mts +0 -190
- package/dist/dom/style.d.mts +0 -29
- package/dist/env/index.d.mts +0 -62
- package/dist/function/index.d.mts +0 -13
- package/dist/identity/index.d.mts +0 -77
- package/dist/internal/text.d.mts +0 -15
- package/dist/logger/index.d.mts +0 -90
- package/dist/number/index.d.mts +0 -89
- package/dist/object/index.d.mts +0 -114
- package/dist/storage/index.d.mts +0 -115
- package/dist/string/index.d.mts +0 -141
- package/dist/vue/breakpoints.d.mts +0 -21
- package/dist/vue/element-size.d.mts +0 -25
- package/dist/vue/emits.d.mts +0 -23
- package/dist/vue/event-listener.d.mts +0 -16
- package/dist/vue/expose.d.mts +0 -11
- package/dist/vue/func.d.mts +0 -13
- package/dist/vue/index.d.mts +0 -15
- package/dist/vue/install.d.mts +0 -50
- package/dist/vue/now.d.mts +0 -13
- package/dist/vue/props.d.mts +0 -22
- package/dist/vue/render.d.mts +0 -11
- package/dist/vue/resize-observer.d.mts +0 -15
- package/dist/vue/slots.d.mts +0 -18
- package/dist/vue/window-size.d.mts +0 -16
- package/dist/vue/with.d.mts +0 -11
- package/docs/API.md +0 -155
- package/docs/API.zh-CN.md +0 -154
- package/docs/DEVELOPMENT_RELEASE.zh-CN.md +0 -65
- package/docs/RUNTIME_CONTRACT.md +0 -44
package/dist/index.mjs
CHANGED
|
@@ -6,6 +6,7 @@ import { contrastRatio, formatHexColor, mixHexColorWithBlack, mixHexColorWithWhi
|
|
|
6
6
|
import { AESDecrypt, AESDecryptAuthenticated, AESDecryptWithPassword, AESEncrypt, AESEncryptAuthenticated, AESEncryptWithPassword, DeriveECDHKeySHA256, DeriveECDHSecret, ECDSASign, ECDSAVerify, FixedTimeEquals, GenerateECDHKeyPair, GenerateECDSAKeyPair, GenerateRSAKeyPair, GenerateRandomBytes, HKDFSHA256, HMACSHA256Encrypt, HMACSHA384Encrypt, HMACSHA512Encrypt, HashPasswordPBKDF2SHA256, MD5Encrypt, PBKDF2SHA256, RSADecryptOAEP, RSAEncryptOAEP, RSASignPSS, RSAVerifyPSS, SHA1Encrypt, SHA256Bytes, SHA256Encrypt, SHA384Bytes, SHA384Encrypt, SHA512Bytes, SHA512Encrypt, VerifyPasswordPBKDF2SHA256 } from "./crypto/index.mjs";
|
|
7
7
|
import { addDays, addMonths, addYears, createDateRangeShortcuts, createDateShortcuts, createOneMonthRangeFromToday, endOfDay, formatChineseRelativeTime, formatRelativeTime, getLocalDayBounds, getLocalTimeGreeting, getStartOfToday, isDateAfterNow, isFuture, isSameDay, isValidDate, isWithinInterval, startOfDay, toDate } from "./date/index.mjs";
|
|
8
8
|
import { addCssUnit, serializeStyle } from "./dom/style.mjs";
|
|
9
|
+
import "./dom/index.mjs";
|
|
9
10
|
import { detectRuntime, hasWebCrypto, isBrowser, isMobileUserAgent, isNode, isTabletUserAgent, isUniApp, isWebWorker } from "./env/index.mjs";
|
|
10
11
|
import { once } from "./function/index.mjs";
|
|
11
12
|
import { Local, Session, base64StorageCodec, configureStorage, isStorageConfigured } from "./storage/index.mjs";
|
|
@@ -27,4 +28,5 @@ import { useRender } from "./vue/render.mjs";
|
|
|
27
28
|
import { makeSlots } from "./vue/slots.mjs";
|
|
28
29
|
import { useWindowSize } from "./vue/window-size.mjs";
|
|
29
30
|
import { withDefineType } from "./vue/with.mjs";
|
|
31
|
+
import "./vue/index.mjs";
|
|
30
32
|
export { AESDecrypt, AESDecryptAuthenticated, AESDecryptWithPassword, AESEncrypt, AESEncryptAuthenticated, AESEncryptWithPassword, DeriveECDHKeySHA256, DeriveECDHSecret, ECDSASign, ECDSAVerify, FixedTimeEquals, GenerateECDHKeyPair, GenerateECDSAKeyPair, GenerateRSAKeyPair, GenerateRandomBytes, HKDFSHA256, HMACSHA256Encrypt, HMACSHA384Encrypt, HMACSHA512Encrypt, HashPasswordPBKDF2SHA256, Local, MD5Encrypt, PBKDF2SHA256, RSADecryptOAEP, RSAEncryptOAEP, RSASignPSS, RSAVerifyPSS, SHA1Encrypt, SHA256Bytes, SHA256Encrypt, SHA384Bytes, SHA384Encrypt, SHA512Bytes, SHA512Encrypt, Session, VerifyPasswordPBKDF2SHA256, addCssUnit, addDays, addMonths, addYears, allEqualBy, average, base64StorageCodec, callOptionalFunction, camelCase, chunk, clamp, cloneDeep, configureInstallationIdentity, configureLogger, configureStorage, contrastRatio, copy, createDateRangeShortcuts, createDateShortcuts, createLogger, createOneMonthRangeFromToday, debounce, decodeBase64, decodeBase64Bytes, decodeBase64Url, decodeBase64UrlBytes, decodeLatin1Base64, decodeSecureBase64, decodeURIComponentRepeatedly, definePropType, detectRuntime, difference, encodeBase64, encodeBase64Bytes, encodeBase64Url, encodeBase64UrlBytes, encodeLatin1Base64, encodeSecureBase64, endOfDay, escapeHtml, formatBytes, formatChineseRelativeTime, formatHexColor, formatRelativeTime, generateUuidV4, getLocalDayBounds, getLocalTimeGreeting, getOrCreateInstallationId, getStartOfToday, groupBy, hasDuplicatesBy, hasOwn, hasWebCrypto, inRange, installationIdentity, intersection, isBrowser, isDateAfterNow, isEqual, isFuture, isMobileUserAgent, isNode, isPlainObject, isSameDay, isStorageConfigured, isTabletUserAgent, isUniApp, isUuidV4, isValidDate, isValidJson, isWebWorker, isWithinInterval, kebabCase, lerp, logger, lowerFirst, makeSlots, mapConcurrent, mapValues, mixHexColorWithBlack, mixHexColorWithWhite, mixHexColors, normalizeWhitespace, omit, omitBy, once, parseHexColor, parseQueryString, partition, pascalCase, pick, pickBy, pickHigherContrastColor, randomInt, randomString, relativeLuminance, removeNullishValues, retry, roundTo, serializeStyle, shallowEqual, sleep, splitWords, startOfDay, sum, symmetricDifference, throttle, toDate, toQueryString, truncateGraphemes, unique, uniqueBy, upperFirst, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall, withTimeout };
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { useEventListener } from "./event-listener.mjs";
|
|
2
|
+
import { useBreakpoints } from "./breakpoints.mjs";
|
|
3
|
+
import { useResizeObserver } from "./resize-observer.mjs";
|
|
4
|
+
import { useElementSize } from "./element-size.mjs";
|
|
5
|
+
import { useEmits } from "./emits.mjs";
|
|
6
|
+
import { useExpose } from "./expose.mjs";
|
|
7
|
+
import { callOptionalFunction } from "./func.mjs";
|
|
8
|
+
import { withInstall, withInstallDirective, withNoopInstall } from "./install.mjs";
|
|
9
|
+
import { useNow } from "./now.mjs";
|
|
10
|
+
import { definePropType, useProps } from "./props.mjs";
|
|
11
|
+
import { useRender } from "./render.mjs";
|
|
12
|
+
import { makeSlots } from "./slots.mjs";
|
|
13
|
+
import { useWindowSize } from "./window-size.mjs";
|
|
14
|
+
import { withDefineType } from "./with.mjs";
|
|
15
|
+
export { callOptionalFunction, definePropType, makeSlots, useBreakpoints, useElementSize, useEmits, useEventListener, useExpose, useNow, useProps, useRender, useResizeObserver, useWindowSize, withDefineType, withInstall, withInstallDirective, withNoopInstall };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@fast-china/utils",
|
|
3
|
-
"version": "2.1.
|
|
3
|
+
"version": "2.1.7",
|
|
4
4
|
"description": "Typed utilities for modern browsers, WebViews, Vue 3, and uni-app applications.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"keywords": [
|
|
@@ -27,8 +27,8 @@
|
|
|
27
27
|
"README.md",
|
|
28
28
|
"README.zh.md",
|
|
29
29
|
"SECURITY.md",
|
|
30
|
-
"
|
|
31
|
-
"
|
|
30
|
+
"THIRD_PARTY_LICENSES.md",
|
|
31
|
+
"dist"
|
|
32
32
|
],
|
|
33
33
|
"main": "./dist/index.mjs",
|
|
34
34
|
"module": "./dist/index.mjs",
|
|
@@ -64,14 +64,12 @@
|
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"vue": "^3.5.11"
|
|
66
66
|
},
|
|
67
|
-
"dependencies": {
|
|
68
|
-
"crypto-js": "^4.2.0"
|
|
69
|
-
},
|
|
70
67
|
"devDependencies": {
|
|
71
68
|
"@eslint/js": "^10.0.1",
|
|
72
69
|
"@eslint/markdown": "^8.0.3",
|
|
73
70
|
"@types/crypto-js": "^4.2.2",
|
|
74
71
|
"@types/node": "^24.13.4",
|
|
72
|
+
"crypto-js": "^4.2.0",
|
|
75
73
|
"eslint": "^10.10.0",
|
|
76
74
|
"eslint-config-flat-gitignore": "^2.4.0",
|
|
77
75
|
"eslint-config-prettier": "^10.1.8",
|
package/dist/array/index.d.mts
DELETED
|
@@ -1,94 +0,0 @@
|
|
|
1
|
-
//#region src/array/index.d.ts
|
|
2
|
-
/** 从数组项中提取可比较键的函数。 */
|
|
3
|
-
export type KeySelector<Item, Key> = (item: Item, index: number) => Key;
|
|
4
|
-
/**
|
|
5
|
-
* 将只读数组按固定大小分组。
|
|
6
|
-
*
|
|
7
|
-
* @typeParam Item - 数组项类型。
|
|
8
|
-
* @param items - 不会被修改的输入数组。
|
|
9
|
-
* @param size - 每组最多包含的项目数,必须是正安全整数。
|
|
10
|
-
* @returns 新建的二维数组;最后一组可能小于 `size`。
|
|
11
|
-
* @throws `RangeError` 当 `size` 不是正安全整数。
|
|
12
|
-
*/
|
|
13
|
-
export declare function chunk<Item>(items: readonly Item[], size: number): Item[][];
|
|
14
|
-
/**
|
|
15
|
-
* 删除数组中的 `null` 与 `undefined`,保留 `false`、`0` 和空字符串。
|
|
16
|
-
*
|
|
17
|
-
* @param items - 可包含空值的只读数组。
|
|
18
|
-
* @returns 保持原顺序的新数组。
|
|
19
|
-
*/
|
|
20
|
-
export declare function removeNullishValues<Item>(items: readonly (Item | null | undefined)[]): Item[];
|
|
21
|
-
/**
|
|
22
|
-
* 使用 JavaScript `Set` 的 SameValueZero 语义去重。
|
|
23
|
-
*
|
|
24
|
-
* @param items - 不会被修改的输入数组。
|
|
25
|
-
* @returns 保留每个值首次出现顺序的新数组;稀疏数组空位被忽略。
|
|
26
|
-
*/
|
|
27
|
-
export declare function unique<Item>(items: readonly Item[]): Item[];
|
|
28
|
-
/**
|
|
29
|
-
* 按选择器返回的键去重。
|
|
30
|
-
*
|
|
31
|
-
* @param items - 不会被修改的输入数组。
|
|
32
|
-
* @param selectKey - 接收项目与索引并返回去重键的函数。
|
|
33
|
-
* @returns 保留每个键首次出现项目的新数组;稀疏数组空位被忽略。
|
|
34
|
-
*/
|
|
35
|
-
export declare function uniqueBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): Item[];
|
|
36
|
-
/**
|
|
37
|
-
* 按选择器结果分组。
|
|
38
|
-
*
|
|
39
|
-
* @param items - 不会被修改的输入数组。
|
|
40
|
-
* @param selectKey - 返回任意 `Map` 键的函数。
|
|
41
|
-
* @returns 按键首次出现顺序排列的 `Map`;每个分组保持输入顺序,稀疏空位被忽略。
|
|
42
|
-
*/
|
|
43
|
-
export declare function groupBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): Map<Key, Item[]>;
|
|
44
|
-
/**
|
|
45
|
-
* 按谓词把数组拆分为匹配项和非匹配项。
|
|
46
|
-
*
|
|
47
|
-
* @param items - 不会被修改的输入数组。
|
|
48
|
-
* @param predicate - 接收项目与索引的判断函数。
|
|
49
|
-
* @returns 二元组:第一项匹配谓词,第二项不匹配;两组都保持原顺序并忽略稀疏空位。
|
|
50
|
-
*/
|
|
51
|
-
export declare function partition<Item>(items: readonly Item[], predicate: (item: Item, index: number) => boolean): [matched: Item[], unmatched: Item[]];
|
|
52
|
-
/**
|
|
53
|
-
* 返回只出现在左侧数组中的不同值。
|
|
54
|
-
*
|
|
55
|
-
* @param left - 主输入数组。
|
|
56
|
-
* @param right - 需要排除的值。
|
|
57
|
-
* @returns 保留左侧首次出现顺序的去重结果;两侧稀疏空位都被忽略。
|
|
58
|
-
*/
|
|
59
|
-
export declare function difference<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
60
|
-
/**
|
|
61
|
-
* 返回两个数组共有的不同值。
|
|
62
|
-
*
|
|
63
|
-
* @param left - 决定结果顺序的数组。
|
|
64
|
-
* @param right - 用于成员判断的数组。
|
|
65
|
-
* @returns 保留左侧首次出现顺序的去重结果;两侧稀疏空位都被忽略。
|
|
66
|
-
*/
|
|
67
|
-
export declare function intersection<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
68
|
-
/**
|
|
69
|
-
* 返回只存在于其中一个数组的不同值。
|
|
70
|
-
*
|
|
71
|
-
* @param left - 决定左侧结果顺序的数组。
|
|
72
|
-
* @param right - 决定右侧结果顺序的数组。
|
|
73
|
-
* @returns 先按左侧、再按右侧首次出现顺序排列的对称差集;使用 SameValueZero 比较并忽略稀疏空位。
|
|
74
|
-
*/
|
|
75
|
-
export declare function symmetricDifference<Item>(left: readonly Item[], right: readonly Item[]): Item[];
|
|
76
|
-
/**
|
|
77
|
-
* 判断选择器产生的键是否重复。
|
|
78
|
-
*
|
|
79
|
-
* @param items - 不会被修改的输入数组。
|
|
80
|
-
* @param selectKey - 返回比较键的函数;键使用 SameValueZero 语义比较。
|
|
81
|
-
* @returns 存在至少一个重复键时返回 `true`。
|
|
82
|
-
*/
|
|
83
|
-
export declare function hasDuplicatesBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): boolean;
|
|
84
|
-
/**
|
|
85
|
-
* 判断所有项目是否具有相同的选择器结果。
|
|
86
|
-
*
|
|
87
|
-
* @remarks 空数组、只有稀疏空位的数组和单项数组按数学惯例返回 `true`;空位不会调用选择器。
|
|
88
|
-
* @param items - 不会被修改的输入数组。
|
|
89
|
-
* @param selectKey - 返回比较键的函数。
|
|
90
|
-
* @returns 所有键都满足 SameValueZero 相等时返回 `true`。
|
|
91
|
-
*/
|
|
92
|
-
export declare function allEqualBy<Item, Key>(items: readonly Item[], selectKey: KeySelector<Item, Key>): boolean;
|
|
93
|
-
//#endregion
|
|
94
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/async/index.d.mts
DELETED
|
@@ -1,145 +0,0 @@
|
|
|
1
|
-
//#region src/async/index.d.ts
|
|
2
|
-
/** 统一同步返回值与 PromiseLike 返回值的内部回调签名。 */
|
|
3
|
-
type AsyncCallback<Arguments extends unknown[], Result> = (...arguments_: Arguments) => Result | PromiseLike<Result>;
|
|
4
|
-
/** 可接收取消信号的通用选项。 */
|
|
5
|
-
export interface AbortOptions {
|
|
6
|
-
/** 已取消时立即失败;运行期间取消时停止等待并拒绝 Promise。 */
|
|
7
|
-
signal?: AbortSignal;
|
|
8
|
-
}
|
|
9
|
-
/** {@link withTimeout} 的行为选项。 */
|
|
10
|
-
export interface TimeoutOptions extends AbortOptions {
|
|
11
|
-
/** 超时时使用的开发者消息。 */
|
|
12
|
-
message?: string;
|
|
13
|
-
}
|
|
14
|
-
/** 每次重试操作接收的上下文。 */
|
|
15
|
-
export interface RetryContext {
|
|
16
|
-
/** 从 1 开始的当前尝试次数。 */
|
|
17
|
-
attempt: number;
|
|
18
|
-
/** 调用方提供的取消信号。 */
|
|
19
|
-
signal?: AbortSignal;
|
|
20
|
-
}
|
|
21
|
-
/** {@link retry} 的策略选项。 */
|
|
22
|
-
export interface RetryOptions extends AbortOptions {
|
|
23
|
-
/** 最大尝试次数,包含首次调用;默认 `3`。 */
|
|
24
|
-
attempts?: number;
|
|
25
|
-
/** 首次重试前的等待毫秒数,最大 2,147,483,647;默认 `200`。 */
|
|
26
|
-
delayMs?: number;
|
|
27
|
-
/** 每次失败后的退避倍数,必须不小于 1;默认 `2`。 */
|
|
28
|
-
factor?: number;
|
|
29
|
-
/** 单次等待上限,最大 2,147,483,647;默认 `30_000` 毫秒。 */
|
|
30
|
-
maxDelayMs?: number;
|
|
31
|
-
/**
|
|
32
|
-
* 决定当前失败后是否继续下一次尝试;默认重试所有尚未到达上限的错误。
|
|
33
|
-
* @param error - 当前操作抛出或拒绝的原始值。
|
|
34
|
-
* @param context - 当前尝试次数和调用方取消信号。
|
|
35
|
-
* @returns `false` 时立即原样抛出当前错误;支持同步值或 PromiseLike。
|
|
36
|
-
*/
|
|
37
|
-
shouldRetry?: (error: unknown, context: RetryContext) => boolean | PromiseLike<boolean>;
|
|
38
|
-
}
|
|
39
|
-
/** {@link mapConcurrent} 的执行选项。 */
|
|
40
|
-
export interface ConcurrentMapOptions {
|
|
41
|
-
/** 已取消时停止调度新任务;已经开始的映射器需要自行响应同一信号。 */
|
|
42
|
-
signal?: AbortSignal;
|
|
43
|
-
}
|
|
44
|
-
/** Promise 感知的防抖函数。 */
|
|
45
|
-
export interface DebouncedFunction<Arguments extends unknown[], Result> {
|
|
46
|
-
/**
|
|
47
|
-
* 调度一次调用;同一等待窗口内的调用共享最后一组参数对应的结果。
|
|
48
|
-
* @param arguments_ - 传给原始回调的参数;后续调用会覆盖尚未执行批次保存的参数。
|
|
49
|
-
* @returns 当前批次的独立 Promise,最终与共享回调结果保持相同状态。
|
|
50
|
-
*/
|
|
51
|
-
(...arguments_: Arguments): Promise<Result>;
|
|
52
|
-
/**
|
|
53
|
-
* 取消尚未执行的批次,并拒绝该批次的所有 Promise。
|
|
54
|
-
* @param reason - 可选拒绝原因;省略时使用内部取消错误。
|
|
55
|
-
*/
|
|
56
|
-
cancel: (reason?: unknown) => void;
|
|
57
|
-
/**
|
|
58
|
-
* 立即执行待处理批次,不创建第二次回调执行。
|
|
59
|
-
* @returns 待处理批次的共享执行 Promise;没有批次时返回 `undefined`。
|
|
60
|
-
*/
|
|
61
|
-
flush: () => Promise<Result> | undefined;
|
|
62
|
-
/** @returns 当前存在尚未开始的批次时返回 `true`;正在执行但没有等待批次时返回 `false`。 */
|
|
63
|
-
pending: () => boolean;
|
|
64
|
-
}
|
|
65
|
-
/** Promise 感知的前缘节流函数。 */
|
|
66
|
-
export interface ThrottledFunction<Arguments extends unknown[], Result> {
|
|
67
|
-
/**
|
|
68
|
-
* 在空闲时立即调用原始回调;执行期和冷却期内的调用共享首次调用的 Promise。
|
|
69
|
-
* @param arguments_ - 仅窗口内首次调用的参数会传给原始回调。
|
|
70
|
-
* @returns 当前执行窗口共享的 Promise。
|
|
71
|
-
*/
|
|
72
|
-
(...arguments_: Arguments): Promise<Result>;
|
|
73
|
-
/** 提前结束冷却期;已经开始的操作不会被取消,结束前仍禁止并发重入。 */
|
|
74
|
-
cancel: () => void;
|
|
75
|
-
/** @returns 原始回调正在执行或计时器仍处于冷却期时返回 `true`。 */
|
|
76
|
-
pending: () => boolean;
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* 等待指定时间,并支持 `AbortSignal`。
|
|
80
|
-
*
|
|
81
|
-
* @param milliseconds - 0 至 2,147,483,647 的有限毫秒数。
|
|
82
|
-
* @param options - 可选取消信号。
|
|
83
|
-
* @returns 到期后完成的 Promise。
|
|
84
|
-
* @throws 取消时抛出名称为 `AbortError` 的 `Error`;参数非法时抛出 `RangeError`。
|
|
85
|
-
*/
|
|
86
|
-
export declare function sleep(milliseconds: number, options?: AbortOptions): Promise<void>;
|
|
87
|
-
/**
|
|
88
|
-
* 为 Promise 增加等待上限。
|
|
89
|
-
*
|
|
90
|
-
* @remarks 超时或取消只停止等待,不能自动取消底层操作;需要真正取消时应同时把
|
|
91
|
-
* 同一个 `AbortSignal` 传给底层 API。
|
|
92
|
-
* @param promise - 需要等待的 Promise 或 PromiseLike。
|
|
93
|
-
* @param timeoutMs - 0 至 2,147,483,647 的有限等待时间。
|
|
94
|
-
* @param options - 取消信号与自定义消息。
|
|
95
|
-
* @returns 底层 Promise 的结果。
|
|
96
|
-
* @throws 超时抛出 `Error`,取消时抛出名称为 `AbortError` 的 `Error`;等待时间非法时抛出 `RangeError`。
|
|
97
|
-
*/
|
|
98
|
-
export declare function withTimeout<Result>(promise: PromiseLike<Result>, timeoutMs: number, options?: TimeoutOptions): Promise<Result>;
|
|
99
|
-
/**
|
|
100
|
-
* 使用有上限的指数退避重试操作。
|
|
101
|
-
*
|
|
102
|
-
* @typeParam Result - 操作结果类型。
|
|
103
|
-
* @param operation - 每次尝试都会调用的函数;`attempt` 从 1 开始。
|
|
104
|
-
* @param options - 尝试次数、退避和取消策略。
|
|
105
|
-
* @returns 首次成功结果。
|
|
106
|
-
* @throws 最后一次操作错误、`shouldRetry` 错误或名称为 `AbortError` 的取消错误;策略参数非法时抛出 `RangeError`。
|
|
107
|
-
*/
|
|
108
|
-
export declare function retry<Result>(operation: (context: RetryContext) => Result | PromiseLike<Result>, options?: RetryOptions): Promise<Awaited<Result>>;
|
|
109
|
-
/**
|
|
110
|
-
* 以固定并发度映射数组,并保持结果顺序。
|
|
111
|
-
*
|
|
112
|
-
* @remarks 任一映射失败后不会再调度新项目,但已经开始的映射无法自动取消;映射器
|
|
113
|
-
* 应使用传入的 `signal` 取消底层工作。
|
|
114
|
-
* @param items - 不会被修改的输入数组。
|
|
115
|
-
* @param concurrency - 同时运行的最大任务数,必须为正安全整数。
|
|
116
|
-
* @param mapper - 接收项目、索引和取消信号的映射函数。
|
|
117
|
-
* @param options - 可选取消信号。
|
|
118
|
-
* @returns 与输入长度和顺序一致的结果数组;稀疏空位保持为空位且不会调用映射器。
|
|
119
|
-
* @throws `RangeError` 当 `concurrency` 不是正安全整数;取消时抛出名称为 `AbortError` 的 `Error`。
|
|
120
|
-
*/
|
|
121
|
-
export declare function mapConcurrent<Item, Result>(items: readonly Item[], concurrency: number, mapper: (item: Item, index: number, signal: AbortSignal | undefined) => Result | PromiseLike<Result>, options?: ConcurrentMapOptions): Promise<Awaited<Result>[]>;
|
|
122
|
-
/**
|
|
123
|
-
* 创建 Promise 感知的防抖函数。
|
|
124
|
-
*
|
|
125
|
-
* @remarks 同一窗口内的所有调用都会等待最后一组参数对应的执行结果;回调错误会原样
|
|
126
|
-
* 拒绝该批次的全部调用,不会留下永久 pending 的 Promise。
|
|
127
|
-
* @param callback - 同步或异步回调。
|
|
128
|
-
* @param delayMs - 0 至 2,147,483,647 的有限等待时间,默认 300 毫秒。
|
|
129
|
-
* @returns 具有取消、立即执行和状态方法的防抖函数。
|
|
130
|
-
* @throws `RangeError` 当延迟不在平台计时器支持范围内。
|
|
131
|
-
*/
|
|
132
|
-
export declare function debounce<Arguments extends unknown[], Result>(callback: AsyncCallback<Arguments, Result>, delayMs?: number): DebouncedFunction<Arguments, Awaited<Result>>;
|
|
133
|
-
/**
|
|
134
|
-
* 创建 Promise 感知的前缘节流函数。
|
|
135
|
-
*
|
|
136
|
-
* @remarks 窗口内的调用共享首次调用结果。若回调执行时间超过窗口,后续调用仍会等待
|
|
137
|
-
* 当前回调,避免异步操作重入;该函数不安排尾缘调用。
|
|
138
|
-
* @param callback - 同步或异步回调。
|
|
139
|
-
* @param delayMs - 0 至 2,147,483,647 的有限冷却时间,默认 300 毫秒。
|
|
140
|
-
* @returns 具有取消和状态方法的前缘节流函数。
|
|
141
|
-
* @throws `RangeError` 当延迟不在平台计时器支持范围内。
|
|
142
|
-
*/
|
|
143
|
-
export declare function throttle<Arguments extends unknown[], Result>(callback: AsyncCallback<Arguments, Result>, delayMs?: number): ThrottledFunction<Arguments, Awaited<Result>>;
|
|
144
|
-
//#endregion
|
|
145
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/base64/index.d.mts
DELETED
|
@@ -1,106 +0,0 @@
|
|
|
1
|
-
import { DecodedText } from "../internal/text.mjs";
|
|
2
|
-
//#region src/base64/index.d.ts
|
|
3
|
-
/**
|
|
4
|
-
* 将任意字节编码为标准 Base64。
|
|
5
|
-
*
|
|
6
|
-
* @param bytes - 不会被修改的字节序列。
|
|
7
|
-
* @returns 带标准 `=` 填充的 Base64 文本。
|
|
8
|
-
*/
|
|
9
|
-
export declare function encodeBase64Bytes(bytes: Uint8Array): string;
|
|
10
|
-
/**
|
|
11
|
-
* 解码标准 Base64。
|
|
12
|
-
*
|
|
13
|
-
* @remarks 允许省略填充和包含 ASCII 空白,但拒绝非规范尾部位。
|
|
14
|
-
* @param value - Base64 文本。
|
|
15
|
-
* @returns 新建的字节数组。
|
|
16
|
-
* @throws 输入非法时抛出 `TypeError`。
|
|
17
|
-
*/
|
|
18
|
-
export declare function decodeBase64Bytes(value: string): Uint8Array;
|
|
19
|
-
/**
|
|
20
|
-
* 将 UTF-8 文本编码为标准 Base64。
|
|
21
|
-
*
|
|
22
|
-
* @param value - 任意 Unicode 字符串。
|
|
23
|
-
* @returns 带标准填充的 Base64 文本。
|
|
24
|
-
* @throws 缺少 Encoding API 时抛出 `Error`。
|
|
25
|
-
*/
|
|
26
|
-
export declare function encodeBase64(value: string): string;
|
|
27
|
-
/**
|
|
28
|
-
* 将标准 Base64 解码为 UTF-8 文本。
|
|
29
|
-
*
|
|
30
|
-
* @param value - Base64 文本。
|
|
31
|
-
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 Unicode 字符串。
|
|
32
|
-
* @throws Base64 或 UTF-8 非法时抛出 `TypeError`;缺少 Encoding API 时抛出 `Error`。
|
|
33
|
-
*/
|
|
34
|
-
export declare function decodeBase64(value: string): DecodedText;
|
|
35
|
-
/**
|
|
36
|
-
* 将任意字节编码为无填充 Base64URL。
|
|
37
|
-
*
|
|
38
|
-
* @param bytes - 不会被修改的字节序列。
|
|
39
|
-
* @returns 仅使用 URL 安全字母表的文本。
|
|
40
|
-
*/
|
|
41
|
-
export declare function encodeBase64UrlBytes(bytes: Uint8Array): string;
|
|
42
|
-
/**
|
|
43
|
-
* 解码 Base64URL 字节。
|
|
44
|
-
*
|
|
45
|
-
* @remarks 接受带填充和无填充形式,不接受空白或标准 Base64 的 `+`、`/`。
|
|
46
|
-
* @param value - Base64URL 文本。
|
|
47
|
-
* @returns 新建的字节数组。
|
|
48
|
-
* @throws 输入非法时抛出 `TypeError`。
|
|
49
|
-
*/
|
|
50
|
-
export declare function decodeBase64UrlBytes(value: string): Uint8Array;
|
|
51
|
-
/**
|
|
52
|
-
* 将 UTF-8 文本编码为无填充 Base64URL。
|
|
53
|
-
*
|
|
54
|
-
* @param value - 任意 Unicode 字符串。
|
|
55
|
-
* @returns 仅使用 URL 安全字母表的文本。
|
|
56
|
-
* @throws 缺少 Encoding API 时抛出 `Error`。
|
|
57
|
-
*/
|
|
58
|
-
export declare function encodeBase64Url(value: string): string;
|
|
59
|
-
/**
|
|
60
|
-
* 将 Base64URL 解码为 UTF-8 文本。
|
|
61
|
-
*
|
|
62
|
-
* @param value - 带填充或无填充的 Base64URL 文本。
|
|
63
|
-
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 Unicode 字符串。
|
|
64
|
-
* @throws Base64URL 或 UTF-8 非法时抛出 `TypeError`;缺少 Encoding API 时抛出 `Error`。
|
|
65
|
-
*/
|
|
66
|
-
export declare function decodeBase64Url(value: string): DecodedText;
|
|
67
|
-
/**
|
|
68
|
-
* 把 Latin-1 文本编码为标准 Base64。
|
|
69
|
-
*
|
|
70
|
-
* @param value - 每个 UTF-16 码元都必须位于 0–255 的文本。
|
|
71
|
-
* @returns 带标准填充的 Base64 文本。
|
|
72
|
-
* @throws `TypeError` 当文本包含 Latin-1 范围外的码元。
|
|
73
|
-
*/
|
|
74
|
-
export declare function encodeLatin1Base64(value: string): string;
|
|
75
|
-
/**
|
|
76
|
-
* 把标准 Base64 解码为 Latin-1 文本。
|
|
77
|
-
*
|
|
78
|
-
* @param value - 标准 Base64 文本;允许 ASCII 空白和省略尾部填充。
|
|
79
|
-
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的 Latin-1 原始字符串。
|
|
80
|
-
* @throws `TypeError` 当 Base64 格式或尾部位非法。
|
|
81
|
-
*/
|
|
82
|
-
export declare function decodeLatin1Base64(value: string): DecodedText;
|
|
83
|
-
/**
|
|
84
|
-
* 使用固定字典和随机前缀编码文本。
|
|
85
|
-
*
|
|
86
|
-
* @remarks 给定相同的 6 字符前缀时,默认输出与旧有效载荷逐字符兼容。旧字典在 101–124 字符载荷中引用越界;这里复制末字符作为单字符回退,
|
|
87
|
-
* 使旧删除字典流程仍能解码。传入 `0` 会同时关闭随机前缀与字典插入。
|
|
88
|
-
* 该格式只是可逆编码,不提供加密、完整性或身份认证。
|
|
89
|
-
* @param value - 任意可由 `encodeURIComponent` 处理的 Unicode 文本。
|
|
90
|
-
* @param prefixLength - 随机字母前缀长度;默认 `6`。
|
|
91
|
-
* @returns 带随机前缀和兼容字典字符的 Base64 文本;空输入返回空字符串。
|
|
92
|
-
* @throws `RangeError` 当前缀长度不是非负安全整数;输入包含孤立代理项时保留平台错误。
|
|
93
|
-
*/
|
|
94
|
-
export declare function encodeSecureBase64(value: string, prefixLength?: number): string;
|
|
95
|
-
/**
|
|
96
|
-
* 解码 {@link encodeSecureBase64} 生成的 SecureBase64 兼容格式。
|
|
97
|
-
*
|
|
98
|
-
* @param value - SecureBase64 文本;必须使用与编码时相同的前缀长度。
|
|
99
|
-
* @param prefixLength - 需要移除的前缀长度;默认 `6`,传入 `0` 时不移除字典字符。
|
|
100
|
-
* @returns 可直接使用或显式调用 `.parseJson<Value>()` 的原始 Unicode 字符串;空输入返回空字符串。
|
|
101
|
-
* @throws `RangeError` 当前缀长度不是非负安全整数;载荷、Base64 或 URI 编码非法时抛出 `TypeError` 或 `URIError`。
|
|
102
|
-
*/
|
|
103
|
-
export declare function decodeSecureBase64(value: string, prefixLength?: number): DecodedText;
|
|
104
|
-
//#endregion
|
|
105
|
-
export type { DecodedText };
|
|
106
|
-
//# sourceMappingURL=index.d.mts.map
|
package/dist/color/index.d.mts
DELETED
|
@@ -1,89 +0,0 @@
|
|
|
1
|
-
//#region src/color/index.d.ts
|
|
2
|
-
/** 0 至 255 范围的 RGB 颜色。 */
|
|
3
|
-
export interface RgbColor {
|
|
4
|
-
/** 蓝色通道;必须是闭区间 `[0, 255]` 内的有限数,格式化时舍入到整数。 */
|
|
5
|
-
blue: number;
|
|
6
|
-
/** 绿色通道;必须是闭区间 `[0, 255]` 内的有限数,格式化时舍入到整数。 */
|
|
7
|
-
green: number;
|
|
8
|
-
/** 红色通道;必须是闭区间 `[0, 255]` 内的有限数,格式化时舍入到整数。 */
|
|
9
|
-
red: number;
|
|
10
|
-
}
|
|
11
|
-
/** 带 0 至 1 Alpha 通道的 RGB 颜色。 */
|
|
12
|
-
export interface RgbaColor extends RgbColor {
|
|
13
|
-
/** 不透明度;必须是闭区间 `[0, 1]` 内的有限数,`0` 完全透明,`1` 完全不透明。 */
|
|
14
|
-
alpha: number;
|
|
15
|
-
}
|
|
16
|
-
/**
|
|
17
|
-
* 解析可带可不带 `#` 的 `rgb`、`rgba`、`rrggbb` 或 `rrggbbaa`。
|
|
18
|
-
*
|
|
19
|
-
* @param value - 十六进制颜色文本。
|
|
20
|
-
* @returns 标准化的 RGBA 对象;省略 Alpha 时为 1。
|
|
21
|
-
* @throws 输入非法时抛出 `TypeError`。
|
|
22
|
-
*/
|
|
23
|
-
export declare function parseHexColor(value: string): RgbaColor;
|
|
24
|
-
/**
|
|
25
|
-
* 把 RGB 或 RGBA 对象格式化为小写十六进制颜色。
|
|
26
|
-
*
|
|
27
|
-
* @param color - 颜色通道;RGB 会四舍五入到最近整数。
|
|
28
|
-
* @param includeAlpha - 是否输出 Alpha;默认只在传入 Alpha 且小于 1 时输出。
|
|
29
|
-
* @returns 小写 `#rrggbb` 或 `#rrggbbaa` 文本。
|
|
30
|
-
* @throws 通道或 Alpha 非法时抛出 `RangeError`。
|
|
31
|
-
*/
|
|
32
|
-
export declare function formatHexColor(color: RgbColor | RgbaColor, includeAlpha?: boolean): string;
|
|
33
|
-
/**
|
|
34
|
-
* 线性混合两种十六进制颜色,包括 Alpha 通道。
|
|
35
|
-
*
|
|
36
|
-
* @param first - `amount = 0` 时的颜色。
|
|
37
|
-
* @param second - `amount = 1` 时的颜色。
|
|
38
|
-
* @param amount - 0 至 1 的混合比例。
|
|
39
|
-
* @returns 小写十六进制颜色;任一输入含透明度时保留 Alpha。
|
|
40
|
-
* @throws 颜色非法时抛出 `TypeError`;比例非法时抛出 `RangeError`。
|
|
41
|
-
*/
|
|
42
|
-
export declare function mixHexColors(first: string, second: string, amount: number): string;
|
|
43
|
-
/**
|
|
44
|
-
* 按比例向黑色混合。
|
|
45
|
-
*
|
|
46
|
-
* @param color - 合法十六进制颜色。
|
|
47
|
-
* @param amount - 0 至 1 的混合比例。
|
|
48
|
-
* @returns 混入黑色后的十六进制颜色;参数与异常语义见 {@link mixHexColors}。
|
|
49
|
-
*/
|
|
50
|
-
export declare function mixHexColorWithBlack(color: string, amount: number): string;
|
|
51
|
-
/**
|
|
52
|
-
* 按比例向白色混合。
|
|
53
|
-
*
|
|
54
|
-
* @param color - 合法十六进制颜色。
|
|
55
|
-
* @param amount - 0 至 1 的混合比例。
|
|
56
|
-
* @returns 混入白色后的十六进制颜色;参数与异常语义见 {@link mixHexColors}。
|
|
57
|
-
*/
|
|
58
|
-
export declare function mixHexColorWithWhite(color: string, amount: number): string;
|
|
59
|
-
/**
|
|
60
|
-
* 计算 WCAG sRGB 相对亮度。
|
|
61
|
-
*
|
|
62
|
-
* @remarks Alpha 通道不会参与计算;半透明颜色应先与实际背景混合。
|
|
63
|
-
* @param color - 合法十六进制颜色。
|
|
64
|
-
* @returns 0 至 1 的相对亮度。
|
|
65
|
-
* @throws 输入非法时抛出 `TypeError`。
|
|
66
|
-
*/
|
|
67
|
-
export declare function relativeLuminance(color: string): number;
|
|
68
|
-
/**
|
|
69
|
-
* 计算两种不透明颜色的 WCAG 对比度,范围 1 至 21。
|
|
70
|
-
*
|
|
71
|
-
* @remarks 返回比值本身,不代表特定字号或 WCAG 等级必然通过。
|
|
72
|
-
* @param first - 第一种十六进制颜色。
|
|
73
|
-
* @param second - 第二种十六进制颜色。
|
|
74
|
-
* @returns 较亮颜色与较暗颜色的对比度。
|
|
75
|
-
* @throws 输入非法时抛出 `TypeError`。
|
|
76
|
-
*/
|
|
77
|
-
export declare function contrastRatio(first: string, second: string): number;
|
|
78
|
-
/**
|
|
79
|
-
* 从两个候选颜色中选择与背景对比度更高的一项。
|
|
80
|
-
*
|
|
81
|
-
* @param background - 实际不透明背景色。
|
|
82
|
-
* @param first - 第一候选,默认黑色。
|
|
83
|
-
* @param second - 第二候选,默认白色。
|
|
84
|
-
* @returns 对比度较高的原始候选字符串;相同时返回 `first`。
|
|
85
|
-
* @throws 任一颜色非法时抛出 `TypeError`。
|
|
86
|
-
*/
|
|
87
|
-
export declare function pickHigherContrastColor(background: string, first?: string, second?: string): string;
|
|
88
|
-
//#endregion
|
|
89
|
-
//# sourceMappingURL=index.d.mts.map
|