a-js-tools 1.0.13-beta.0 → 1.0.13-beta.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.
@@ -1,59 +0,0 @@
1
- import { isEmptyArray, isArray } from 'a-type-of-js';
2
-
3
- /**
4
- *
5
- * 数组的并集
6
- *
7
- * <span style="color:#f36;">请注意,参数有不为数组时直接抛出 TypeError</span>
8
- * @param arrays - 多个数组
9
- * @returns 联合后的数组
10
- *
11
- *
12
- * @example
13
- *
14
- * ```ts
15
- * import { union } from 'a-js-tools';
16
- *
17
- * const log = console.log;
18
- *
19
- * // []
20
- * log(union());
21
- *
22
- * // [1, 2, 3]
23
- * log(union([1, 2, 3]));
24
- *
25
- * // TypeError
26
- * log(union([1, 2, 3], 'i'));
27
- * log(union([1, 2, 3], undefined));
28
- * log(union([1, 2, 3], null));
29
- * log(union([1, 2, 3], 4));
30
- * log(union([1, 2, 3], {}));
31
- * log(union([1, 2, 3], false));
32
- *
33
- * // [1, 2, 3, 4, 6]
34
- * log(union([1, 2, 3], [2, 4, 6]));
35
- *
36
- * // [1, 2, 3, 4, 6]
37
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3]));
38
- *
39
- * // [1, 2, 3, 4, 6]
40
- * log(union([1, 2, 3], [2, 4, 6], [1, 2, 3], [1, 2, 3]));
41
- * ```
42
- *
43
- */
44
- function union(...arrays) {
45
- if (isEmptyArray(arrays))
46
- return [];
47
- if (arrays.some(i => !isArray(i)))
48
- throw new TypeError('参数必须都是数组形式的元素');
49
- if (arrays.length === 1)
50
- return [...arrays[0]];
51
- const resultSet = new Set();
52
- for (const array of arrays) {
53
- for (const item of array)
54
- resultSet.add(item);
55
- }
56
- return Array.from(resultSet);
57
- }
58
-
59
- export { union };
@@ -1,58 +0,0 @@
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
38
- .split('')
39
- .forEach((item) => (result = toTransform(result, item)));
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;
@@ -1,55 +0,0 @@
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
36
- .split('')
37
- .forEach((item) => (result = toTransform(result, item)));
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 };
@@ -1,76 +0,0 @@
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
- * 您可以传入两个参数并获取它们之间的任意数字,返回值<span style="color:#ff0;">*会包含端值*</span>
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 (_max === _min)
40
- return _max;
41
- // 两值交换
42
- if (_min > _max)
43
- [_max, _min] = [_min, _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,73 +0,0 @@
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
- * 您可以传入两个参数并获取它们之间的任意数字,返回值<span style="color:#ff0;">*会包含端值*</span>
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 (_max === _min)
38
- return _max;
39
- // 两值交换
40
- if (_min > _max)
41
- [_max, _min] = [_min, _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,107 +0,0 @@
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-string
10
- * @license MIT
11
- */
12
- /**
13
- *
14
- * 获取简单的随机字符串
15
- *
16
- * @param options - 字符串长度
17
- * @returns - 随机字符串
18
- *
19
- *
20
- */
21
- function getRandomString(options) {
22
- // 验证输入参数
23
- if (
24
- // 参数类型错误
25
- (!aTypeOfJs.isPlainObject(options) && !aTypeOfJs.isNumber(options)) ||
26
- // 参数为 NaN
27
- (aTypeOfJs.isNumber(options) && aTypeOfJs.isNaN(options)) ||
28
- // 参数为数字时为无穷大
29
- (aTypeOfJs.isNumber(options) && !isFinite(options)) ||
30
- // 参数为数字时为非整数
31
- (aTypeOfJs.isNumber(options) && !Number.isInteger(options)) ||
32
- // 参数为数字时为负数
33
- (aTypeOfJs.isNumber(options) && Number.isInteger(options) && options < 1) ||
34
- // 参数为数值然而却小于 1
35
- (aTypeOfJs.isNumber(options) && options < 1) ||
36
- // 参数为对象但是 length 属性非数值
37
- (aTypeOfJs.isPlainObject(options) &&
38
- (!aTypeOfJs.isNumber(options.length) ||
39
- options.length < 1 ||
40
- !Number.isInteger(options.length))))
41
- throw new TypeError('参数类型错误 ❌ (getRandomString)');
42
- const initOptions = {
43
- length: 32,
44
- chars: 'abcdefghijklmnopqrstuvwxyz',
45
- chars2: '0123456789',
46
- chars3: '!@#$%^&*()_+~`|}{[]:;?><,./-=',
47
- type: 'string',
48
- includeUppercaseLetters: false,
49
- includeNumbers: false,
50
- includeSpecial: false,
51
- };
52
- /// 生成 UUID
53
- if (initOptions.type === 'uuid')
54
- return crypto.randomUUID();
55
- // 验证输入参数
56
- if (aTypeOfJs.isNumber(options) && Number.isInteger(options) && options > 0)
57
- Object.assign(initOptions, { length: options });
58
- if (aTypeOfJs.isPlainObject(options)) {
59
- Object.assign(initOptions, options);
60
- initOptions.length = initOptions.length < 1 ? 32 : initOptions.length;
61
- }
62
- /** 生成随机字符串 */
63
- const templateCharsArr = initOptions.chars.split('');
64
- // 添加大写字母
65
- if (initOptions.includeUppercaseLetters)
66
- interleaveString(templateCharsArr, initOptions.chars.toUpperCase());
67
- // 添加数字
68
- if (initOptions.includeNumbers)
69
- interleaveString(templateCharsArr, initOptions.chars2);
70
- // 添加特殊字符
71
- if (initOptions.includeSpecial)
72
- interleaveString(templateCharsArr, initOptions.chars3);
73
- // 使用密码学安全的随机数生成器
74
- const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
75
- let result = '';
76
- /** 获取最后的 chars 数据 */
77
- const chars = templateCharsArr.join('');
78
- // 循环遍历
79
- bytes.forEach(byte => (result += chars.charAt(byte % chars.length)));
80
- /**
81
- *
82
- * 字符串交叉函数
83
- *
84
- * 非线形串交叉,对相交叉
85
- *
86
- * @param str1 - 字符串1
87
- * @param str2 - 字符串2
88
- * @returns - 交叉后的字符串
89
- * @example
90
- * ```ts
91
- * interleaveString('abc', '123') // 'a1b2c3'
92
- * ```
93
- */
94
- function interleaveString(str1, str2) {
95
- const str1Length = str1.length, str2Length = str2.length;
96
- const maxLength = Math.max(str1Length, str2Length);
97
- for (let i = 0; i < maxLength; i++) {
98
- if (i < str1Length && !aTypeOfJs.isUndefined(str2[i]))
99
- str1[i] += str2[i];
100
- else if (i < str2Length)
101
- str1[i] = str2[i];
102
- }
103
- }
104
- return result;
105
- }
106
-
107
- exports.getRandomString = getRandomString;
@@ -1,105 +0,0 @@
1
- import { isPlainObject, isNumber, isNaN, isUndefined } from 'a-type-of-js';
2
-
3
- /**
4
- * 获取随机字符串
5
- *
6
- * @packageDocumentation
7
- * @module @a-js-tools/get-random-string
8
- * @license MIT
9
- */
10
- /**
11
- *
12
- * 获取简单的随机字符串
13
- *
14
- * @param options - 字符串长度
15
- * @returns - 随机字符串
16
- *
17
- *
18
- */
19
- function getRandomString(options) {
20
- // 验证输入参数
21
- if (
22
- // 参数类型错误
23
- (!isPlainObject(options) && !isNumber(options)) ||
24
- // 参数为 NaN
25
- (isNumber(options) && isNaN(options)) ||
26
- // 参数为数字时为无穷大
27
- (isNumber(options) && !isFinite(options)) ||
28
- // 参数为数字时为非整数
29
- (isNumber(options) && !Number.isInteger(options)) ||
30
- // 参数为数字时为负数
31
- (isNumber(options) && Number.isInteger(options) && options < 1) ||
32
- // 参数为数值然而却小于 1
33
- (isNumber(options) && options < 1) ||
34
- // 参数为对象但是 length 属性非数值
35
- (isPlainObject(options) &&
36
- (!isNumber(options.length) ||
37
- options.length < 1 ||
38
- !Number.isInteger(options.length))))
39
- throw new TypeError('参数类型错误 ❌ (getRandomString)');
40
- const initOptions = {
41
- length: 32,
42
- chars: 'abcdefghijklmnopqrstuvwxyz',
43
- chars2: '0123456789',
44
- chars3: '!@#$%^&*()_+~`|}{[]:;?><,./-=',
45
- type: 'string',
46
- includeUppercaseLetters: false,
47
- includeNumbers: false,
48
- includeSpecial: false,
49
- };
50
- /// 生成 UUID
51
- if (initOptions.type === 'uuid')
52
- return crypto.randomUUID();
53
- // 验证输入参数
54
- if (isNumber(options) && Number.isInteger(options) && options > 0)
55
- Object.assign(initOptions, { length: options });
56
- if (isPlainObject(options)) {
57
- Object.assign(initOptions, options);
58
- initOptions.length = initOptions.length < 1 ? 32 : initOptions.length;
59
- }
60
- /** 生成随机字符串 */
61
- const templateCharsArr = initOptions.chars.split('');
62
- // 添加大写字母
63
- if (initOptions.includeUppercaseLetters)
64
- interleaveString(templateCharsArr, initOptions.chars.toUpperCase());
65
- // 添加数字
66
- if (initOptions.includeNumbers)
67
- interleaveString(templateCharsArr, initOptions.chars2);
68
- // 添加特殊字符
69
- if (initOptions.includeSpecial)
70
- interleaveString(templateCharsArr, initOptions.chars3);
71
- // 使用密码学安全的随机数生成器
72
- const bytes = globalThis.crypto.getRandomValues(new Uint8Array(initOptions.length));
73
- let result = '';
74
- /** 获取最后的 chars 数据 */
75
- const chars = templateCharsArr.join('');
76
- // 循环遍历
77
- bytes.forEach(byte => (result += chars.charAt(byte % chars.length)));
78
- /**
79
- *
80
- * 字符串交叉函数
81
- *
82
- * 非线形串交叉,对相交叉
83
- *
84
- * @param str1 - 字符串1
85
- * @param str2 - 字符串2
86
- * @returns - 交叉后的字符串
87
- * @example
88
- * ```ts
89
- * interleaveString('abc', '123') // 'a1b2c3'
90
- * ```
91
- */
92
- function interleaveString(str1, str2) {
93
- const str1Length = str1.length, str2Length = str2.length;
94
- const maxLength = Math.max(str1Length, str2Length);
95
- for (let i = 0; i < maxLength; i++) {
96
- if (i < str1Length && !isUndefined(str2[i]))
97
- str1[i] += str2[i];
98
- else if (i < str2Length)
99
- str1[i] = str2[i];
100
- }
101
- }
102
- return result;
103
- }
104
-
105
- export { getRandomString };
package/src/isNode.cjs.js DELETED
@@ -1,23 +0,0 @@
1
- 'use strict';
2
-
3
- var aTypeOfJs = require('a-type-of-js');
4
-
5
- /**
6
- *
7
- * 判断当前环境是否为 node 环境
8
- *
9
- */
10
- function isNode() {
11
- return !aTypeOfJs.isUndefined(globalThis?.process?.versions?.node);
12
- }
13
- /**
14
- *
15
- * 是否为浏览器环境
16
- *
17
- */
18
- function isBrowser() {
19
- return !isNode();
20
- }
21
-
22
- exports.isBrowser = isBrowser;
23
- exports.isNode = isNode;
package/src/isNode.mjs.js DELETED
@@ -1,20 +0,0 @@
1
- import { isUndefined } from 'a-type-of-js';
2
-
3
- /**
4
- *
5
- * 判断当前环境是否为 node 环境
6
- *
7
- */
8
- function isNode() {
9
- return !isUndefined(globalThis?.process?.versions?.node);
10
- }
11
- /**
12
- *
13
- * 是否为浏览器环境
14
- *
15
- */
16
- function isBrowser() {
17
- return !isNode();
18
- }
19
-
20
- export { isBrowser, isNode };
@@ -1,51 +0,0 @@
1
- 'use strict';
2
-
3
- /**
4
- *
5
- * 构建一个 Constructor 构造函数
6
- *
7
- * 接收一个构造函数,然后返回 TS 能识别的构造函数自身
8
- *
9
- * 函数本身并没有执行任何逻辑,仅是简单的返回了实参自身
10
- *
11
- * 而经过该函数的包装,构造函数成了能够被 TS 识别为可用 new 实例的构造函数
12
- *
13
- * @param constructor - 传入一个构造函数
14
- * @returns 返回传入的构造函数
15
- *
16
- * ```ts
17
- * import { createConstructor } from "a-js-tools";
18
- *
19
- * type Tom = {
20
- * a: number
21
- * }
22
- *
23
- * function _Tom (this: TomType): Tom {
24
- * this.a = 1;
25
- *
26
- * return this;
27
- * }
28
- *
29
- * // 逻辑上没有错,但是会造成 ts 显示
30
- * // 其目标缺少构造签名的 "new" 表达式隐式具有 "any" 类型。ts(7009)
31
- * const a = new _Tom();
32
- *
33
- * const tomConstructor = createConstructor(_tom);
34
- *
35
- * const b = new tomConstructor(); // 这时就不会显示错误
36
- *
37
- * ```
38
- *
39
- */
40
- function createConstructor(constructor) {
41
- constructor.prototype.apply = Function.apply;
42
- constructor.prototype.bind = Function.bind;
43
- constructor.prototype.call = Function.call;
44
- constructor.prototype.length = Function.length;
45
- // constructor.prototype.arguments = Function.arguments;
46
- constructor.prototype.name = Function.name;
47
- constructor.prototype.toString = Function.toString;
48
- return constructor;
49
- }
50
-
51
- exports.createConstructor = createConstructor;
@@ -1,49 +0,0 @@
1
- /**
2
- *
3
- * 构建一个 Constructor 构造函数
4
- *
5
- * 接收一个构造函数,然后返回 TS 能识别的构造函数自身
6
- *
7
- * 函数本身并没有执行任何逻辑,仅是简单的返回了实参自身
8
- *
9
- * 而经过该函数的包装,构造函数成了能够被 TS 识别为可用 new 实例的构造函数
10
- *
11
- * @param constructor - 传入一个构造函数
12
- * @returns 返回传入的构造函数
13
- *
14
- * ```ts
15
- * import { createConstructor } from "a-js-tools";
16
- *
17
- * type Tom = {
18
- * a: number
19
- * }
20
- *
21
- * function _Tom (this: TomType): Tom {
22
- * this.a = 1;
23
- *
24
- * return this;
25
- * }
26
- *
27
- * // 逻辑上没有错,但是会造成 ts 显示
28
- * // 其目标缺少构造签名的 "new" 表达式隐式具有 "any" 类型。ts(7009)
29
- * const a = new _Tom();
30
- *
31
- * const tomConstructor = createConstructor(_tom);
32
- *
33
- * const b = new tomConstructor(); // 这时就不会显示错误
34
- *
35
- * ```
36
- *
37
- */
38
- function createConstructor(constructor) {
39
- constructor.prototype.apply = Function.apply;
40
- constructor.prototype.bind = Function.bind;
41
- constructor.prototype.call = Function.call;
42
- constructor.prototype.length = Function.length;
43
- // constructor.prototype.arguments = Function.arguments;
44
- constructor.prototype.name = Function.name;
45
- constructor.prototype.toString = Function.toString;
46
- return constructor;
47
- }
48
-
49
- export { createConstructor };