a-js-tools 0.1.0 → 0.1.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.
package/README.md CHANGED
@@ -1,30 +1,35 @@
1
1
  # a-js-tools
2
2
 
3
- [![version](<https://img.shields.io/npm/v/a-js-tools.svg?logo=npm&logoColor=rgb(0,0,0)&label=version&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![NPM Last Update](<https://img.shields.io/npm/last-update/a-js-tools?logo=npm&labelColor=rgb(255,36,63)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![📦 size](<https://img.shields.io/bundlephobia/minzip/a-js-tools.svg?logo=npm&labelColor=rgb(201,158,140)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![downloads](<https://img.shields.io/npm/dm/a-js-tools.svg?logo=npm&logoColor=rgb(0,0,0)&labelColor=rgb(194,112,210)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![downloads](<https://img.shields.io/npm/dt/a-js-tools.svg?logo=npm&labelColor=rgb(107,187,124)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools)
3
+ [![version](<https://img.shields.io/npm/v/a-js-tools.svg?logo=npm&logoColor=rgb(0,0,0)&label=版本号&labelColor=rgb(73,73,228)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![NPM Last Update](<https://img.shields.io/npm/last-update/a-js-tools?logo=npm&label=版本最后更新&labelColor=rgb(255,36,63)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![📦 size](<https://img.shields.io/bundlephobia/minzip/a-js-tools.svg?logo=npm&label=压缩包大小&labelColor=rgb(201,158,140)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![downloads](<https://img.shields.io/npm/dm/a-js-tools.svg?logo=npm&logoColor=rgb(0,0,0)&label=月下载量&labelColor=rgb(194,112,210)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools) [![downloads](<https://img.shields.io/npm/dt/a-js-tools.svg?logo=npm&label=总下载量&labelColor=rgb(107,187,124)&color=rgb(0,0,0)>)](https://www.npmjs.com/package/a-js-tools)
4
4
 
5
- [![last commit](<https://img.shields.io/github/last-commit/earthnutDev/a-js-tools.svg?logo=github&logoColor=rgb(0,0,0)&labelColor=rgb(255,165,0)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools) [![GitHub commit activity](<https://img.shields.io/github/commit-activity/y/earthnutDev/a-js-tools.svg?logo=github&labelColor=rgb(128,0,128)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools) [![Coverage Status](<https://img.shields.io/coverallsCoverage/github/earthnutDev/a-js-tools?logo=coveralls&label=coveralls&labelColor=rgb(12, 244, 39)&color=rgb(0,0,0)>)](https://coveralls.io/github/earthnutDev/a-js-tools?branch=main) [![codecov](<https://img.shields.io/codecov/c/github/earthnutDev/a-js-tools/main?logo=codecov&label=codecov&labelColor=rgb(7, 245, 245)&color=rgb(0,0,0)>)](https://codecov.io/gh/earthnutDev/a-js-tools)
5
+ [![last commit](<https://img.shields.io/github/last-commit/earthnutDev/a-js-tools.svg?logo=github&logoColor=rgb(0,0,0)&label=最后推码&labelColor=rgb(255,165,0)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools) [![GitHub commit activity](<https://img.shields.io/github/commit-activity/y/earthnutDev/a-js-tools.svg?logo=github&label=推码数&labelColor=rgb(128,0,128)&color=rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools) [![Coverage Status](<https://img.shields.io/coverallsCoverage/github/earthnutDev/a-js-tools?logo=coveralls&label=coveralls&labelColor=rgb(12, 244, 39)&color=rgb(0,0,0)>)](https://coveralls.io/github/earthnutDev/a-js-tools?branch=main) [![codecov](<https://img.shields.io/codecov/c/github/earthnutDev/a-js-tools/main?logo=codecov&label=codecov&labelColor=rgb(7, 245, 245)&color=rgb(0,0,0)>)](https://codecov.io/gh/earthnutDev/a-js-tools)
6
6
 
7
7
  ---
8
8
 
9
- [![🇨🇳 中文](<https://img.shields.io/badge/🇨🇳-中_%20_文-rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools/blob/main/README-zh.md) ![🌍 English](<https://img.shields.io/badge/🌍-English-rgb(0,0,0)?style=social>) [![👀 change log](<https://img.shields.io/badge/👀-change_%20_log-rgb(0,125,206)?logo=github>)](https://github.com/earthnutDev/a-js-tools/blob/main/CHANGELOG-en.md) [![submit 🙋‍♂️ issue](<https://img.shields.io/badge/☣️-submit_%20_issue-rgb(255,0,63)?logo=github>)](https://github.com/earthnutDev/a-js-tools/issues)
9
+ [![查看 📔 日志](<https://img.shields.io/badge/👀-日_%20_志-rgb(0,125,206)>)](https://github.com/earthnutDev/a-js-tools/blob/main/CHANGELOG.md) [![bug 🙋‍♂️ 提交](<https://img.shields.io/badge/☣️-bug_%20_提交-rgb(255,0,63)>)](https://github.com/earthnutDev/a-js-tools/issues)
10
10
 
11
11
  ---
12
12
 
13
- A purely functional tool that includes .
13
+ 一个纯函数的工具
14
+
15
+ ## 安装
16
+
17
+ ```sh
18
+ npm install a-js-tools --save
19
+ ```
14
20
 
15
21
  ## pure function
16
22
 
17
- - `typeOf` Verify data type
18
- - `lmDebounce` Anti shake function
19
- - `lmThrottle` Throttling function
20
- - `getRandomInt` get random int number
21
- - `getRandomFloat` get random float number
23
+ - `lmDebounce` 防抖函数
24
+ - `lmThrottle` 节流函数
25
+ - `getRandomInt` 获取随机的整数
26
+ - `getRandomFloat` 获取随机的浮点数
22
27
 
23
- ## class name
28
+ ## class 名称转化
24
29
 
25
30
  - `toLowerCamelCase` Convert hyphenation to hump
26
31
  - `toSplitCase` Convert small hump to hyphen split
27
32
 
28
- ## Documentation
33
+ ## 查看文档
29
34
 
30
- see [https://earthnut.dev/a-js-tools/](https://earthnut.dev/a-js-tools/)
35
+ 产看 [https://earthnut.dev/a-js-tools](https://earthnut.dev/a-js-tools)
@@ -0,0 +1,58 @@
1
+ 'use strict';
2
+
3
+ /**
4
+ * 驼峰命名与连字符命名法的互换
5
+ *
6
+ * @packageDocumentation
7
+ * @module @a-js-tools/class-name
8
+ * @license MIT
9
+ */
10
+ /**
11
+ *
12
+ * 连字符连接转化为小/大驼峰命名法
13
+ *
14
+ * @param str 待转化文本
15
+ * @param dividingType 连字符,缺省值为 "-"
16
+ * @param initial 是否转换第一个字符。默认值为 false (小驼峰类型)
17
+ * @returns 驼峰命名法字符串(e.g. “helloWorld”)
18
+ *
19
+ */
20
+ function toLowerCamelCase(
21
+ /** 待转化文本 */
22
+ str,
23
+ /** 连字符,缺省值为 "-" */
24
+ dividingType = '-',
25
+ /** 是否转换第一个字符。默认值为 false (小驼峰类型) */
26
+ initial = false) {
27
+ let result = str;
28
+ /**
29
+ * 匹配规则
30
+ *
31
+ * - 匹配到分隔符,将分隔符后面的字符转化为大写
32
+ */
33
+ const template = /[\\]|[\^]|[?]|[-]|[.]|[(]|[)]|[|]|[[]\[\]]|[{]|[}]|[+]|[*]|[$]/;
34
+ /** 转化首字符 */
35
+ const toTransform = (_str, _dividingType) => _str.replace(new RegExp(`${template.test(_dividingType) ? `\\${_dividingType}` : _dividingType}([a-zA-Z])`, 'g'), (match, p1) => p1.toUpperCase());
36
+ // 多分隔符转化
37
+ dividingType.split('').forEach((item) => {
38
+ result = toTransform(result, item);
39
+ });
40
+ return initial
41
+ ? result.replace(/^./, (match) => match.toUpperCase())
42
+ : result;
43
+ }
44
+ /**
45
+ * 驼峰命名法转化为连字符连接
46
+ *
47
+ * @param str 待转化文本
48
+ * @param dividingType 分割符
49
+ * @returns 分割符转化的文本 (e.g. 'hello-world')
50
+ *
51
+ */
52
+ function toSplitCase(str, dividingType = '-') {
53
+ const result = str.replace(/[A-Z]/g, (match) => dividingType.concat(match.toLowerCase()));
54
+ return result.startsWith(dividingType) ? result.substring(1) : result;
55
+ }
56
+
57
+ exports.toLowerCamelCase = toLowerCamelCase;
58
+ exports.toSplitCase = toSplitCase;
@@ -0,0 +1,76 @@
1
+ 'use strict';
2
+
3
+ var aTypeOfJs = require('a-type-of-js');
4
+
5
+ /**
6
+ * 过去随机数
7
+ *
8
+ * @packageDocumentation
9
+ * @module @a-js-tools/get-random-number
10
+ * @license MIT
11
+ */
12
+ /**
13
+ *
14
+ * 获取一个随机的整数类型
15
+ *
16
+ * 您可以传入两个参数并获取它们之间的任意数字
17
+ *
18
+ * 如果只传递一个参数,则如果提供的值为负数,则得到一个小于(或大于)该数字的整数
19
+ *
20
+ * @param max 较大值 ,不允许为`NaN`
21
+ * @param min 较小值,不允许为 `NaN`
22
+ * @returns 任意的整数
23
+ */
24
+ function getRandomInt(max = 1, min = 0) {
25
+ // 判断是否为 NaN 或 不是数字
26
+ if (!isFinite(max) ||
27
+ !isFinite(min) ||
28
+ aTypeOfJs.isNaN(max) ||
29
+ aTypeOfJs.isNaN(min) ||
30
+ !aTypeOfJs.isNumber(max) ||
31
+ !aTypeOfJs.isNumber(min)) {
32
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
33
+ }
34
+ /** 获取最小值 */
35
+ let _min = Math.ceil(Number(min)),
36
+ /** 获取最大值 */
37
+ _max = Math.floor(Number(max));
38
+ /** 两值交换 */
39
+ if (_min > _max)
40
+ [_max, _min] = [_min, _max];
41
+ //** 两值相等时,直接返回最大值 */
42
+ if (_max === _min)
43
+ return _max;
44
+ return Math.round(Math.random() * (_max - _min) + _min);
45
+ }
46
+ /**
47
+ *
48
+ * 获取任意的浮点数
49
+ *
50
+ * 您可以传入两个参数并获取它们之间的任意数字
51
+ *
52
+ * 如果只传入一个参数,则如果提供的值为负数,则获取小于(或大于)该数字的浮点数
53
+ *
54
+ * @param max 较大数,缺省值为 1
55
+ * @param min 较小值,缺省值为 0
56
+ * @returns 任意的浮点数
57
+ */
58
+ function getRandomFloat(max = 1, min = 0) {
59
+ // 判断是否为 NaN 或 不是数字
60
+ if (!isFinite(max) ||
61
+ !isFinite(min) ||
62
+ aTypeOfJs.isNaN(max) ||
63
+ aTypeOfJs.isNaN(min) ||
64
+ !aTypeOfJs.isNumber(max) ||
65
+ !aTypeOfJs.isNumber(min)) {
66
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
67
+ }
68
+ if (max == min)
69
+ max++;
70
+ if (min > max)
71
+ [max, min] = [min, max];
72
+ return Math.random() * (max - min) + min;
73
+ }
74
+
75
+ exports.getRandomFloat = getRandomFloat;
76
+ exports.getRandomInt = getRandomInt;
@@ -1,12 +1,19 @@
1
1
  'use strict';
2
2
 
3
- /**************************************
3
+ /**
4
+ * 防抖和节流
5
+ *
6
+ * @packageDocumentation
7
+ * @module @a-js-tools/performance
8
+ * @license MIT
9
+ */
10
+ /**
4
11
  *
5
- * 函数防抖
12
+ * 防抖
6
13
  *
7
- * @param {*} callback
8
- * @param {number} delay 缺省 300 ms
9
- * @return {*} 返回的是一个函数
14
+ * @param callback 回调函数
15
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
16
+ * @returns 返回的闭包函数
10
17
  * @example
11
18
  *
12
19
  * ```ts
@@ -17,8 +24,7 @@
17
24
  * }
18
25
  * }
19
26
  *
20
- **************************************/
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
27
+ */
22
28
  function debounce(callback, delay = 200) {
23
29
  if (typeof callback !== 'function') {
24
30
  throw new TypeError('callback must be a function');
@@ -51,12 +57,12 @@ function debounce(callback, delay = 200) {
51
57
  return result;
52
58
  }
53
59
  /**
54
- * 节流函数
55
- * @param callback
56
- * @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
57
- * @returns 返回的是一个函数
60
+ * 节流
61
+ *
62
+ * @param callback 回调函数
63
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
64
+ * @returns 返回的闭包函数
58
65
  */
59
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
60
66
  function throttle(callback, delay = 200) {
61
67
  // 强制转换非数值
62
68
  if (!isFinite(delay) || (isFinite(delay) && delay < 0))
@@ -0,0 +1,55 @@
1
+ /**
2
+ * 驼峰命名与连字符命名法的互换
3
+ *
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/class-name
6
+ * @license MIT
7
+ */
8
+ /**
9
+ *
10
+ * 连字符连接转化为小/大驼峰命名法
11
+ *
12
+ * @param str 待转化文本
13
+ * @param dividingType 连字符,缺省值为 "-"
14
+ * @param initial 是否转换第一个字符。默认值为 false (小驼峰类型)
15
+ * @returns 驼峰命名法字符串(e.g. “helloWorld”)
16
+ *
17
+ */
18
+ function toLowerCamelCase(
19
+ /** 待转化文本 */
20
+ str,
21
+ /** 连字符,缺省值为 "-" */
22
+ dividingType = '-',
23
+ /** 是否转换第一个字符。默认值为 false (小驼峰类型) */
24
+ initial = false) {
25
+ let result = str;
26
+ /**
27
+ * 匹配规则
28
+ *
29
+ * - 匹配到分隔符,将分隔符后面的字符转化为大写
30
+ */
31
+ const template = /[\\]|[\^]|[?]|[-]|[.]|[(]|[)]|[|]|[[]\[\]]|[{]|[}]|[+]|[*]|[$]/;
32
+ /** 转化首字符 */
33
+ const toTransform = (_str, _dividingType) => _str.replace(new RegExp(`${template.test(_dividingType) ? `\\${_dividingType}` : _dividingType}([a-zA-Z])`, 'g'), (match, p1) => p1.toUpperCase());
34
+ // 多分隔符转化
35
+ dividingType.split('').forEach((item) => {
36
+ result = toTransform(result, item);
37
+ });
38
+ return initial
39
+ ? result.replace(/^./, (match) => match.toUpperCase())
40
+ : result;
41
+ }
42
+ /**
43
+ * 驼峰命名法转化为连字符连接
44
+ *
45
+ * @param str 待转化文本
46
+ * @param dividingType 分割符
47
+ * @returns 分割符转化的文本 (e.g. 'hello-world')
48
+ *
49
+ */
50
+ function toSplitCase(str, dividingType = '-') {
51
+ const result = str.replace(/[A-Z]/g, (match) => dividingType.concat(match.toLowerCase()));
52
+ return result.startsWith(dividingType) ? result.substring(1) : result;
53
+ }
54
+
55
+ export { toLowerCamelCase, toSplitCase };
@@ -0,0 +1,73 @@
1
+ import { isNaN, isNumber } from 'a-type-of-js';
2
+
3
+ /**
4
+ * 过去随机数
5
+ *
6
+ * @packageDocumentation
7
+ * @module @a-js-tools/get-random-number
8
+ * @license MIT
9
+ */
10
+ /**
11
+ *
12
+ * 获取一个随机的整数类型
13
+ *
14
+ * 您可以传入两个参数并获取它们之间的任意数字
15
+ *
16
+ * 如果只传递一个参数,则如果提供的值为负数,则得到一个小于(或大于)该数字的整数
17
+ *
18
+ * @param max 较大值 ,不允许为`NaN`
19
+ * @param min 较小值,不允许为 `NaN`
20
+ * @returns 任意的整数
21
+ */
22
+ function getRandomInt(max = 1, min = 0) {
23
+ // 判断是否为 NaN 或 不是数字
24
+ if (!isFinite(max) ||
25
+ !isFinite(min) ||
26
+ isNaN(max) ||
27
+ isNaN(min) ||
28
+ !isNumber(max) ||
29
+ !isNumber(min)) {
30
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
31
+ }
32
+ /** 获取最小值 */
33
+ let _min = Math.ceil(Number(min)),
34
+ /** 获取最大值 */
35
+ _max = Math.floor(Number(max));
36
+ /** 两值交换 */
37
+ if (_min > _max)
38
+ [_max, _min] = [_min, _max];
39
+ //** 两值相等时,直接返回最大值 */
40
+ if (_max === _min)
41
+ return _max;
42
+ return Math.round(Math.random() * (_max - _min) + _min);
43
+ }
44
+ /**
45
+ *
46
+ * 获取任意的浮点数
47
+ *
48
+ * 您可以传入两个参数并获取它们之间的任意数字
49
+ *
50
+ * 如果只传入一个参数,则如果提供的值为负数,则获取小于(或大于)该数字的浮点数
51
+ *
52
+ * @param max 较大数,缺省值为 1
53
+ * @param min 较小值,缺省值为 0
54
+ * @returns 任意的浮点数
55
+ */
56
+ function getRandomFloat(max = 1, min = 0) {
57
+ // 判断是否为 NaN 或 不是数字
58
+ if (!isFinite(max) ||
59
+ !isFinite(min) ||
60
+ isNaN(max) ||
61
+ isNaN(min) ||
62
+ !isNumber(max) ||
63
+ !isNumber(min)) {
64
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
65
+ }
66
+ if (max == min)
67
+ max++;
68
+ if (min > max)
69
+ [max, min] = [min, max];
70
+ return Math.random() * (max - min) + min;
71
+ }
72
+
73
+ export { getRandomFloat, getRandomInt };
@@ -1,10 +1,17 @@
1
- /**************************************
1
+ /**
2
+ * 防抖和节流
3
+ *
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/performance
6
+ * @license MIT
7
+ */
8
+ /**
2
9
  *
3
- * 函数防抖
10
+ * 防抖
4
11
  *
5
- * @param {*} callback
6
- * @param {number} delay 缺省 300 ms
7
- * @return {*} 返回的是一个函数
12
+ * @param callback 回调函数
13
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
14
+ * @returns 返回的闭包函数
8
15
  * @example
9
16
  *
10
17
  * ```ts
@@ -15,8 +22,7 @@
15
22
  * }
16
23
  * }
17
24
  *
18
- **************************************/
19
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
25
+ */
20
26
  function debounce(callback, delay = 200) {
21
27
  if (typeof callback !== 'function') {
22
28
  throw new TypeError('callback must be a function');
@@ -49,12 +55,12 @@ function debounce(callback, delay = 200) {
49
55
  return result;
50
56
  }
51
57
  /**
52
- * 节流函数
53
- * @param callback
54
- * @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
55
- * @returns 返回的是一个函数
58
+ * 节流
59
+ *
60
+ * @param callback 回调函数
61
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
62
+ * @returns 返回的闭包函数
56
63
  */
57
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
58
64
  function throttle(callback, delay = 200) {
59
65
  // 强制转换非数值
60
66
  if (!isFinite(delay) || (isFinite(delay) && delay < 0))
package/package.json CHANGED
@@ -1,33 +1,22 @@
1
1
  {
2
2
  "type": "module",
3
- "version": "0.1.0",
3
+ "version": "0.1.2",
4
4
  "name": "a-js-tools",
5
- "main": "dist/cjs/index.cjs",
6
- "module": "dist/mjs/index.mjs",
7
- "typings": "dist/types/index.d.ts",
5
+ "main": "cjs/index.cjs",
6
+ "module": "mjs/index.mjs",
7
+ "typings": "types/index.d.ts",
8
8
  "description": "Some functions that are available in js",
9
9
  "files": [
10
- "dist/",
10
+ "mjs",
11
+ "cjs",
12
+ "types",
11
13
  "CHANGELOG-en.md",
12
14
  "CHANGELOG.md"
13
15
  ],
14
16
  "exports": {
15
- "import": "./dist/mjs/index.mjs",
16
- "require": "./dist/cjs/index.cjs",
17
- "types": "./dist/types/index.d.ts"
18
- },
19
- "scripts": {
20
- "b": "rollup --config rollup.config.js && tsc -p tsconfig.types.json",
21
- "build": "npx ixxx rm dist && npm run b",
22
- "push:version": "bash -c 'git add . && git commit -m \"version: $1 $(date +\"%Y-%m-%d %H:%M:%S\")${2:+ }$2\" && git tag -a \"v$1\" -m \"$(date +\"%Y-%m-%d %H:%M:%S\")${2:+ }$2\" && git push origin main --tags' -- ",
23
- "push:submit": "bash -c 'git add . && git commit -m \"submit: $(date +\"%Y-%m-%d %H:%M:%S\")${1:+ }$1\" && git push origin main' -- ",
24
- "clean": "npx ixxx up -d r node_modules package-lock.json && npm install && npm run build",
25
- "prettier": "npx prettier . --write",
26
- "test": "npx ixxx clear && npx jest --coverage",
27
- "coverage": "codecov",
28
- "report": "cat ./coverage/lcov.info | coveralls",
29
- "versionPatch": "npx ixxx up -n",
30
- "pub": "npm run build && npm publish --access public"
17
+ "import": "./mjs/index.mjs",
18
+ "require": "./cjs/index.cjs",
19
+ "types": "./types/index.d.ts"
31
20
  },
32
21
  "repository": {
33
22
  "type": "git",
@@ -52,39 +41,6 @@
52
41
  "registry": "https://registry.npmjs.org/"
53
42
  },
54
43
  "dependencies": {
55
- "a-type-of-js": ">=0.1.3 <1.0.0"
56
- },
57
- "devDependencies": {
58
- "@babel/core": "^7.26.9",
59
- "@babel/preset-env": "^7.26.9",
60
- "@babel/preset-typescript": "^7.26.0",
61
- "@eslint/js": "^9.6.0",
62
- "@rollup/plugin-commonjs": "^25.0.8",
63
- "@rollup/plugin-json": "^6.1.0",
64
- "@rollup/plugin-node-resolve": "^15.2.3",
65
- "@rollup/plugin-terser": "^0.4.4",
66
- "@rollup/plugin-typescript": "^11.1.6",
67
- "@types/expect": "^1.20.4",
68
- "@types/jest": "^29.5.14",
69
- "@types/node": "^20.14.9",
70
- "babel-jest": "^29.7.0",
71
- "codecov": "^3.8.2",
72
- "coveralls": "^3.1.1",
73
- "eslint": "^8.57.0",
74
- "eslint-config-prettier": "^9.1.0",
75
- "expect": "^29.7.0",
76
- "globals": "^15.7.0",
77
- "jest": "^29.7.0",
78
- "jest-environment-jsdom": "^29.7.0",
79
- "jest-junit": "^16.0.0",
80
- "prettier": "^3.3.2",
81
- "rollup": "^4.35.0",
82
- "rollup-plugin-cleanup": "^3.2.1",
83
- "rollup-plugin-copy": "^3.5.0",
84
- "ts-jest": "^29.2.6",
85
- "ts-node": "^10.9.2",
86
- "tslib": "^2.6.3",
87
- "typescript": "^5.5.3",
88
- "typescript-eslint": "^7.15.0"
44
+ "a-type-of-js": ">=0.1.6 <1.0.0"
89
45
  }
90
46
  }
@@ -0,0 +1,33 @@
1
+ /**
2
+ * 驼峰命名与连字符命名法的互换
3
+ *
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/class-name
6
+ * @license MIT
7
+ */
8
+ /**
9
+ *
10
+ * 连字符连接转化为小/大驼峰命名法
11
+ *
12
+ * @param str 待转化文本
13
+ * @param dividingType 连字符,缺省值为 "-"
14
+ * @param initial 是否转换第一个字符。默认值为 false (小驼峰类型)
15
+ * @returns 驼峰命名法字符串(e.g. “helloWorld”)
16
+ *
17
+ */
18
+ export declare function toLowerCamelCase(
19
+ /** 待转化文本 */
20
+ str: string,
21
+ /** 连字符,缺省值为 "-" */
22
+ dividingType?: string,
23
+ /** 是否转换第一个字符。默认值为 false (小驼峰类型) */
24
+ initial?: boolean): string;
25
+ /**
26
+ * 驼峰命名法转化为连字符连接
27
+ *
28
+ * @param str 待转化文本
29
+ * @param dividingType 分割符
30
+ * @returns 分割符转化的文本 (e.g. 'hello-world')
31
+ *
32
+ */
33
+ export declare function toSplitCase(str: string, dividingType?: string): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * 获取一个随机的整数类型
4
+ *
5
+ * 您可以传入两个参数并获取它们之间的任意数字
6
+ *
7
+ * 如果只传递一个参数,则如果提供的值为负数,则得到一个小于(或大于)该数字的整数
8
+ *
9
+ * @param max 较大值 ,不允许为`NaN`
10
+ * @param min 较小值,不允许为 `NaN`
11
+ * @returns 任意的整数
12
+ */
13
+ export declare function getRandomInt(max?: number, min?: number): number;
14
+ /**
15
+ *
16
+ * 获取任意的浮点数
17
+ *
18
+ * 您可以传入两个参数并获取它们之间的任意数字
19
+ *
20
+ * 如果只传入一个参数,则如果提供的值为负数,则获取小于(或大于)该数字的浮点数
21
+ *
22
+ * @param max 较大数,缺省值为 1
23
+ * @param min 较小值,缺省值为 0
24
+ * @returns 任意的浮点数
25
+ */
26
+ export declare function getRandomFloat(max?: number, min?: number): number;
@@ -0,0 +1,56 @@
1
+ /**
2
+ *
3
+ * Random string generation function
4
+ *
5
+ *
6
+ *
7
+ */
8
+ export type RandomStringOptions = {
9
+ /**
10
+ * 字符串长度
11
+ *
12
+ * @default 32
13
+ */
14
+ length?: number;
15
+ /**
16
+ * 字符集
17
+ * @default '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
18
+ */
19
+ chars?: string;
20
+ /**
21
+ * 是否包含数字
22
+ *
23
+ * @default false
24
+ */
25
+ includeNumbers?: boolean;
26
+ /**
27
+ * 是否包含大写字母
28
+ *
29
+ * @default false
30
+ */
31
+ includeUppercaseLetters?: boolean;
32
+ /**
33
+ * 是否包含特殊字符
34
+ *
35
+ * @default false
36
+ */
37
+ includeSpecial?: boolean;
38
+ /**
39
+ * 字符类型
40
+ *
41
+ * 缺省值为 'string',可选为 'uuid'
42
+ *
43
+ * @default 'string''
44
+ */
45
+ type?: 'string' | 'uuid';
46
+ };
47
+ /**
48
+ *
49
+ * 获取随机字符串
50
+ *
51
+ * @param length - 字符串长度
52
+ * @returns - 随机字符串
53
+ *
54
+ *
55
+ */
56
+ export declare function getRandomString(length?: RandomStringOptions | number): string;
@@ -0,0 +1,45 @@
1
+ /**
2
+ * 防抖和节流
3
+ *
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/performance
6
+ * @license MIT
7
+ */
8
+ type Callback = (...args: unknown[]) => void;
9
+ /**
10
+ *
11
+ * 节流和防抖返回值类型
12
+ *
13
+ */
14
+ export interface DebounceAndThrottleReturnType<F extends Callback> {
15
+ (...args: Parameters<F>): void;
16
+ cancel(): void;
17
+ }
18
+ /**
19
+ *
20
+ * 防抖
21
+ *
22
+ * @param callback 回调函数
23
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
24
+ * @returns 返回的闭包函数
25
+ * @example
26
+ *
27
+ * ```ts
28
+ * const debounce = (callback: Function, delay = 300) => {
29
+ * let timer: any = null
30
+ * return (...args: any[]) => {
31
+ * clearTimeout(timer)
32
+ * }
33
+ * }
34
+ *
35
+ */
36
+ export declare function debounce<F extends (...args: unknown[]) => void>(callback: F, delay?: number): DebounceAndThrottleReturnType<F>;
37
+ /**
38
+ * 节流
39
+ *
40
+ * @param callback 回调函数
41
+ * @param delay 延迟时间(毫秒),默认 200 (ms)
42
+ * @returns 返回的闭包函数
43
+ */
44
+ export declare function throttle<F extends (...args: unknown[]) => void>(callback: F, delay?: number): DebounceAndThrottleReturnType<F>;
45
+ export {};
package/CHANGELOG-en.md DELETED
@@ -1,24 +0,0 @@
1
- # change log
2
-
3
- [![中文 🇨🇳](<https://img.shields.io/badge/🇨🇳-自述_%20_文件-rgb(255,12,36)>)](https://github.com/earthnutDev/a-js-tools/blob/main/README-zh.md) [![English 🌍](<https://img.shields.io/badge/🌍-README-rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools/blob/main/README.md) [![查看 📔 日志](<https://img.shields.io/badge/👀-日_%20_志-rgb(0,125,206)>)](https://github.com/earthnutDev/a-js-tools/blob/main/CHANGELOG.md) ![查看 📔 日志](<https://img.shields.io/badge/👀-Change_%20_log-rgb(0,125,206)?style=social>)
4
-
5
- ## 0.1.0(3/22/2025)
6
-
7
- - There are no feature updates
8
-
9
- ## 0.0.4(3/21/2025)
10
-
11
- - There are no feature updates
12
- - Updated badge links and how test coverage badges are displayed
13
-
14
- ## 0.0.3(3/16/2025)
15
-
16
- - The previous version's dependency `a-type-of-js` exception was not detected and has been fixed
17
-
18
- ## 0.0.2(3/15/2025)
19
-
20
- - add test coverage percentage badge
21
-
22
- ## 0.0.1(3/7/2025)
23
-
24
- - Refine the test
package/CHANGELOG.md DELETED
@@ -1,47 +0,0 @@
1
- # 更新日志
2
-
3
- [![中文 🇨🇳](<https://img.shields.io/badge/🇨🇳-自述_%20_文件-rgb(255,12,36)>)](https://github.com/earthnutDev/a-js-tools/blob/main/README-zh.md) [![English 🌍](<https://img.shields.io/badge/🌍-README-rgb(0,0,0)>)](https://github.com/earthnutDev/a-js-tools/blob/main/README.md) ![查看 📔 日志](<https://img.shields.io/badge/👀-日_%20_志-rgb(0,125,206)?style=social>) [![查看 📔 日志](<https://img.shields.io/badge/👀-Change_%20_log-rgb(0,125,206)>)](https://github.com/earthnutDev/a-js-tools/blob/main/CHANGELOG-en.md)
4
-
5
- ## 0.1.0 (3 月 22 日 2025 年)
6
-
7
- - 没有更新功能
8
-
9
- ## 0.0.4 (3 月 21 日 2025 年)
10
-
11
- - 没有更新功能
12
- - 更新了徽章的链接和测试覆盖率徽章的展示方式
13
-
14
- ## 0.0.3 (3 月 16 日 2025 年)
15
-
16
- - 上一个版本的依赖 `a-type-of-js` 异常而未察觉,已修复
17
-
18
- ## 0.0.2(3 月 15 日 2025 年)
19
-
20
- - 添加测试率的徽章
21
-
22
- ## 0.0.1(3 月 7 日 2025 年)
23
-
24
- - 优化了 `typeOf` 的逻辑及返回值的类型收缩
25
- - 修改了 `debounce` 函数,在返回的函数的原型上添加 `clear` 方法,以便主动取消未执行的定时器
26
- - 调优了代码结构
27
- - 由于实际需要,移除了 `t`、`isTTY` 的支持,并转移到 [a-node-tools](https://github.com/earthnutDev/a-node-tools)
28
-
29
- ## 0.0.0 (6 月 11 日 2024 年)
30
-
31
- - 最爱干的事,就是改名字,哈哈哈哈哈
32
-
33
- ## 0.0.2-5 (6 月 11 日 2024 年)
34
-
35
- - 添加了 `eslint`
36
-
37
- ## 0.0.1 (6 月 11 日 2024 年)
38
-
39
- - 维护了导出
40
-
41
- ## 0.0.0 (6 月 4 日 2024 年)
42
-
43
- - 项目做了迁移
44
-
45
- ## 0.0.1 (4 月 28 日 2024 年)
46
-
47
- - 初始化这个项目
@@ -1,58 +0,0 @@
1
- 'use strict';
2
-
3
- /****************************************************************************
4
- * @Author earthnut
5
- * @Email earthnut.dev@outlook.com
6
- * @ProjectName a-js-tools
7
- * @FileName className.ts
8
- * @CreateDate 周六 09/14/2024
9
- * @Description css 类名转换
10
- ****************************************************************************/
11
- /**************************************
12
- *
13
- * 转化为驼峰命名法
14
- *
15
- * @param str 待转化的字符串
16
- * @param [dividingType='-'] 分隔符。缺省为 "-"
17
- * @param [initial=false] 是否转化首字符。缺省为false(小驼峰式)
18
- * @returns {string} 转化后的字符串
19
- *
20
- **************************************/
21
- function toLowerCamelCase(
22
- /** 待转化的字符串 */
23
- str,
24
- /** 分隔符。缺省为 "-" */
25
- dividingType = '-',
26
- /** 是否转化首字符。缺省为false(小驼峰式) */
27
- initial = false) {
28
- let result = str;
29
- /**************************
30
- * 匹配规则
31
- *
32
- * - 匹配到分隔符,将分隔符后面的字符转化为大写
33
- **************************/
34
- const template = /[\\]|[\^]|[?]|[-]|[.]|[(]|[)]|[|]|[[]\[\]]|[{]|[}]|[+]|[*]|[$]/;
35
- /** 转化首字符 */
36
- const toTransform = (_str, _dividingType) => _str.replace(new RegExp(`${template.test(_dividingType) ? `\\${_dividingType}` : _dividingType}([a-zA-Z])`, 'g'), (match, p1) => p1.toUpperCase());
37
- // 多分隔符转化
38
- dividingType.split('').forEach((item) => {
39
- result = toTransform(result, item);
40
- });
41
- return initial
42
- ? result.replace(/^./, (match) => match.toUpperCase())
43
- : result;
44
- }
45
- /**************************************
46
- *
47
- * @param str 转化的字符串
48
- * @param [dividingType='-'] 转化后单词间的连字符
49
- *
50
- *
51
- **************************************/
52
- function toSplitCase(str, dividingType = '-') {
53
- const result = str.replace(/[A-Z]/g, (match) => dividingType.concat(match.toLowerCase()));
54
- return result.startsWith(dividingType) ? result.substring(1) : result;
55
- }
56
-
57
- exports.toLowerCamelCase = toLowerCamelCase;
58
- exports.toSplitCase = toSplitCase;
@@ -1,55 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
-
5
- /**
6
- *
7
- * 获取一个随机整数
8
- *
9
- * 可传入两个参数,获取两参数之间的任意数
10
- *
11
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
12
- *
13
- * @export
14
- * @param {number} max 最大值,不可为 `NaN`
15
- * @param {number} [min] 最小值,不可取值 `NaN`
16
- * @return {*} {number}
17
- */
18
- function getRandomInt(max = 1, min = 0) {
19
- // 判断是否为 NaN 或 不是数字
20
- if (aTypeOfJs.isNaN(max) || aTypeOfJs.isNaN(min) || !aTypeOfJs.isNumber(max) || !aTypeOfJs.isNumber(min)) {
21
- throw new TypeError('getRandomInt: max or min is NaN or is not a number');
22
- }
23
- /** 获取最小值 */
24
- let _min = Math.ceil(Number(min)),
25
- /** 获取最大值 */
26
- _max = Math.floor(Number(max));
27
- /** 两值交换 */
28
- _min > _max && ([_max, _min] = [_min, _max]);
29
- //** 两值相等时,直接返回最大值 */
30
- if (_max === _min)
31
- return _max;
32
- return Math.round(Math.random() * (_max - _min) + _min);
33
- }
34
- /**
35
- *
36
- * 获取一个随机浮点数数
37
- *
38
- * 可传入两个参数,获取两参数之间的任意数
39
- *
40
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
41
- *
42
- * @export
43
- * @param {number} max 最大值,缺省 1
44
- * @param {number} [min] 最小值,缺省 0
45
- * @return {*} {number}
46
- */
47
- function getRandomFloat(max = 1, min = 0) {
48
- if (max == min)
49
- max++;
50
- min > max && ([max, min] = [min, max]);
51
- return Math.random() * (max - min) + min;
52
- }
53
-
54
- exports.getRandomFloat = getRandomFloat;
55
- exports.getRandomInt = getRandomInt;
@@ -1,55 +0,0 @@
1
- /****************************************************************************
2
- * @Author earthnut
3
- * @Email earthnut.dev@outlook.com
4
- * @ProjectName a-js-tools
5
- * @FileName className.ts
6
- * @CreateDate 周六 09/14/2024
7
- * @Description css 类名转换
8
- ****************************************************************************/
9
- /**************************************
10
- *
11
- * 转化为驼峰命名法
12
- *
13
- * @param str 待转化的字符串
14
- * @param [dividingType='-'] 分隔符。缺省为 "-"
15
- * @param [initial=false] 是否转化首字符。缺省为false(小驼峰式)
16
- * @returns {string} 转化后的字符串
17
- *
18
- **************************************/
19
- function toLowerCamelCase(
20
- /** 待转化的字符串 */
21
- str,
22
- /** 分隔符。缺省为 "-" */
23
- dividingType = '-',
24
- /** 是否转化首字符。缺省为false(小驼峰式) */
25
- initial = false) {
26
- let result = str;
27
- /**************************
28
- * 匹配规则
29
- *
30
- * - 匹配到分隔符,将分隔符后面的字符转化为大写
31
- **************************/
32
- const template = /[\\]|[\^]|[?]|[-]|[.]|[(]|[)]|[|]|[[]\[\]]|[{]|[}]|[+]|[*]|[$]/;
33
- /** 转化首字符 */
34
- const toTransform = (_str, _dividingType) => _str.replace(new RegExp(`${template.test(_dividingType) ? `\\${_dividingType}` : _dividingType}([a-zA-Z])`, 'g'), (match, p1) => p1.toUpperCase());
35
- // 多分隔符转化
36
- dividingType.split('').forEach((item) => {
37
- result = toTransform(result, item);
38
- });
39
- return initial
40
- ? result.replace(/^./, (match) => match.toUpperCase())
41
- : result;
42
- }
43
- /**************************************
44
- *
45
- * @param str 转化的字符串
46
- * @param [dividingType='-'] 转化后单词间的连字符
47
- *
48
- *
49
- **************************************/
50
- function toSplitCase(str, dividingType = '-') {
51
- const result = str.replace(/[A-Z]/g, (match) => dividingType.concat(match.toLowerCase()));
52
- return result.startsWith(dividingType) ? result.substring(1) : result;
53
- }
54
-
55
- export { toLowerCamelCase, toSplitCase };
@@ -1,52 +0,0 @@
1
- import { isNaN, isNumber } from 'a-type-of-js';
2
-
3
- /**
4
- *
5
- * 获取一个随机整数
6
- *
7
- * 可传入两个参数,获取两参数之间的任意数
8
- *
9
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
10
- *
11
- * @export
12
- * @param {number} max 最大值,不可为 `NaN`
13
- * @param {number} [min] 最小值,不可取值 `NaN`
14
- * @return {*} {number}
15
- */
16
- function getRandomInt(max = 1, min = 0) {
17
- // 判断是否为 NaN 或 不是数字
18
- if (isNaN(max) || isNaN(min) || !isNumber(max) || !isNumber(min)) {
19
- throw new TypeError('getRandomInt: max or min is NaN or is not a number');
20
- }
21
- /** 获取最小值 */
22
- let _min = Math.ceil(Number(min)),
23
- /** 获取最大值 */
24
- _max = Math.floor(Number(max));
25
- /** 两值交换 */
26
- _min > _max && ([_max, _min] = [_min, _max]);
27
- //** 两值相等时,直接返回最大值 */
28
- if (_max === _min)
29
- return _max;
30
- return Math.round(Math.random() * (_max - _min) + _min);
31
- }
32
- /**
33
- *
34
- * 获取一个随机浮点数数
35
- *
36
- * 可传入两个参数,获取两参数之间的任意数
37
- *
38
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
39
- *
40
- * @export
41
- * @param {number} max 最大值,缺省 1
42
- * @param {number} [min] 最小值,缺省 0
43
- * @return {*} {number}
44
- */
45
- function getRandomFloat(max = 1, min = 0) {
46
- if (max == min)
47
- max++;
48
- min > max && ([max, min] = [min, max]);
49
- return Math.random() * (max - min) + min;
50
- }
51
-
52
- export { getRandomFloat, getRandomInt };
@@ -1,33 +0,0 @@
1
- /****************************************************************************
2
- * @Author earthnut
3
- * @Email earthnut.dev@outlook.com
4
- * @ProjectName a-js-tools
5
- * @FileName className.ts
6
- * @CreateDate 周六 09/14/2024
7
- * @Description css 类名转换
8
- ****************************************************************************/
9
- /**************************************
10
- *
11
- * 转化为驼峰命名法
12
- *
13
- * @param str 待转化的字符串
14
- * @param [dividingType='-'] 分隔符。缺省为 "-"
15
- * @param [initial=false] 是否转化首字符。缺省为false(小驼峰式)
16
- * @returns {string} 转化后的字符串
17
- *
18
- **************************************/
19
- export declare function toLowerCamelCase(
20
- /** 待转化的字符串 */
21
- str: string,
22
- /** 分隔符。缺省为 "-" */
23
- dividingType?: string,
24
- /** 是否转化首字符。缺省为false(小驼峰式) */
25
- initial?: boolean): string;
26
- /**************************************
27
- *
28
- * @param str 转化的字符串
29
- * @param [dividingType='-'] 转化后单词间的连字符
30
- *
31
- *
32
- **************************************/
33
- export declare function toSplitCase(str: string, dividingType?: string): string;
@@ -1,28 +0,0 @@
1
- /**
2
- *
3
- * 获取一个随机整数
4
- *
5
- * 可传入两个参数,获取两参数之间的任意数
6
- *
7
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的整数
8
- *
9
- * @export
10
- * @param {number} max 最大值,不可为 `NaN`
11
- * @param {number} [min] 最小值,不可取值 `NaN`
12
- * @return {*} {number}
13
- */
14
- export declare function getRandomInt(max?: number, min?: number): number;
15
- /**
16
- *
17
- * 获取一个随机浮点数数
18
- *
19
- * 可传入两个参数,获取两参数之间的任意数
20
- *
21
- * 若只传入一个参数,这获取小于(若提供的值为负数,则为大于)该数的浮点数数
22
- *
23
- * @export
24
- * @param {number} max 最大值,缺省 1
25
- * @param {number} [min] 最小值,缺省 0
26
- * @return {*} {number}
27
- */
28
- export declare function getRandomFloat(max?: number, min?: number): number;
@@ -1,48 +0,0 @@
1
- /**************************************
2
- *
3
- * 随机字符串生成函数
4
- *
5
- *
6
- *
7
- **************************************/
8
- export type RandomStringOptions = {
9
- /**************************
10
- * 字符串长度
11
- * @default 32
12
- **************************/
13
- length?: number;
14
- /**************************
15
- * 字符串可选字符
16
- * @default '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
17
- **************************/
18
- chars?: string;
19
- /**************************
20
- * 是否包含数字
21
- * @default false
22
- **************************/
23
- includeNumbers?: boolean;
24
- /**************************
25
- * 是否包含大写字母
26
- * @default false
27
- **************************/
28
- includeUppercaseLetters?: boolean;
29
- /**************************
30
- * 是否包含特殊字符
31
- * @default false
32
- **************************/
33
- includeSpecial?: boolean;
34
- /**************************
35
- * 字符串类型
36
- * @default 'string''
37
- **************************/
38
- type?: 'string' | 'uuid';
39
- };
40
- /**************************************
41
- *
42
- * 随机字符串生成函数
43
- * @param {number} length - 字符串长度
44
- * @returns {string} - 生成的随机字符串
45
- *
46
- *
47
- **************************************/
48
- export declare function getRandomString(length?: RandomStringOptions | number): string;
@@ -1,40 +0,0 @@
1
- type Callback = (...args: unknown[]) => void;
2
- /**************************
3
- * DebounceAndThrottleReturnType
4
- *
5
- *
6
- *
7
- * @description: 函数防抖和函数节流的返回类型
8
- *
9
- **************************/
10
- export interface DebounceAndThrottleReturnType<F extends Callback> {
11
- (...args: Parameters<F>): void;
12
- cancel(): void;
13
- }
14
- /**************************************
15
- *
16
- * 函数防抖
17
- *
18
- * @param {*} callback
19
- * @param {number} delay 缺省 300 ms
20
- * @return {*} 返回的是一个函数
21
- * @example
22
- *
23
- * ```ts
24
- * const debounce = (callback: Function, delay = 300) => {
25
- * let timer: any = null
26
- * return (...args: any[]) => {
27
- * clearTimeout(timer)
28
- * }
29
- * }
30
- *
31
- **************************************/
32
- export declare function debounce<F extends (...args: any[]) => void>(callback: F, delay?: number): DebounceAndThrottleReturnType<F>;
33
- /**
34
- * 节流函数
35
- * @param callback
36
- * @param delay 延迟时间,单位为毫秒(ms),缺省 200(ms)
37
- * @returns 返回的是一个函数
38
- */
39
- export declare function throttle<F extends (...args: any[]) => void>(callback: F, delay?: number): DebounceAndThrottleReturnType<F>;
40
- export {};
File without changes
File without changes
File without changes
File without changes