util-helpers 4.23.0 → 4.23.2

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 (49) hide show
  1. package/dist/util-helpers.js +453 -504
  2. package/dist/util-helpers.js.map +1 -1
  3. package/dist/util-helpers.min.js +1 -1
  4. package/dist/util-helpers.min.js.map +1 -1
  5. package/esm/VERSION.js +1 -1
  6. package/esm/getImageInfo.js +34 -40
  7. package/esm/index.js +1 -1
  8. package/esm/loadImage.js +32 -34
  9. package/esm/loadImageWithBlob.js +23 -24
  10. package/lib/VERSION.js +1 -1
  11. package/lib/getImageInfo.js +33 -39
  12. package/lib/index.js +1 -1
  13. package/lib/loadImage.js +31 -33
  14. package/lib/loadImageWithBlob.js +23 -24
  15. package/package.json +14 -13
  16. package/types/AsyncMemo.d.ts +2 -2
  17. package/types/ajax.d.ts +2 -2
  18. package/types/blobToDataURL.d.ts +1 -1
  19. package/types/calculateCursorPosition.d.ts +2 -2
  20. package/types/compressImage.d.ts +1 -1
  21. package/types/dataURLToBlob.d.ts +1 -1
  22. package/types/download.d.ts +3 -3
  23. package/types/fileReader.d.ts +1 -1
  24. package/types/gcd.d.ts +1 -1
  25. package/types/getImageInfo.d.ts +11 -10
  26. package/types/index.d.ts +2 -2
  27. package/types/isBankCard.d.ts +1 -1
  28. package/types/isBusinessLicense.d.ts +1 -1
  29. package/types/isChinese.d.ts +3 -3
  30. package/types/isHMCard.d.ts +1 -1
  31. package/types/isIdCard.d.ts +2 -2
  32. package/types/isPassport.d.ts +1 -1
  33. package/types/isPassword.d.ts +1 -1
  34. package/types/isSocialCreditCode.d.ts +1 -1
  35. package/types/isSwiftCode.d.ts +1 -1
  36. package/types/isTWCard.d.ts +1 -1
  37. package/types/isUrl.d.ts +1 -1
  38. package/types/isVehicle.d.ts +1 -1
  39. package/types/lcm.d.ts +1 -1
  40. package/types/loadImage.d.ts +2 -0
  41. package/types/loadImageWithBlob.d.ts +6 -4
  42. package/types/normalizeString.d.ts +1 -1
  43. package/types/numberToChinese.d.ts +1 -1
  44. package/types/parseIdCard.d.ts +1 -1
  45. package/types/safeDate.d.ts +1 -1
  46. package/types/setDataURLPrefix.d.ts +2 -2
  47. package/types/validatePassword.d.ts +1 -1
  48. package/esm/utils/Cache.js +0 -47
  49. package/lib/utils/Cache.js +0 -49
@@ -7,7 +7,7 @@
7
7
  * @static
8
8
  * @alias module:Processor.blobToDataURL
9
9
  * @since 4.1.0
10
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL | FileReader.readAsDataURL()}
10
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader/readAsDataURL FileReader.readAsDataURL()}
11
11
  * @deprecated 请使用 `fileReader` 方法
12
12
  * @param {Blob} blob Blob 或 File 对象
13
13
  * @returns {Promise<string>} data:URL 格式的 Base64 字符串。
@@ -9,8 +9,8 @@ type CalculateCursorPositionOptions = {
9
9
  * @static
10
10
  * @alias module:Other.calculateCursorPosition
11
11
  * @since 4.6.0
12
- * @see {@link https://2950v9.csb.app/ | h5示例}
13
- * @see {@link https://33ccy9.csb.app/ | react示例}
12
+ * @see {@link https://2950v9.csb.app/ h5示例}
13
+ * @see {@link https://33ccy9.csb.app/ react示例}
14
14
  * @param {number} prevPos 赋值前的光标位置,onChange/onInput的光标位置 e.target.selectionEnd
15
15
  * @param {string} prevCtrlValue 上一个格式化后的值
16
16
  * @param {string} rawValue 当前输入原值
@@ -38,7 +38,7 @@ interface CompressImage {
38
38
  * @function
39
39
  * @alias module:Other.compressImage
40
40
  * @since 4.20.0
41
- * @see {@link https://sytpwg.csb.app/ | 在线示例}
41
+ * @see {@link https://sytpwg.csb.app/ 在线示例}
42
42
  * @param {string | Blob} img 图片地址或 blob 对象
43
43
  * @param {Object} [options] 配置项
44
44
  * @param {number} [options.width] 自定义图片宽度,默认图片自身宽度
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Processor.dataURLToBlob
6
6
  * @since 4.1.0
7
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 | Base64}
7
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Glossary/Base64 Base64}
8
8
  * @param {string} data data: 协议的URL
9
9
  * @returns {Blob} Blob 对象
10
10
  * @example
@@ -38,9 +38,9 @@ type DownloadOptions = {
38
38
  * @static
39
39
  * @alias module:Other.download
40
40
  * @since 4.16.0
41
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers | Access-Control-Expose-Headers}
42
- * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 | MIME}
43
- * @see {@link https://9ykc9s.csb.app/ | 在线示例}
41
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Headers/Access-Control-Expose-Headers Access-Control-Expose-Headers}
42
+ * @see {@link https://zh.wikipedia.org/wiki/多用途互聯網郵件擴展 MIME}
43
+ * @see {@link https://9ykc9s.csb.app/ 在线示例}
44
44
  * @param {string|Blob|ArrayBuffer|TypedArray} data 字符串、blob数据或url地址
45
45
  * @param {string|DownloadOptions} [options] 文件名称 或 配置项
46
46
  * @returns {Promise<void>}
@@ -16,7 +16,7 @@ interface FileReader {
16
16
  *
17
17
  * @function
18
18
  * @alias module:Processor.fileReader
19
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader | FileReader}
19
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/API/FileReader FileReader}
20
20
  * @since 4.16.0
21
21
  * @param {Blob} blob Blob 或 File 对象
22
22
  * @param {'arrayBuffer'|'binaryString'|'dataURL'|'text'} [type='dataURL'] 读取类型
package/types/gcd.d.ts CHANGED
@@ -12,7 +12,7 @@
12
12
  * @static
13
13
  * @alias module:Math.gcd
14
14
  * @since 4.20.0
15
- * @see {@link https://baike.baidu.com/item/最大公约数 | 最大公约数}
15
+ * @see {@link https://baike.baidu.com/item/最大公约数 最大公约数}
16
16
  * @param {...(number|string)} nums 两个或多个整数。
17
17
  * @returns {number} 最大公约数。
18
18
  * @example
@@ -1,4 +1,14 @@
1
1
  import loadImageWithBlob from './loadImageWithBlob';
2
+ type Result = {
3
+ width: number;
4
+ height: number;
5
+ contrast: string;
6
+ measure: string;
7
+ size: string;
8
+ bytes: number;
9
+ image: HTMLImageElement;
10
+ blob: Blob;
11
+ };
2
12
  /**
3
13
  * @typedef {Object} ImageInfo 图片信息
4
14
  * @property {number} width 宽度
@@ -37,14 +47,5 @@ import loadImageWithBlob from './loadImageWithBlob';
37
47
  * });
38
48
  *
39
49
  */
40
- declare function getImageInfo(img: string | Blob, cacheOptions?: boolean | Parameters<typeof loadImageWithBlob>[1], ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<{
41
- width: number;
42
- height: number;
43
- contrast: string;
44
- measure: string;
45
- size: string;
46
- bytes: number;
47
- image: HTMLImageElement;
48
- blob: Blob;
49
- }>;
50
+ declare function getImageInfo(img: string | Blob, cacheOptions?: boolean | Parameters<typeof loadImageWithBlob>[1], ajaxOptions?: Parameters<typeof loadImageWithBlob>[2]): Promise<Result>;
50
51
  export default getImageInfo;
package/types/index.d.ts CHANGED
@@ -53,8 +53,8 @@ export { default as transformObjectValue } from './transformObjectValue';
53
53
  *
54
54
  * @module Math
55
55
  * @since 3.1.0
56
- * @see {@link https://github.com/camsong/blog/issues/9 | JavaScript 浮点数陷阱及解法}
57
- * @see {@link https://2zbuy.csb.app/ | JS浮点数计算测试}
56
+ * @see {@link https://github.com/camsong/blog/issues/9 JavaScript 浮点数陷阱及解法}
57
+ * @see {@link https://2zbuy.csb.app/ JS浮点数计算测试}
58
58
  * @example
59
59
  * // 从 4.12.0 版本开始,规范了有效数值。(注意:4.12.3 对有效数值重新定义)
60
60
  * // 有效数值即能通过 Number(value) 转为数字,且不能为 NaN 。
@@ -8,7 +8,7 @@ type Options = {
8
8
  * @static
9
9
  * @alias module:Validator.isBankCard
10
10
  * @since 1.1.0
11
- * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html | 常用银行账号位数参考}
11
+ * @see {@link https://kf.qq.com/faq/170112ABnm6b170112FvquAn.html 常用银行账号位数参考}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
14
  * @param {boolean} [options.loose=false] 宽松模式,8-30位数字
@@ -9,7 +9,7 @@ type Options = {
9
9
  * @static
10
10
  * @alias module:Validator.isBusinessLicense
11
11
  * @since 3.5.0
12
- * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html | GS15—2006 工商行政管理市场主体注册号编制规则}
12
+ * @see {@link https://wenku.baidu.com/view/19873704cc1755270722087c.html GS15—2006 工商行政管理市场主体注册号编制规则}
13
13
  * @param {*} value 要检测的值
14
14
  * @param {Object} [options] 配置项
15
15
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -8,9 +8,9 @@ type Options = {
8
8
  * @static
9
9
  * @alias module:Validator.isChinese
10
10
  * @since 1.1.0
11
- * @see {@link http://www.unicode.org/reports/tr38/#BlockListing | 4.4 Listing of Characters Covered by the Unihan Database}
12
- * @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射 | Unicode字符平面映射}
13
- * @see {@link https://zh.wikipedia.org/wiki/Unicode區段 | Unicode区段}
11
+ * @see {@link http://www.unicode.org/reports/tr38/#BlockListing 4.4 Listing of Characters Covered by the Unihan Database}
12
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode字符平面映射 Unicode字符平面映射}
13
+ * @see {@link https://zh.wikipedia.org/wiki/Unicode區段 Unicode区段}
14
14
  * @param {*} value 要检测的值
15
15
  * @param {Object} [options] 配置项
16
16
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,只要包含中文即为true
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Validator.isHMCard
6
6
  * @since 4.0.0
7
- * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证 | 港澳居民来往内地通行证}
7
+ * @see {@link https://zh.wikipedia.org/wiki/港澳居民来往内地通行证 港澳居民来往内地通行证}
8
8
  * @param {*} value 要检测的值
9
9
  * @returns {boolean} 是否为港澳居民来往内地通行证
10
10
  * @example
@@ -10,8 +10,8 @@ type Options = {
10
10
  * @static
11
11
  * @alias module:Validator.isIdCard
12
12
  * @since 1.1.0
13
- * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码 | 中华人民共和国公民身份号码}
14
- * @see {@link https://baike.baidu.com/item/居民身份证号码 | 居民身份证号码}
13
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国公民身份号码 中华人民共和国公民身份号码}
14
+ * @see {@link https://baike.baidu.com/item/居民身份证号码 居民身份证号码}
15
15
  * @param {*} value 要检测的值
16
16
  * @param {Object} [options] 配置项
17
17
  * @param {boolean} [options.loose=false] 宽松模式,支持15位身份证号码
@@ -5,7 +5,7 @@
5
5
  * @static
6
6
  * @alias module:Validator.isPassport
7
7
  * @since 1.1.0
8
- * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页 | 中华人民共和国护照#个人资料页}
8
+ * @see {@link https://zh.wikipedia.org/wiki/中华人民共和国护照#个人资料页 中华人民共和国护照#个人资料页}
9
9
  * @param {*} value 要检测的值
10
10
  * @returns {boolean} 值是否为护照号
11
11
  * @example
@@ -8,7 +8,7 @@ import validatePassword from './validatePassword';
8
8
  * @alias module:Validator.isPassword
9
9
  * @requires module:Validator.validatePassword
10
10
  * @since 1.1.0
11
- * @see {@link https://baike.baidu.com/item/ASCII#3 | ASCII}
11
+ * @see {@link https://baike.baidu.com/item/ASCII#3 ASCII}
12
12
  * @param {*} value 要检测的值
13
13
  * @param {Object} [options] 配置项
14
14
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
@@ -9,7 +9,7 @@ type Options = {
9
9
  * @static
10
10
  * @alias module:Validator.isSocialCreditCode
11
11
  * @since 1.1.0
12
- * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 | GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
12
+ * @see {@link https://zh.wikisource.org/zh-hans/GB_32100-2015_法人和其他组织统一社会信用代码编码规则 GB 32100-2015 法人和其他组织统一社会信用代码编码规则}
13
13
  * @param {*} value 要检测的值
14
14
  * @param {Object} [options] 配置项
15
15
  * @param {boolean} [options.checkCode=true] 是否校验最后一位校验码,如果为false,不校验校验位。
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Validator.isSwiftCode
6
6
  * @since 4.9.0
7
- * @see {@link https://zh.wikipedia.org/wiki/ISO_9362 | ISO 9362}
7
+ * @see {@link https://zh.wikipedia.org/wiki/ISO_9362 ISO 9362}
8
8
  * @param {*} value 要检测的值
9
9
  * @returns {boolean} 值是否为 Swift Code
10
10
  * @example
@@ -7,7 +7,7 @@ type Options = {
7
7
  * @static
8
8
  * @alias module:Validator.isTWCard
9
9
  * @since 4.0.0
10
- * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证 | 台湾居民来往大陆通行证}
10
+ * @see {@link https://zh.wikipedia.org/wiki/台湾居民来往大陆通行证 台湾居民来往大陆通行证}
11
11
  * @param {*} value 要检测的值
12
12
  * @param {Object} [options] 配置项
13
13
  * @param {boolean} [options.loose=false] 宽松模式。如果为true,表示支持一次性短期通行证
package/types/isUrl.d.ts CHANGED
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Validator.isUrl
6
6
  * @since 3.4.0
7
- * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符 | 统一资源定位符}
7
+ * @see {@link https://zh.wikipedia.org/wiki/统一资源定位符 统一资源定位符}
8
8
  * @param {*} value 要检测的值
9
9
  * @returns {boolean} 值是否为url
10
10
  * @example
@@ -4,7 +4,7 @@
4
4
  * @static
5
5
  * @alias module:Validator.isVehicle
6
6
  * @since 1.1.0
7
- * @see {@link https://baike.baidu.com/item/车牌号 | 车牌号}
7
+ * @see {@link https://baike.baidu.com/item/车牌号 车牌号}
8
8
  * @param {*} value 要检测的值
9
9
  * @returns {boolean} 值是否为车牌号
10
10
  * @example
package/types/lcm.d.ts CHANGED
@@ -14,7 +14,7 @@
14
14
  * @static
15
15
  * @alias module:Math.lcm
16
16
  * @since 4.20.0
17
- * @see {@link https://baike.baidu.com/item/最小公倍数 | 最小公倍数}
17
+ * @see {@link https://baike.baidu.com/item/最小公倍数 最小公倍数}
18
18
  * @param {...(number|string)} nums 两个或多个整数。
19
19
  * @returns {number} 最小公倍数。
20
20
  * @example
@@ -2,6 +2,7 @@
2
2
  * @typedef {Object} CacheOptions 缓存配置
3
3
  * @property {boolean} [useCache=true] 是否使用缓存
4
4
  * @property {boolean} [autoRevokeOnDel=true] 删除时自动释放缓存
5
+ * @property {string} [cacheKey] 缓存键
5
6
  */
6
7
  /**
7
8
  * 加载图片。
@@ -31,6 +32,7 @@
31
32
  */
32
33
  declare function loadImage(img: string | Blob, cacheOptions?: boolean | {
33
34
  useCache?: boolean;
35
+ cacheKey?: string;
34
36
  autoRevokeOnDel?: boolean;
35
37
  }): Promise<HTMLImageElement>;
36
38
  export default loadImage;
@@ -1,4 +1,8 @@
1
1
  import getFileBlob from './getFileBlob';
2
+ type Result = {
3
+ image: HTMLImageElement;
4
+ blob: Blob;
5
+ };
2
6
  /**
3
7
  * @typedef {Object} ImageWithBlob HTML图片元素和 blob 对象
4
8
  * @property {HTMLImageElement} image HTML图片元素
@@ -33,9 +37,7 @@ import getFileBlob from './getFileBlob';
33
37
  */
34
38
  declare function loadImageWithBlob(img: string | Blob, cacheOptions?: boolean | {
35
39
  useCache?: boolean;
40
+ cacheKey?: string;
36
41
  autoRevokeOnDel?: boolean;
37
- }, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<{
38
- image: HTMLImageElement;
39
- blob: Blob;
40
- }>;
42
+ }, ajaxOptions?: Parameters<typeof getFileBlob>[1]): Promise<Result>;
41
43
  export default loadImageWithBlob;
@@ -5,7 +5,7 @@
5
5
  * @static
6
6
  * @alias module:Processor.normalizeString
7
7
  * @since 4.3.0
8
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances | String}
8
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/String#string_instances String}
9
9
  * @deprecated 即将废弃,请使用 `import { toString } 'ut2'`
10
10
  * @param {*} value 待处理的值
11
11
  * @returns {string} 规整化的值
@@ -17,7 +17,7 @@ type Options = {
17
17
  * @static
18
18
  * @alias module:Processor.numberToChinese
19
19
  * @since 1.2.0
20
- * @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 | 出版物上数字用法}
20
+ * @see {@link https://openstd.samr.gov.cn/bzgk/gb/newGbInfo?hcno=F5DAC3377DA99C8D78AE66735B6359C7 出版物上数字用法}
21
21
  * @param {number} num 数字
22
22
  * @param {Object} [options] 配置项
23
23
  * @param {boolean} [options.big5=false] 繁体
@@ -36,7 +36,7 @@ type IdCardInfo = {
36
36
  * @static
37
37
  * @alias module:Processor.parseIdCard
38
38
  * @since 4.0.0
39
- * @see {@link https://baike.baidu.com/item/居民身份证号码 | 居民身份证号码}
39
+ * @see {@link https://baike.baidu.com/item/居民身份证号码 居民身份证号码}
40
40
  * @param {string} id 身份证号码,支持15位
41
41
  * @returns {IdCardInfo | null} 省份、生日、性别,省/市/区/年/月/日/性别编码。如果解析失败将返回 null 。
42
42
  * @example
@@ -13,7 +13,7 @@ interface SafeDate {
13
13
  * @function
14
14
  * @alias module:Processor.safeDate
15
15
  * @since 4.4.0
16
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date | Date}
16
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Global_Objects/Date Date}
17
17
  * @param {string|number|Date} [value] 日期时间字符串、毫秒数、日期对象
18
18
  * @param {...number} [args] 月/日/时/分/秒/毫秒
19
19
  * @returns {Date} Date 实例日期对象
@@ -6,8 +6,8 @@
6
6
  * @static
7
7
  * @alias module:Processor.setDataURLPrefix
8
8
  * @since 4.1.0
9
- * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs | Data URLs}
10
- * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types | MIME types}
9
+ * @see {@link https://developer.mozilla.org/zh-CN/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URLs}
10
+ * @see {@link https://mimesniff.spec.whatwg.org/#understanding-mime-types MIME types}
11
11
  * @param {string} data 数据本身
12
12
  * @param {string} [mimeType="image/png"] MIME 类型
13
13
  * @param {boolean} [base64=true] 添加 base64 标识
@@ -23,7 +23,7 @@ type Options = {
23
23
  * @static
24
24
  * @alias module:Validator.validatePassword
25
25
  * @since 3.7.0
26
- * @see {@link https://baike.baidu.com/item/ASCII#3 | ASCII}
26
+ * @see {@link https://baike.baidu.com/item/ASCII#3 ASCII}
27
27
  * @param {string} value 要检测的值
28
28
  * @param {Object} [options] 配置项
29
29
  * @param {number} [options.level=2] 密码强度 1-包含一种字符 2-包含两种字符 3-包含三种字符。(大写字母、小写字母、数字、特殊字符)
@@ -1,47 +0,0 @@
1
- import { __extends, __assign } from 'tslib';
2
- import Emitter from 'emitter-pro';
3
- import { forEach } from 'ut2';
4
-
5
- var Cache = (function (_super) {
6
- __extends(Cache, _super);
7
- function Cache(options) {
8
- var _this = _super.call(this) || this;
9
- _this.data = [];
10
- _this.options = __assign({ max: 10 }, options);
11
- return _this;
12
- }
13
- Cache.prototype.has = function (k) {
14
- return !!this.data.find(function (item) { return item.k === k; });
15
- };
16
- Cache.prototype.get = function (k) {
17
- var _a;
18
- return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
19
- };
20
- Cache.prototype.checkLimit = function () {
21
- var _this = this;
22
- if (this.options.max !== 0) {
23
- var limit = this.data.length - this.options.max;
24
- if (limit >= 0) {
25
- var delArr = this.data.splice(0, limit + 1);
26
- forEach(delArr, function (item) {
27
- _this.emit('del', item.v, item.k);
28
- });
29
- }
30
- }
31
- };
32
- Cache.prototype.set = function (k, v) {
33
- var newData = { k: k, v: v };
34
- if (this.has(k)) {
35
- var index = this.data.findIndex(function (item) { return item.k === k; });
36
- this.data.splice(index, 1, newData);
37
- }
38
- else {
39
- this.checkLimit();
40
- this.data.push(newData);
41
- }
42
- };
43
- return Cache;
44
- }(Emitter));
45
- var Cache$1 = Cache;
46
-
47
- export { Cache$1 as default };
@@ -1,49 +0,0 @@
1
- 'use strict';
2
-
3
- var tslib = require('tslib');
4
- var Emitter = require('emitter-pro');
5
- var ut2 = require('ut2');
6
-
7
- var Cache = (function (_super) {
8
- tslib.__extends(Cache, _super);
9
- function Cache(options) {
10
- var _this = _super.call(this) || this;
11
- _this.data = [];
12
- _this.options = tslib.__assign({ max: 10 }, options);
13
- return _this;
14
- }
15
- Cache.prototype.has = function (k) {
16
- return !!this.data.find(function (item) { return item.k === k; });
17
- };
18
- Cache.prototype.get = function (k) {
19
- var _a;
20
- return (_a = this.data.find(function (item) { return item.k === k; })) === null || _a === void 0 ? void 0 : _a.v;
21
- };
22
- Cache.prototype.checkLimit = function () {
23
- var _this = this;
24
- if (this.options.max !== 0) {
25
- var limit = this.data.length - this.options.max;
26
- if (limit >= 0) {
27
- var delArr = this.data.splice(0, limit + 1);
28
- ut2.forEach(delArr, function (item) {
29
- _this.emit('del', item.v, item.k);
30
- });
31
- }
32
- }
33
- };
34
- Cache.prototype.set = function (k, v) {
35
- var newData = { k: k, v: v };
36
- if (this.has(k)) {
37
- var index = this.data.findIndex(function (item) { return item.k === k; });
38
- this.data.splice(index, 1, newData);
39
- }
40
- else {
41
- this.checkLimit();
42
- this.data.push(newData);
43
- }
44
- };
45
- return Cache;
46
- }(Emitter));
47
- var Cache$1 = Cache;
48
-
49
- module.exports = Cache$1;