@vope/utils 1.1.0 → 1.2.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/README.md +0 -5
- package/cjs/index.js +10 -2
- package/cjs/input-regex.js +10 -0
- package/cjs/rotate/angle.js +14 -0
- package/cjs/rotate/rad.js +17 -0
- package/cjs/union.js +7 -6
- package/cjs/url/join.js +3 -3
- package/cjs/wait.js +6 -0
- package/lib/index.js +5 -1
- package/lib/input-regex.js +8 -0
- package/lib/rotate/angle.js +9 -0
- package/lib/rotate/rad.js +15 -0
- package/lib/union.js +7 -6
- package/lib/url/join.js +3 -3
- package/lib/wait.js +4 -0
- package/package.json +4 -7
- package/types/index.d.ts +5 -1
- package/types/input-regex.d.ts +13 -0
- package/types/rotate/angle.d.ts +9 -0
- package/types/rotate/rad.d.ts +9 -0
- package/types/union.d.ts +6 -5
- package/types/url/join.d.ts +2 -2
- package/types/wait.d.ts +5 -0
package/README.md
CHANGED
package/cjs/index.js
CHANGED
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.connectURLParams = exports.
|
|
6
|
+
exports.wait = exports.connectURLParams = exports.joinPaths = exports.Union = exports.rotateRad = exports.rotateAngle = exports.deconPowersSum = exports.once = exports.MemoryPower = exports.MemoryList = exports.MemoryBasic = exports.isNull = exports.isEmpty = exports.isClass = exports.inputRegex = exports.getEncoding = exports.hash8strings = exports.hash8object = exports.hash8json = exports.deepWeakEqual = exports.compareVersion = exports.classnames = exports.clamp = exports.apiGet = exports.apiPost = void 0;
|
|
7
7
|
var api_1 = require("./api");
|
|
8
8
|
Object.defineProperty(exports, "apiPost", { enumerable: true, get: function () { return api_1.apiPost; } });
|
|
9
9
|
Object.defineProperty(exports, "apiGet", { enumerable: true, get: function () { return api_1.apiGet; } });
|
|
@@ -23,6 +23,8 @@ var strings_1 = require("./convert/strings");
|
|
|
23
23
|
Object.defineProperty(exports, "hash8strings", { enumerable: true, get: function () { return __importDefault(strings_1).default; } });
|
|
24
24
|
var encoding_1 = require("./encoding");
|
|
25
25
|
Object.defineProperty(exports, "getEncoding", { enumerable: true, get: function () { return __importDefault(encoding_1).default; } });
|
|
26
|
+
var input_regex_1 = require("./input-regex");
|
|
27
|
+
Object.defineProperty(exports, "inputRegex", { enumerable: true, get: function () { return __importDefault(input_regex_1).default; } });
|
|
26
28
|
var class_1 = require("./is/class");
|
|
27
29
|
Object.defineProperty(exports, "isClass", { enumerable: true, get: function () { return __importDefault(class_1).default; } });
|
|
28
30
|
var empty_1 = require("./is/empty");
|
|
@@ -39,9 +41,15 @@ var once_1 = require("./once");
|
|
|
39
41
|
Object.defineProperty(exports, "once", { enumerable: true, get: function () { return __importDefault(once_1).default; } });
|
|
40
42
|
var decon_1 = require("./power/decon");
|
|
41
43
|
Object.defineProperty(exports, "deconPowersSum", { enumerable: true, get: function () { return __importDefault(decon_1).default; } });
|
|
44
|
+
var angle_1 = require("./rotate/angle");
|
|
45
|
+
Object.defineProperty(exports, "rotateAngle", { enumerable: true, get: function () { return __importDefault(angle_1).default; } });
|
|
46
|
+
var rad_1 = require("./rotate/rad");
|
|
47
|
+
Object.defineProperty(exports, "rotateRad", { enumerable: true, get: function () { return __importDefault(rad_1).default; } });
|
|
42
48
|
var union_1 = require("./union");
|
|
43
49
|
Object.defineProperty(exports, "Union", { enumerable: true, get: function () { return __importDefault(union_1).default; } });
|
|
44
50
|
var join_1 = require("./url/join");
|
|
45
|
-
Object.defineProperty(exports, "
|
|
51
|
+
Object.defineProperty(exports, "joinPaths", { enumerable: true, get: function () { return __importDefault(join_1).default; } });
|
|
46
52
|
var params_1 = require("./url/params");
|
|
47
53
|
Object.defineProperty(exports, "connectURLParams", { enumerable: true, get: function () { return __importDefault(params_1).default; } });
|
|
54
|
+
var wait_1 = require("./wait");
|
|
55
|
+
Object.defineProperty(exports, "wait", { enumerable: true, get: function () { return __importDefault(wait_1).default; } });
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
4
|
+
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
5
|
+
function inputRegex(text, flags) {
|
|
6
|
+
return flags === false
|
|
7
|
+
? text.replace(RE_STRING, ($0) => '\\' + $0)
|
|
8
|
+
: new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
|
|
9
|
+
}
|
|
10
|
+
exports.default = inputRegex;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
const rad_1 = __importDefault(require("./rad"));
|
|
7
|
+
/**
|
|
8
|
+
* 返回点被旋转指定角度后新的位置
|
|
9
|
+
* @param from 旋转点
|
|
10
|
+
* @param angle 旋转角度
|
|
11
|
+
* @param visit 旋转原点
|
|
12
|
+
*/
|
|
13
|
+
const rotateAngle = (from, angle, visit) => (0, rad_1.default)(from, angle / 180 * Math.PI, visit);
|
|
14
|
+
exports.default = rotateAngle;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
/**
|
|
4
|
+
* 返回点被旋转指定弧度后新的位置
|
|
5
|
+
* @param from 旋转点
|
|
6
|
+
* @param rad 旋转弧度
|
|
7
|
+
* @param visit 旋转原点
|
|
8
|
+
*/
|
|
9
|
+
const rotateRad = (from, rad, visit = [0, 0]) => {
|
|
10
|
+
const x = from[0] - visit[0];
|
|
11
|
+
const y = from[1] - visit[1];
|
|
12
|
+
return [
|
|
13
|
+
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
14
|
+
y * Math.cos(rad) - x * Math.sin(rad) + visit[1],
|
|
15
|
+
];
|
|
16
|
+
};
|
|
17
|
+
exports.default = rotateRad;
|
package/cjs/union.js
CHANGED
|
@@ -2,22 +2,23 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
/**
|
|
4
4
|
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
5
|
+
* @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
|
|
5
6
|
*/
|
|
6
7
|
class Union {
|
|
7
8
|
key;
|
|
8
|
-
|
|
9
|
+
formatter;
|
|
9
10
|
#map = {};
|
|
10
11
|
get value() {
|
|
11
12
|
return this.#map;
|
|
12
13
|
}
|
|
13
|
-
constructor(key,
|
|
14
|
+
constructor(key, formatter) {
|
|
14
15
|
this.key = key;
|
|
15
|
-
this.
|
|
16
|
+
this.formatter = formatter;
|
|
16
17
|
}
|
|
17
18
|
add(data) {
|
|
18
|
-
const {
|
|
19
|
-
this.#map[data[this.key]] =
|
|
20
|
-
?
|
|
19
|
+
const { formatter } = this;
|
|
20
|
+
this.#map[data[this.key]] = formatter
|
|
21
|
+
? formatter(data)
|
|
21
22
|
: data;
|
|
22
23
|
return this;
|
|
23
24
|
}
|
package/cjs/url/join.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const re = /(
|
|
3
|
+
const re = /([^:])\/{2,}/g;
|
|
4
4
|
/**
|
|
5
5
|
* 实现多个路径拼接
|
|
6
6
|
*/
|
|
7
|
-
const
|
|
7
|
+
const joinPaths = (...list) => {
|
|
8
8
|
const { length } = list;
|
|
9
9
|
if (length === 0)
|
|
10
10
|
return '';
|
|
@@ -12,4 +12,4 @@ const joinURLs = (...list) => {
|
|
|
12
12
|
? list[0]
|
|
13
13
|
: list.join('/').replace(re, ($0, $1) => `${$1}/`);
|
|
14
14
|
};
|
|
15
|
-
exports.default =
|
|
15
|
+
exports.default = joinPaths;
|
package/cjs/wait.js
ADDED
package/lib/index.js
CHANGED
|
@@ -7,6 +7,7 @@ export { default as hash8json } from './convert/json';
|
|
|
7
7
|
export { default as hash8object } from './convert/object';
|
|
8
8
|
export { default as hash8strings } from './convert/strings';
|
|
9
9
|
export { default as getEncoding } from './encoding';
|
|
10
|
+
export { default as inputRegex } from './input-regex';
|
|
10
11
|
export { default as isClass } from './is/class';
|
|
11
12
|
export { default as isEmpty } from './is/empty';
|
|
12
13
|
export { default as isNull } from './is/null';
|
|
@@ -15,6 +16,9 @@ export { default as MemoryList } from './memory/list';
|
|
|
15
16
|
export { default as MemoryPower } from './memory/power';
|
|
16
17
|
export { default as once } from './once';
|
|
17
18
|
export { default as deconPowersSum } from './power/decon';
|
|
19
|
+
export { default as rotateAngle } from './rotate/angle';
|
|
20
|
+
export { default as rotateRad } from './rotate/rad';
|
|
18
21
|
export { default as Union } from './union';
|
|
19
|
-
export { default as
|
|
22
|
+
export { default as joinPaths } from './url/join';
|
|
20
23
|
export { default as connectURLParams } from './url/params';
|
|
24
|
+
export { default as wait } from './wait';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
const RE_REGEX = /[$()*+.[?\\^{|]/g;
|
|
2
|
+
const RE_STRING = /[$()*+.[?\\^{|-]/g;
|
|
3
|
+
function inputRegex(text, flags) {
|
|
4
|
+
return flags === false
|
|
5
|
+
? text.replace(RE_STRING, ($0) => '\\' + $0)
|
|
6
|
+
: new RegExp(text.replace(RE_REGEX, ($0) => '\\' + $0), flags);
|
|
7
|
+
}
|
|
8
|
+
export default inputRegex;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 返回点被旋转指定弧度后新的位置
|
|
3
|
+
* @param from 旋转点
|
|
4
|
+
* @param rad 旋转弧度
|
|
5
|
+
* @param visit 旋转原点
|
|
6
|
+
*/
|
|
7
|
+
const rotateRad = (from, rad, visit = [0, 0]) => {
|
|
8
|
+
const x = from[0] - visit[0];
|
|
9
|
+
const y = from[1] - visit[1];
|
|
10
|
+
return [
|
|
11
|
+
x * Math.cos(rad) + y * Math.sin(rad) + visit[0],
|
|
12
|
+
y * Math.cos(rad) - x * Math.sin(rad) + visit[1],
|
|
13
|
+
];
|
|
14
|
+
};
|
|
15
|
+
export default rotateRad;
|
package/lib/union.js
CHANGED
|
@@ -1,21 +1,22 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
3
|
+
* @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
|
|
3
4
|
*/
|
|
4
5
|
export default class Union {
|
|
5
6
|
key;
|
|
6
|
-
|
|
7
|
+
formatter;
|
|
7
8
|
#map = {};
|
|
8
9
|
get value() {
|
|
9
10
|
return this.#map;
|
|
10
11
|
}
|
|
11
|
-
constructor(key,
|
|
12
|
+
constructor(key, formatter) {
|
|
12
13
|
this.key = key;
|
|
13
|
-
this.
|
|
14
|
+
this.formatter = formatter;
|
|
14
15
|
}
|
|
15
16
|
add(data) {
|
|
16
|
-
const {
|
|
17
|
-
this.#map[data[this.key]] =
|
|
18
|
-
?
|
|
17
|
+
const { formatter } = this;
|
|
18
|
+
this.#map[data[this.key]] = formatter
|
|
19
|
+
? formatter(data)
|
|
19
20
|
: data;
|
|
20
21
|
return this;
|
|
21
22
|
}
|
package/lib/url/join.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const re = /(
|
|
1
|
+
const re = /([^:])\/{2,}/g;
|
|
2
2
|
/**
|
|
3
3
|
* 实现多个路径拼接
|
|
4
4
|
*/
|
|
5
|
-
const
|
|
5
|
+
const joinPaths = (...list) => {
|
|
6
6
|
const { length } = list;
|
|
7
7
|
if (length === 0)
|
|
8
8
|
return '';
|
|
@@ -10,4 +10,4 @@ const joinURLs = (...list) => {
|
|
|
10
10
|
? list[0]
|
|
11
11
|
: list.join('/').replace(re, ($0, $1) => `${$1}/`);
|
|
12
12
|
};
|
|
13
|
-
export default
|
|
13
|
+
export default joinPaths;
|
package/lib/wait.js
ADDED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vope/utils",
|
|
3
|
-
"version": "1.1
|
|
3
|
+
"version": "1.2.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"publishConfig": {
|
|
@@ -12,18 +12,15 @@
|
|
|
12
12
|
"main": "./cjs/index.js",
|
|
13
13
|
"scripts": {
|
|
14
14
|
"build": "npm run cjs | npm run esm | npm run types",
|
|
15
|
-
"init:build": "npm run devs & npm run trove & npm run test:build",
|
|
16
15
|
"cjs": "rimraf cjs & npx tsc -p ./tsconfig.cjs.json",
|
|
17
16
|
"esm": "rimraf lib & npx tsc -p ./tsconfig.esm.json",
|
|
18
17
|
"types": "rimraf types & npx tsc -p ./tsconfig.types.json & node ./__devs/type.cjs",
|
|
19
18
|
"trove": "node ./__devs/trove.cjs",
|
|
20
19
|
"trove:build": "npm run devs & npm run trove",
|
|
21
20
|
"devs": "rimraf __devs & npx tsc -p ./tsconfig.devs.json",
|
|
22
|
-
"test": "mocha __tests/**/*.js",
|
|
23
|
-
"test:
|
|
24
|
-
"
|
|
25
|
-
"test:all": "npm run devs & npm run test:build & npm run test",
|
|
26
|
-
"prepublishOnly": "npm run devs & npm run trove & npm run build"
|
|
21
|
+
"test": "node ./__devs/test.cjs & mocha __tests/**/*.js",
|
|
22
|
+
"test:build": "npm run devs & npm run trove & npm run test",
|
|
23
|
+
"prepublishOnly": "npm run devs & npm run trove & npm run test & npm run build"
|
|
27
24
|
},
|
|
28
25
|
"exports": {
|
|
29
26
|
".": {
|
package/types/index.d.ts
CHANGED
|
@@ -7,6 +7,7 @@ export { default as hash8json } from './convert/json';
|
|
|
7
7
|
export { default as hash8object } from './convert/object';
|
|
8
8
|
export { default as hash8strings } from './convert/strings';
|
|
9
9
|
export { default as getEncoding } from './encoding';
|
|
10
|
+
export { default as inputRegex } from './input-regex';
|
|
10
11
|
export { default as isClass } from './is/class';
|
|
11
12
|
export { default as isEmpty } from './is/empty';
|
|
12
13
|
export { default as isNull } from './is/null';
|
|
@@ -15,6 +16,9 @@ export { default as MemoryList } from './memory/list';
|
|
|
15
16
|
export { default as MemoryPower } from './memory/power';
|
|
16
17
|
export { default as once } from './once';
|
|
17
18
|
export { default as deconPowersSum } from './power/decon';
|
|
19
|
+
export { default as rotateAngle } from './rotate/angle';
|
|
20
|
+
export { default as rotateRad } from './rotate/rad';
|
|
18
21
|
export { default as Union } from './union';
|
|
19
|
-
export { default as
|
|
22
|
+
export { default as joinPaths } from './url/join';
|
|
20
23
|
export { default as connectURLParams } from './url/params';
|
|
24
|
+
export { default as wait } from './wait';
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
3
|
+
* @param text
|
|
4
|
+
* @param flags 表示输出正则表达式
|
|
5
|
+
*/
|
|
6
|
+
declare function inputRegex(text: string, flags?: string): RegExp;
|
|
7
|
+
/**
|
|
8
|
+
* 处理输入文本中的特殊字符,用于转换正则表达式
|
|
9
|
+
* @param text
|
|
10
|
+
* @param flags 表示输出字符串,该字符串将作为正则表达式的一部分
|
|
11
|
+
*/
|
|
12
|
+
declare function inputRegex(text: string, flags: false): string;
|
|
13
|
+
export default inputRegex;
|
package/types/union.d.ts
CHANGED
|
@@ -6,15 +6,16 @@ type IMap<K extends string, VV extends string, T extends {
|
|
|
6
6
|
};
|
|
7
7
|
/**
|
|
8
8
|
* 数据联合(用于需要对加入的数据进行智能提示)
|
|
9
|
+
* @description 如果设置了formatter,则可以通过设置泛型R来变化Union.value的类型
|
|
9
10
|
*/
|
|
10
11
|
export default class Union<K extends string, VV extends string, T extends {
|
|
11
12
|
[key in K]: string;
|
|
12
|
-
}, L extends VV | never = never> {
|
|
13
|
+
}, R extends T = T, L extends VV | never = never> {
|
|
13
14
|
#private;
|
|
14
15
|
private key;
|
|
15
|
-
private
|
|
16
|
-
get value(): Required<IMap<K, L,
|
|
17
|
-
constructor(key: K,
|
|
18
|
-
add<V extends Exclude<VV, L>>(data: Revise<T, K, V>): Union<K, VV, T, L | V>;
|
|
16
|
+
private formatter?;
|
|
17
|
+
get value(): Required<IMap<K, L, R>>;
|
|
18
|
+
constructor(key: K, formatter?: ((data: T) => R) | undefined);
|
|
19
|
+
add<V extends Exclude<VV, L>>(data: Revise<T, K, V>): Union<K, VV, T, R, L | V>;
|
|
19
20
|
}
|
|
20
21
|
export {};
|
package/types/url/join.d.ts
CHANGED