@daysnap/utils 0.0.41 → 0.0.42
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 +21 -4
- package/docs/README.md +20 -4
- package/docs/modules.md +228 -93
- package/es/base64ToBlob.js +11 -17
- package/es/blobToBase64.js +10 -10
- package/es/canvasToBlob.js +4 -6
- package/es/clone.d.ts +4 -6
- package/es/clone.js +18 -8
- package/es/cloneSimple.d.ts +7 -0
- package/es/cloneSimple.js +9 -0
- package/es/compareVersion.js +27 -40
- package/es/compressImage.js +11 -13
- package/es/createHexColorByHash.js +59 -56
- package/es/debounce.d.ts +5 -0
- package/es/debounce.js +14 -0
- package/es/downloadFile.js +7 -7
- package/es/each.js +11 -10
- package/es/filterBankCardNo.js +4 -2
- package/es/filterCRLF.js +2 -2
- package/es/filterEmoji.js +13 -6
- package/es/filterIdCard.js +2 -2
- package/es/filterName.js +12 -12
- package/es/filterPhone.js +3 -4
- package/es/formatAmount.js +18 -20
- package/es/formatDate.js +28 -29
- package/es/getBlobByUrl.js +17 -18
- package/es/getDayMillisecond.js +3 -4
- package/es/getImageInfo.js +9 -9
- package/es/getRandomColor.js +2 -2
- package/es/getVideoInfo.js +11 -11
- package/es/inBrowser.js +2 -2
- package/es/index.d.ts +4 -0
- package/es/index.js +5 -1
- package/es/isAndroid.js +2 -2
- package/es/isArray.js +2 -2
- package/es/isBoolean.js +2 -2
- package/es/isEmail.js +2 -2
- package/es/isEmpty.js +2 -2
- package/es/isEmptyObject.js +2 -2
- package/es/isError.js +2 -2
- package/es/isFunction.js +2 -2
- package/es/isIOS.js +2 -2
- package/es/isIdCard.js +2 -2
- package/es/isJSONString.js +8 -7
- package/es/isLan.js +29 -28
- package/es/isLicenseCode.js +2 -2
- package/es/isMobile.js +7 -6
- package/es/isNull.js +2 -2
- package/es/isNumber.js +2 -2
- package/es/isObject.js +2 -2
- package/es/isPhone.js +2 -2
- package/es/isPromise.js +2 -2
- package/es/isRegExp.js +2 -2
- package/es/isString.js +2 -2
- package/es/isURL.d.ts +4 -0
- package/es/isURL.js +6 -0
- package/es/isUndefined.js +2 -2
- package/es/isWeixin.js +2 -2
- package/es/isWindow.js +2 -2
- package/es/loadResource.d.ts +1 -1
- package/es/loadResource.js +27 -23
- package/es/omit.js +7 -9
- package/es/padding.js +5 -5
- package/es/parseDate.js +7 -7
- package/es/parseError.js +15 -16
- package/es/parseObject.d.ts +2 -1
- package/es/parseObject.js +9 -8
- package/es/parsePath.js +7 -7
- package/es/parseQuery.d.ts +1 -1
- package/es/parseQuery.js +13 -24
- package/es/pick.js +7 -8
- package/es/replaceCrlf.js +2 -2
- package/es/reserve.js +2 -2
- package/es/round.js +38 -39
- package/es/sleep.d.ts +4 -2
- package/es/sleep.js +8 -7
- package/es/storage/factory.d.ts +2 -2
- package/es/storage/factory.js +44 -54
- package/es/storage/index.d.ts +4 -4
- package/es/storage/index.js +10 -10
- package/es/stringTrim.d.ts +3 -1
- package/es/stringTrim.js +17 -19
- package/es/stringifyQuery.d.ts +1 -1
- package/es/stringifyQuery.js +11 -8
- package/es/throttle.d.ts +5 -0
- package/es/throttle.js +17 -0
- package/es/typeOf.d.ts +1 -1
- package/es/typeOf.js +2 -2
- package/lib/base64ToBlob.js +14 -23
- package/lib/blobToBase64.js +13 -15
- package/lib/canvasToBlob.js +7 -11
- package/lib/clone.d.ts +4 -6
- package/lib/clone.js +21 -13
- package/lib/cloneSimple.d.ts +7 -0
- package/lib/cloneSimple.js +13 -0
- package/lib/compareVersion.js +30 -46
- package/lib/compressImage.js +15 -19
- package/lib/createHexColorByHash.js +60 -60
- package/lib/debounce.d.ts +5 -0
- package/lib/debounce.js +18 -0
- package/lib/downloadFile.js +10 -12
- package/lib/each.js +14 -15
- package/lib/filterBankCardNo.js +7 -7
- package/lib/filterCRLF.js +5 -7
- package/lib/filterEmoji.js +16 -11
- package/lib/filterIdCard.js +5 -7
- package/lib/filterName.js +15 -17
- package/lib/filterPhone.js +6 -9
- package/lib/formatAmount.js +21 -25
- package/lib/formatDate.js +32 -35
- package/lib/getBlobByUrl.js +20 -23
- package/lib/getDayMillisecond.js +6 -9
- package/lib/getImageInfo.js +12 -14
- package/lib/getRandomColor.js +5 -7
- package/lib/getVideoInfo.js +14 -16
- package/lib/inBrowser.js +5 -7
- package/lib/index.d.ts +4 -0
- package/lib/index.js +84 -708
- package/lib/isAndroid.js +5 -7
- package/lib/isArray.js +5 -7
- package/lib/isBoolean.js +5 -7
- package/lib/isEmail.js +5 -7
- package/lib/isEmpty.js +7 -9
- package/lib/isEmptyObject.js +5 -7
- package/lib/isError.js +5 -7
- package/lib/isFunction.js +5 -7
- package/lib/isIOS.js +5 -7
- package/lib/isIdCard.js +5 -7
- package/lib/isJSONString.js +12 -13
- package/lib/isLan.js +32 -33
- package/lib/isLicenseCode.js +5 -7
- package/lib/isMobile.js +10 -11
- package/lib/isNull.js +5 -7
- package/lib/isNumber.js +5 -7
- package/lib/isObject.js +5 -7
- package/lib/isPhone.js +5 -7
- package/lib/isPromise.js +5 -7
- package/lib/isRegExp.js +5 -7
- package/lib/isString.js +5 -7
- package/lib/isURL.d.ts +4 -0
- package/lib/isURL.js +10 -0
- package/lib/isUndefined.js +5 -7
- package/lib/isWeixin.js +5 -7
- package/lib/isWindow.js +5 -7
- package/lib/loadResource.d.ts +1 -1
- package/lib/loadResource.js +31 -29
- package/lib/omit.js +10 -15
- package/lib/padding.js +8 -10
- package/lib/parseDate.js +10 -12
- package/lib/parseError.js +21 -24
- package/lib/parseObject.d.ts +2 -1
- package/lib/parseObject.js +12 -13
- package/lib/parsePath.js +10 -12
- package/lib/parseQuery.d.ts +1 -1
- package/lib/parseQuery.js +17 -31
- package/lib/pick.js +10 -13
- package/lib/replaceCrlf.js +5 -7
- package/lib/reserve.js +6 -8
- package/lib/round.js +41 -44
- package/lib/sleep.d.ts +4 -2
- package/lib/sleep.js +11 -12
- package/lib/storage/factory.d.ts +2 -2
- package/lib/storage/factory.js +47 -60
- package/lib/storage/index.d.ts +4 -4
- package/lib/storage/index.js +12 -17
- package/lib/stringTrim.d.ts +3 -1
- package/lib/stringTrim.js +20 -24
- package/lib/stringifyQuery.d.ts +1 -1
- package/lib/stringifyQuery.js +15 -14
- package/lib/throttle.d.ts +5 -0
- package/lib/throttle.js +21 -0
- package/lib/typeOf.d.ts +1 -1
- package/lib/typeOf.js +5 -7
- package/package.json +15 -17
package/lib/storage/index.js
CHANGED
|
@@ -1,20 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, "__esModule", {
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
3
|
exports.getLocal = exports.getCache = void 0;
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
4
|
+
const factory_1 = require("./factory");
|
|
5
|
+
const getStorage = (type) => {
|
|
6
|
+
let instance = null;
|
|
7
|
+
return () => {
|
|
8
|
+
if (!instance) {
|
|
9
|
+
instance = (0, factory_1.factory)(type);
|
|
10
|
+
}
|
|
11
|
+
return instance;
|
|
12
|
+
};
|
|
16
13
|
};
|
|
17
|
-
|
|
18
|
-
exports.
|
|
19
|
-
var getLocal = getStorage('localStorage');
|
|
20
|
-
exports.getLocal = getLocal;
|
|
14
|
+
exports.getCache = getStorage('sessionStorage');
|
|
15
|
+
exports.getLocal = getStorage('localStorage');
|
package/lib/stringTrim.d.ts
CHANGED
package/lib/stringTrim.js
CHANGED
|
@@ -1,27 +1,23 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.stringTrim = stringTrim;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringTrim = void 0;
|
|
7
4
|
/**
|
|
8
|
-
|
|
5
|
+
* 去除字符串空格
|
|
6
|
+
* @param str 字符串值
|
|
7
|
+
* @param type 方式 1-所有空格,2-前后空格,3-前空格,4-后空格
|
|
9
8
|
*/
|
|
10
|
-
function stringTrim(str, type) {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
return str;
|
|
26
|
-
}
|
|
27
|
-
}
|
|
9
|
+
function stringTrim(str, type = 1) {
|
|
10
|
+
switch (type) {
|
|
11
|
+
case 1:
|
|
12
|
+
return str.replace(/\s+/g, '');
|
|
13
|
+
case 2:
|
|
14
|
+
return str.replace(/(^\s*)|(\s*$)/g, '');
|
|
15
|
+
case 3:
|
|
16
|
+
return str.replace(/(^\s*)/g, '');
|
|
17
|
+
case 4:
|
|
18
|
+
return str.replace(/(\s*$)/g, '');
|
|
19
|
+
default:
|
|
20
|
+
return str;
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
exports.stringTrim = stringTrim;
|
package/lib/stringifyQuery.d.ts
CHANGED
package/lib/stringifyQuery.js
CHANGED
|
@@ -1,19 +1,20 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
exports.stringifyQuery = stringifyQuery;
|
|
7
|
-
var _isEmptyObject = require("./isEmptyObject");
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.stringifyQuery = void 0;
|
|
4
|
+
const isEmptyObject_1 = require("./isEmptyObject");
|
|
5
|
+
const isString_1 = require("./isString");
|
|
8
6
|
/**
|
|
9
7
|
* 说明
|
|
10
8
|
*/
|
|
11
9
|
function stringifyQuery(v) {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
10
|
+
if ((0, isEmptyObject_1.isEmptyObject)(v)) {
|
|
11
|
+
return '';
|
|
12
|
+
}
|
|
13
|
+
const query = new URLSearchParams();
|
|
14
|
+
Object.keys(v).forEach((key) => {
|
|
15
|
+
const value = (0, isString_1.isString)(v[key]) ? v[key] : JSON.stringify(v[key]);
|
|
16
|
+
query.append(key, value);
|
|
17
|
+
});
|
|
18
|
+
return query.toString();
|
|
19
|
+
}
|
|
20
|
+
exports.stringifyQuery = stringifyQuery;
|
package/lib/throttle.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.throttle = void 0;
|
|
4
|
+
/**
|
|
5
|
+
* 节流函数
|
|
6
|
+
* 减少事件执行次数,有规律的执行
|
|
7
|
+
*/
|
|
8
|
+
function throttle(fn, ms) {
|
|
9
|
+
let timer = null;
|
|
10
|
+
// eslint-disable-next-line func-names
|
|
11
|
+
return function (...args) {
|
|
12
|
+
if (timer) {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
timer = setTimeout(() => {
|
|
16
|
+
fn.apply(this, args);
|
|
17
|
+
timer = null;
|
|
18
|
+
}, ms);
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
exports.throttle = throttle;
|
package/lib/typeOf.d.ts
CHANGED
|
@@ -3,4 +3,4 @@
|
|
|
3
3
|
* @param val 待判断数据
|
|
4
4
|
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
5
5
|
*/
|
|
6
|
-
export declare function typeOf
|
|
6
|
+
export declare function typeOf(val: unknown): string;
|
package/lib/typeOf.js
CHANGED
|
@@ -1,14 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.typeOf = typeOf;
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.typeOf = void 0;
|
|
7
4
|
/**
|
|
8
5
|
* 判断类型
|
|
9
6
|
* @param val 待判断数据
|
|
10
7
|
* @returns 'undefined'|'null'|'boolean'|'string'|'number'|'object'|'array'|'function'|'symbol'|'map'|'weakmap'|'bigint'|'regexp'|'date'
|
|
11
8
|
*/
|
|
12
9
|
function typeOf(val) {
|
|
13
|
-
|
|
14
|
-
}
|
|
10
|
+
return Object.prototype.toString.call(val).slice(8, -1).toLowerCase();
|
|
11
|
+
}
|
|
12
|
+
exports.typeOf = typeOf;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@daysnap/utils",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.42",
|
|
4
4
|
"description": "通用的工具库",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -10,14 +10,18 @@
|
|
|
10
10
|
"del": "plop --plopfile ./scripts/del.js --force",
|
|
11
11
|
"entry": "plop --plopfile ./scripts/entry.js --force",
|
|
12
12
|
"docs": "typedoc --plugin typedoc-plugin-markdown --out docs src/index.ts",
|
|
13
|
-
"
|
|
13
|
+
"clean:es": "rimraf ./es",
|
|
14
|
+
"clean:lib": "rimraf ./lib",
|
|
15
|
+
"clean": "npm run clean:es && npm run clean:lib",
|
|
16
|
+
"build:es": "npm run clean:es && tsc -p ./tsconfig-esm.json",
|
|
17
|
+
"build:lib": "npm run clean:lib && tsc -p ./tsconfig.json",
|
|
18
|
+
"build": "npm run build:es && npm run build:lib",
|
|
14
19
|
"test": "jest",
|
|
15
20
|
"coverage": "jest --coverage",
|
|
16
21
|
"prerelease": "npm run entry && npm run test && npm run docs",
|
|
17
22
|
"release": "npm run build && dsc publish -t",
|
|
18
|
-
"husky": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' >> ~/.huskyrc",
|
|
19
23
|
"lint": "eslint 'src/**/*.{js,ts}' --fix",
|
|
20
|
-
"prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"'
|
|
24
|
+
"prepare": "husky install && echo 'export PATH=\"/usr/local/bin/:$PATH\"' > ~/.huskyrc"
|
|
21
25
|
},
|
|
22
26
|
"repository": {
|
|
23
27
|
"type": "git",
|
|
@@ -43,24 +47,21 @@
|
|
|
43
47
|
"devDependencies": {
|
|
44
48
|
"@commitlint/cli": "^16.2.1",
|
|
45
49
|
"@commitlint/config-conventional": "^16.2.1",
|
|
46
|
-
"@types/jest": "^
|
|
47
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
48
|
-
"@typescript-eslint/parser": "^5.
|
|
50
|
+
"@types/jest": "^27.5.2",
|
|
51
|
+
"@typescript-eslint/eslint-plugin": "^5.55.0",
|
|
52
|
+
"@typescript-eslint/parser": "^5.55.0",
|
|
49
53
|
"commitizen": "^4.2.4",
|
|
50
|
-
"eslint": "^8.
|
|
51
|
-
"eslint-config-
|
|
52
|
-
"eslint-config-prettier": "^8.5.0",
|
|
53
|
-
"eslint-plugin-import": "^2.26.0",
|
|
54
|
+
"eslint": "^8.36.0",
|
|
55
|
+
"eslint-config-prettier": "^8.7.0",
|
|
54
56
|
"eslint-plugin-prettier": "^4.2.1",
|
|
55
57
|
"husky": "^7.0.4",
|
|
56
58
|
"jest": "^27.5.1",
|
|
57
59
|
"lint-staged": "^13.0.3",
|
|
58
60
|
"node-dir": "^0.1.17",
|
|
59
61
|
"plop": "^3.1.1",
|
|
60
|
-
"prettier": "^2.
|
|
62
|
+
"prettier": "^2.8.4",
|
|
61
63
|
"rimraf": "^3.0.2",
|
|
62
|
-
"ts-jest": "^27.1.
|
|
63
|
-
"ts-node": "^10.9.1",
|
|
64
|
+
"ts-jest": "^27.1.5",
|
|
64
65
|
"typedoc": "^0.23.21",
|
|
65
66
|
"typedoc-plugin-markdown": "^3.14.0",
|
|
66
67
|
"typescript": "^4.8.4"
|
|
@@ -74,8 +75,5 @@
|
|
|
74
75
|
},
|
|
75
76
|
"lint-staged": {
|
|
76
77
|
"*.{js,ts}": "eslint --fix"
|
|
77
|
-
},
|
|
78
|
-
"dependencies": {
|
|
79
|
-
"@babel/runtime": "^7.19.4"
|
|
80
78
|
}
|
|
81
79
|
}
|