a-js-tools 0.1.0 → 0.1.1

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-en.md CHANGED
@@ -2,6 +2,10 @@
2
2
 
3
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
4
 
5
+ ## 0.1.1(3/23/2025)
6
+
7
+ - There are no feature updates
8
+
5
9
  ## 0.1.0(3/22/2025)
6
10
 
7
11
  - There are no feature updates
@@ -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
+ * Translates into hump nomenclature
13
+ *
14
+ * @param str The string to be converted
15
+ * @param dividingType Separator. Defaults to "-"
16
+ * @param initial Whether or not to convert the first character. Default is false (small hump type)
17
+ * @returns hump nomenclature string (e.g. "helloWorld")
18
+ *
19
+ */
20
+ function toLowerCamelCase(
21
+ /** The string to be converted */
22
+ str,
23
+ /** Separator. Defaults to "-" */
24
+ dividingType = '-',
25
+ /** Whether or not to convert the first character. Default is false (small hump type) */
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
+ * Convert to hyphenated joins
46
+ *
47
+ * @param str The converted string
48
+ * @param dividingType Hyphens between converted words
49
+ * @returns a hyphenated string (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,62 @@
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
+ * Get a random integer
15
+ *
16
+ * You can pass in two parameters and get any number between them
17
+ *
18
+ * If only one parameter is passed, this gets an integer that is less than (or greater than) that number if the value provided is negative
19
+ *
20
+ * @param max Maximum, not allowed `NaN`
21
+ * @param min Minimum, non-desirable value `NaN`
22
+ * @returns a random integer number
23
+ */
24
+ function getRandomInt(max = 1, min = 0) {
25
+ // 判断是否为 NaN 或 不是数字
26
+ if (aTypeOfJs.isNaN(max) || aTypeOfJs.isNaN(min) || !aTypeOfJs.isNumber(max) || !aTypeOfJs.isNumber(min)) {
27
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
28
+ }
29
+ /** 获取最小值 */
30
+ let _min = Math.ceil(Number(min)),
31
+ /** 获取最大值 */
32
+ _max = Math.floor(Number(max));
33
+ /** 两值交换 */
34
+ if (_min > _max)
35
+ [_max, _min] = [_min, _max];
36
+ //** 两值相等时,直接返回最大值 */
37
+ if (_max === _min)
38
+ return _max;
39
+ return Math.round(Math.random() * (_max - _min) + _min);
40
+ }
41
+ /**
42
+ *
43
+ * Gets a random floating-point number
44
+ *
45
+ * You can pass in two parameters and get any number between them
46
+ *
47
+ * If you pass in only one parameter, this gets the number of floating-point numbers that are less than (or greater than) that number if the value provided is negative
48
+ *
49
+ * @param max Maximum, default 1
50
+ * @param min Minimum, default 0
51
+ * @returns a random floating-point number
52
+ */
53
+ function getRandomFloat(max = 1, min = 0) {
54
+ if (max == min)
55
+ max++;
56
+ if (min > max)
57
+ [max, min] = [min, max];
58
+ return Math.random() * (max - min) + min;
59
+ }
60
+
61
+ exports.getRandomFloat = getRandomFloat;
62
+ exports.getRandomInt = getRandomInt;
@@ -1,12 +1,19 @@
1
1
  'use strict';
2
2
 
3
- /**************************************
3
+ /**
4
+ *
4
5
  *
5
- * 函数防抖
6
+ * @packageDocumentation
7
+ * @module @a-js-tools/performance
8
+ * @license MIT
9
+ */
10
+ /**
6
11
  *
7
- * @param {*} callback
8
- * @param {number} delay 缺省 300 ms
9
- * @return {*} 返回的是一个函数
12
+ * debounce function
13
+ *
14
+ * @param callback
15
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
16
+ * @returns return a function
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
+ * throttle
61
+ *
62
+ * @param callback Callback function
63
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
64
+ * @returns return a function
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
+ * Translates into hump nomenclature
11
+ *
12
+ * @param str The string to be converted
13
+ * @param dividingType Separator. Defaults to "-"
14
+ * @param initial Whether or not to convert the first character. Default is false (small hump type)
15
+ * @returns hump nomenclature string (e.g. "helloWorld")
16
+ *
17
+ */
18
+ function toLowerCamelCase(
19
+ /** The string to be converted */
20
+ str,
21
+ /** Separator. Defaults to "-" */
22
+ dividingType = '-',
23
+ /** Whether or not to convert the first character. Default is false (small hump type) */
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
+ * Convert to hyphenated joins
44
+ *
45
+ * @param str The converted string
46
+ * @param dividingType Hyphens between converted words
47
+ * @returns a hyphenated string (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,59 @@
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
+ * Get a random integer
13
+ *
14
+ * You can pass in two parameters and get any number between them
15
+ *
16
+ * If only one parameter is passed, this gets an integer that is less than (or greater than) that number if the value provided is negative
17
+ *
18
+ * @param max Maximum, not allowed `NaN`
19
+ * @param min Minimum, non-desirable value `NaN`
20
+ * @returns a random integer number
21
+ */
22
+ function getRandomInt(max = 1, min = 0) {
23
+ // 判断是否为 NaN 或 不是数字
24
+ if (isNaN(max) || isNaN(min) || !isNumber(max) || !isNumber(min)) {
25
+ throw new TypeError('getRandomInt: max or min is NaN or is not a number');
26
+ }
27
+ /** 获取最小值 */
28
+ let _min = Math.ceil(Number(min)),
29
+ /** 获取最大值 */
30
+ _max = Math.floor(Number(max));
31
+ /** 两值交换 */
32
+ if (_min > _max)
33
+ [_max, _min] = [_min, _max];
34
+ //** 两值相等时,直接返回最大值 */
35
+ if (_max === _min)
36
+ return _max;
37
+ return Math.round(Math.random() * (_max - _min) + _min);
38
+ }
39
+ /**
40
+ *
41
+ * Gets a random floating-point number
42
+ *
43
+ * You can pass in two parameters and get any number between them
44
+ *
45
+ * If you pass in only one parameter, this gets the number of floating-point numbers that are less than (or greater than) that number if the value provided is negative
46
+ *
47
+ * @param max Maximum, default 1
48
+ * @param min Minimum, default 0
49
+ * @returns a random floating-point number
50
+ */
51
+ function getRandomFloat(max = 1, min = 0) {
52
+ if (max == min)
53
+ max++;
54
+ if (min > max)
55
+ [max, min] = [min, max];
56
+ return Math.random() * (max - min) + min;
57
+ }
58
+
59
+ export { getRandomFloat, getRandomInt };
@@ -1,10 +1,17 @@
1
- /**************************************
1
+ /**
2
+ *
2
3
  *
3
- * 函数防抖
4
+ * @packageDocumentation
5
+ * @module @a-js-tools/performance
6
+ * @license MIT
7
+ */
8
+ /**
4
9
  *
5
- * @param {*} callback
6
- * @param {number} delay 缺省 300 ms
7
- * @return {*} 返回的是一个函数
10
+ * debounce function
11
+ *
12
+ * @param callback
13
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
14
+ * @returns return a function
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
+ * throttle
59
+ *
60
+ * @param callback Callback function
61
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
62
+ * @returns return a function
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.1",
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.5 <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
+ * Translates into hump nomenclature
11
+ *
12
+ * @param str The string to be converted
13
+ * @param dividingType Separator. Defaults to "-"
14
+ * @param initial Whether or not to convert the first character. Default is false (small hump type)
15
+ * @returns hump nomenclature string (e.g. "helloWorld")
16
+ *
17
+ */
18
+ export declare function toLowerCamelCase(
19
+ /** The string to be converted */
20
+ str: string,
21
+ /** Separator. Defaults to "-" */
22
+ dividingType?: string,
23
+ /** Whether or not to convert the first character. Default is false (small hump type) */
24
+ initial?: boolean): string;
25
+ /**
26
+ * Convert to hyphenated joins
27
+ *
28
+ * @param str The converted string
29
+ * @param dividingType Hyphens between converted words
30
+ * @returns a hyphenated string (e.g. 'hello-world')
31
+ *
32
+ */
33
+ export declare function toSplitCase(str: string, dividingType?: string): string;
@@ -0,0 +1,26 @@
1
+ /**
2
+ *
3
+ * Get a random integer
4
+ *
5
+ * You can pass in two parameters and get any number between them
6
+ *
7
+ * If only one parameter is passed, this gets an integer that is less than (or greater than) that number if the value provided is negative
8
+ *
9
+ * @param max Maximum, not allowed `NaN`
10
+ * @param min Minimum, non-desirable value `NaN`
11
+ * @returns a random integer number
12
+ */
13
+ export declare function getRandomInt(max?: number, min?: number): number;
14
+ /**
15
+ *
16
+ * Gets a random floating-point number
17
+ *
18
+ * You can pass in two parameters and get any number between them
19
+ *
20
+ * If you pass in only one parameter, this gets the number of floating-point numbers that are less than (or greater than) that number if the value provided is negative
21
+ *
22
+ * @param max Maximum, default 1
23
+ * @param min Minimum, default 0
24
+ * @returns a random floating-point number
25
+ */
26
+ export declare function getRandomFloat(max?: number, min?: number): number;
@@ -0,0 +1,49 @@
1
+ /**
2
+ *
3
+ * Random string generation function
4
+ *
5
+ *
6
+ *
7
+ */
8
+ export type RandomStringOptions = {
9
+ /**
10
+ * string length
11
+ * @default 32
12
+ */
13
+ length?: number;
14
+ /**
15
+ * String optional characters
16
+ * @default '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'
17
+ */
18
+ chars?: string;
19
+ /**
20
+ * Whether or not to include numbers
21
+ * @default false
22
+ */
23
+ includeNumbers?: boolean;
24
+ /**
25
+ * Whether or not to include capital letters
26
+ * @default false
27
+ */
28
+ includeUppercaseLetters?: boolean;
29
+ /**
30
+ * Whether or not it contains special characters
31
+ * @default false
32
+ */
33
+ includeSpecial?: boolean;
34
+ /**
35
+ * String type
36
+ * @default 'string''
37
+ */
38
+ type?: 'string' | 'uuid';
39
+ };
40
+ /**
41
+ *
42
+ * Random string generation
43
+ *
44
+ * @param length - string length
45
+ * @returns - A random string of characters generated
46
+ *
47
+ *
48
+ */
49
+ 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
+ * debounce or throttle function return value type
12
+ *
13
+ */
14
+ export interface DebounceAndThrottleReturnType<F extends Callback> {
15
+ (...args: Parameters<F>): void;
16
+ cancel(): void;
17
+ }
18
+ /**
19
+ *
20
+ * debounce function
21
+ *
22
+ * @param callback
23
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
24
+ * @returns return a function
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
+ * throttle
39
+ *
40
+ * @param callback Callback function
41
+ * @param delay Delay time in milliseconds (ms), default 200 (ms)
42
+ * @returns return a function
43
+ */
44
+ export declare function throttle<F extends (...args: unknown[]) => void>(callback: F, delay?: number): DebounceAndThrottleReturnType<F>;
45
+ export {};
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