ddan-js 1.0.0 → 1.0.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/LICENSE CHANGED
@@ -0,0 +1,7 @@
1
+ Copyright 2017 yury <yurangyi@heywoods.cn>
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
4
+
5
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
6
+
7
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md CHANGED
@@ -0,0 +1,10 @@
1
+ # ddan-js
2
+
3
+ A simple library
4
+
5
+ ### Usage
6
+
7
+ ```bash
8
+ npm i ddan-js
9
+ ```
10
+
@@ -0,0 +1,28 @@
1
+ class math {
2
+ /**
3
+ * 随机取值[0, max)
4
+ * @param max 最大值
5
+ */
6
+ static random(max) {
7
+ return Math.floor(Math.random() * max);
8
+ }
9
+ /**
10
+ * 范围随机取值[min, max]
11
+ * @param min 最小值
12
+ * @param max 最大值
13
+ */
14
+ static randomRange(min, max) {
15
+ return Math.floor(Math.random() * (max - min + 1) + min);
16
+ }
17
+ /**
18
+ * 插值
19
+ * @param start
20
+ * @param end
21
+ * @param t
22
+ */
23
+ static lerp(start, end, t) {
24
+ return start * (1 - t) + end * t;
25
+ }
26
+ }
27
+
28
+ export { math };
package/bin/ddan-js.js ADDED
@@ -0,0 +1,38 @@
1
+ (function (global, factory) {
2
+ typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports) :
3
+ typeof define === 'function' && define.amd ? define(['exports'], factory) :
4
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory(global.DdanJs = {}));
5
+ })(this, (function (exports) { 'use strict';
6
+
7
+ class math {
8
+ /**
9
+ * 随机取值[0, max)
10
+ * @param max 最大值
11
+ */
12
+ static random(max) {
13
+ return Math.floor(Math.random() * max);
14
+ }
15
+ /**
16
+ * 范围随机取值[min, max]
17
+ * @param min 最小值
18
+ * @param max 最大值
19
+ */
20
+ static randomRange(min, max) {
21
+ return Math.floor(Math.random() * (max - min + 1) + min);
22
+ }
23
+ /**
24
+ * 插值
25
+ * @param start
26
+ * @param end
27
+ * @param t
28
+ */
29
+ static lerp(start, end, t) {
30
+ return start * (1 - t) + end * t;
31
+ }
32
+ }
33
+
34
+ exports.math = math;
35
+
36
+ Object.defineProperty(exports, '__esModule', { value: true });
37
+
38
+ }));
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isChinese = exports.isString = exports.isNumber = void 0;
4
+ const util_1 = require("./util");
5
+ /**
6
+ * 判断是否数字
7
+ * @param value
8
+ * @returns
9
+ */
10
+ function isNumber(value) {
11
+ return util_1.default.getTag(value) === "[object Number]";
12
+ }
13
+ exports.isNumber = isNumber;
14
+ /**
15
+ * 判断是否是字符串
16
+ * @param value
17
+ * @returns
18
+ */
19
+ function isString(value) {
20
+ return util_1.default.getTag(value) === "[object String]";
21
+ }
22
+ exports.isString = isString;
23
+ function isChinese(content) {
24
+ if (!content)
25
+ return false;
26
+ const reg = /^[\u4E00-\u9FA5]+$/;
27
+ if (!reg.test(content)) {
28
+ return false;
29
+ }
30
+ return true;
31
+ }
32
+ exports.isChinese = isChinese;
@@ -0,0 +1,23 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const { toString } = Object.prototype;
4
+ const util = {
5
+ getTag(value) {
6
+ if (value == null) {
7
+ return value === undefined ? "[object Undefined]" : "[object Null]";
8
+ }
9
+ return toString.call(value);
10
+ },
11
+ getType(value) {
12
+ let str = "";
13
+ if (value == null) {
14
+ str = value === undefined ? "[object Undefined]" : "[object Null]";
15
+ }
16
+ else {
17
+ str = toString.call(value);
18
+ }
19
+ const mat = str.match(/\w+/g) || ["object", "Undefined"];
20
+ return mat[1] || "";
21
+ }
22
+ };
23
+ exports.default = util;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.math = void 0;
4
+ const math_1 = require("./modules/math");
5
+ exports.math = math_1.default;
@@ -0,0 +1,48 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.gbkCut = exports.gbkLength = void 0;
4
+ /**
5
+ *
6
+ * @param str
7
+ * @returns
8
+ */
9
+ function gbkLength(str) {
10
+ let len = 0;
11
+ if (!str)
12
+ return 0;
13
+ for (let i = 0; i < str.length; i++) {
14
+ if (str.charCodeAt(i) > 127 || str.charCodeAt(i) === 94) {
15
+ len += 2;
16
+ }
17
+ else {
18
+ len++;
19
+ }
20
+ }
21
+ return len;
22
+ }
23
+ exports.gbkLength = gbkLength;
24
+ /**
25
+ * 根据gbk字符长度截取内容
26
+ * @param {string} source
27
+ * @param {number} len
28
+ */
29
+ function gbkCut(source, len) {
30
+ if (!source || len <= 0)
31
+ return "";
32
+ let n = 0;
33
+ let idx = 0;
34
+ for (let i = 0; i < source.length; i++) {
35
+ if (source.charCodeAt(i) > 127 || source.charCodeAt(i) === 94) {
36
+ n += 2;
37
+ }
38
+ else {
39
+ n++;
40
+ }
41
+ if (n > len) {
42
+ break;
43
+ }
44
+ idx = i;
45
+ }
46
+ return source.substr(0, idx + 1);
47
+ }
48
+ exports.gbkCut = gbkCut;
@@ -0,0 +1,61 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.throttle = exports.debounce = exports.task = exports.run = exports.sleep = void 0;
4
+ /**
5
+ * 休眠
6
+ * @param {number} time
7
+ * @returns
8
+ */
9
+ const sleep = (time = 1000) => new Promise((resolve) => {
10
+ setTimeout(resolve, time);
11
+ });
12
+ exports.sleep = sleep;
13
+ function run(cb) {
14
+ try {
15
+ if (!cb)
16
+ return null;
17
+ return cb();
18
+ }
19
+ catch (err) {
20
+ return undefined;
21
+ }
22
+ }
23
+ exports.run = run;
24
+ const task = (promise) => promise.then((data) => [data, null]).catch((err) => [undefined, err]);
25
+ exports.task = task;
26
+ const debounce = (fn, interval = 300) => {
27
+ let timer;
28
+ const intervalTime = interval || 300;
29
+ return function func(...args) {
30
+ const context = this;
31
+ if (timer)
32
+ clearTimeout(timer);
33
+ timer = setTimeout(() => {
34
+ fn.call(context, ...args);
35
+ }, intervalTime);
36
+ };
37
+ };
38
+ exports.debounce = debounce;
39
+ const throttle = (fn, delay = 300) => {
40
+ let timer;
41
+ const delayTime = delay || 300;
42
+ let lastTime = Date.now();
43
+ return function func(...args) {
44
+ const context = this;
45
+ const curTime = Date.now();
46
+ const remaining = delayTime - (curTime - lastTime);
47
+ if (remaining < 0) {
48
+ timer && clearTimeout(timer);
49
+ timer = null;
50
+ fn.call(context, ...args);
51
+ lastTime = curTime;
52
+ }
53
+ else if (!timer) {
54
+ timer = setTimeout(() => {
55
+ fn.call(context, ...args);
56
+ lastTime = Date.now();
57
+ }, delayTime);
58
+ }
59
+ };
60
+ };
61
+ exports.throttle = throttle;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ class math {
4
+ /**
5
+ * 随机取值[0, max)
6
+ * @param max 最大值
7
+ */
8
+ static random(max) {
9
+ return Math.floor(Math.random() * max);
10
+ }
11
+ /**
12
+ * 范围随机取值[min, max]
13
+ * @param min 最小值
14
+ * @param max 最大值
15
+ */
16
+ static randomRange(min, max) {
17
+ return Math.floor(Math.random() * (max - min + 1) + min);
18
+ }
19
+ /**
20
+ * 插值
21
+ * @param start
22
+ * @param end
23
+ * @param t
24
+ */
25
+ static lerp(start, end, t) {
26
+ return start * (1 - t) + end * t;
27
+ }
28
+ }
29
+ exports.default = math;
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseTime = exports.timeFormat = exports.isToday = void 0;
4
+ /**
5
+ * 是否是今天
6
+ * @param {*} date
7
+ * @returns
8
+ */
9
+ const isToday = (date) => new Date().toDateString() === new Date(date).toDateString();
10
+ exports.isToday = isToday;
11
+ /**
12
+ * 时间格式化
13
+ * @param {string|number|Date} time
14
+ * @param {string} reg "yyyyMMdd hhmmss"
15
+ * @returns
16
+ */
17
+ const timeFormat = (time, reg) => {
18
+ const date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
19
+ const map = {};
20
+ map.yyyy = date.getFullYear();
21
+ map.yy = `${map.yyyy}`.substr(2);
22
+ map.M = date.getMonth() + 1;
23
+ map.MM = (map.M < 10 ? "0" : "") + map.M;
24
+ map.d = date.getDate();
25
+ map.dd = (map.d < 10 ? "0" : "") + map.d;
26
+ map.h = date.getHours();
27
+ map.hh = (map.h < 10 ? "0" : "") + map.h;
28
+ map.m = date.getMinutes();
29
+ map.mm = (map.m < 10 ? "0" : "") + map.m;
30
+ map.s = date.getSeconds();
31
+ map.ss = (map.s < 10 ? "0" : "") + map.s;
32
+ map.S = date.getMilliseconds();
33
+ map.SS = (map.S < 10 ? "0" : "") + map.S;
34
+ map.SSS = map.S.toString().padStart(3, 0);
35
+ return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, ($1) => map[$1]);
36
+ };
37
+ exports.timeFormat = timeFormat;
38
+ function parseTime({ year = 0, month = 0, date = 0, hour = 0, minute = 0, second = 0 }) {
39
+ const format = `${year || "yyyy"}/${month || "MM"}/${date || "dd"} ${hour}:${minute}:${second}`;
40
+ return new Date((0, exports.timeFormat)(Date.now(), format)).getTime();
41
+ }
42
+ exports.parseTime = parseTime;
@@ -0,0 +1,13 @@
1
+ /**
2
+ * 判断是否数字
3
+ * @param value
4
+ * @returns
5
+ */
6
+ export declare function isNumber(value: any): boolean;
7
+ /**
8
+ * 判断是否是字符串
9
+ * @param value
10
+ * @returns
11
+ */
12
+ export declare function isString(value: any): boolean;
13
+ export declare function isChinese(content: string): boolean;
@@ -0,0 +1,5 @@
1
+ declare const util: {
2
+ getTag(value: any): string;
3
+ getType(value: any): string;
4
+ };
5
+ export default util;
@@ -0,0 +1,2 @@
1
+ import math from "./modules/math";
2
+ export { math };
@@ -1,12 +1,12 @@
1
- /**
2
- *
3
- * @param str
4
- * @returns
5
- */
6
- export declare function gbkLength(str: string): number;
7
- /**
8
- * 根据gbk字符长度截取内容
9
- * @param {string} source
10
- * @param {number} len
11
- */
12
- export declare function gbkCut(source: string, len: number): string;
1
+ /**
2
+ *
3
+ * @param str
4
+ * @returns
5
+ */
6
+ export declare function gbkLength(str: string): number;
7
+ /**
8
+ * 根据gbk字符长度截取内容
9
+ * @param {string} source
10
+ * @param {number} len
11
+ */
12
+ export declare function gbkCut(source: string, len: number): string;
@@ -1,10 +1,10 @@
1
- /**
2
- * 休眠
3
- * @param {number} time
4
- * @returns
5
- */
6
- export declare const sleep: (time?: number) => Promise<unknown>;
7
- export declare function run(cb: Function): any;
8
- export declare const task: (promise: Promise<any>) => Promise<any[]>;
9
- export declare const debounce: (fn: Function, interval?: number) => (...args: any[]) => void;
10
- export declare const throttle: (fn: Function, delay?: number) => (...args: any[]) => void;
1
+ /**
2
+ * 休眠
3
+ * @param {number} time
4
+ * @returns
5
+ */
6
+ export declare const sleep: (time?: number) => Promise<unknown>;
7
+ export declare function run(cb: Function): any;
8
+ export declare const task: (promise: Promise<any>) => Promise<any[]>;
9
+ export declare const debounce: (fn: Function, interval?: number) => (...args: any[]) => void;
10
+ export declare const throttle: (fn: Function, delay?: number) => (...args: any[]) => void;
@@ -0,0 +1,20 @@
1
+ export default class math {
2
+ /**
3
+ * 随机取值[0, max)
4
+ * @param max 最大值
5
+ */
6
+ static random(max: number): number;
7
+ /**
8
+ * 范围随机取值[min, max]
9
+ * @param min 最小值
10
+ * @param max 最大值
11
+ */
12
+ static randomRange(min: number, max: number): number;
13
+ /**
14
+ * 插值
15
+ * @param start
16
+ * @param end
17
+ * @param t
18
+ */
19
+ static lerp(start: number, end: number, t: number): number;
20
+ }
@@ -1,21 +1,21 @@
1
- /**
2
- * 是否是今天
3
- * @param {*} date
4
- * @returns
5
- */
6
- export declare const isToday: (date: any) => boolean;
7
- /**
8
- * 时间格式化
9
- * @param {string|number|Date} time
10
- * @param {string} reg "yyyyMMdd hhmmss"
11
- * @returns
12
- */
13
- export declare const timeFormat: (time: string | number | Date, reg: string) => string;
14
- export declare function parseTime({ year, month, date, hour, minute, second }: {
15
- year?: number | undefined;
16
- month?: number | undefined;
17
- date?: number | undefined;
18
- hour?: number | undefined;
19
- minute?: number | undefined;
20
- second?: number | undefined;
21
- }): number;
1
+ /**
2
+ * 是否是今天
3
+ * @param {*} date
4
+ * @returns
5
+ */
6
+ export declare const isToday: (date: any) => boolean;
7
+ /**
8
+ * 时间格式化
9
+ * @param {string|number|Date} time
10
+ * @param {string} reg "yyyyMMdd hhmmss"
11
+ * @returns
12
+ */
13
+ export declare const timeFormat: (time: string | number | Date, reg: string) => string;
14
+ export declare function parseTime({ year, month, date, hour, minute, second }: {
15
+ year?: number | undefined;
16
+ month?: number | undefined;
17
+ date?: number | undefined;
18
+ hour?: number | undefined;
19
+ minute?: number | undefined;
20
+ second?: number | undefined;
21
+ }): number;
package/package.json CHANGED
@@ -1,82 +1,129 @@
1
1
  {
2
2
  "name": "ddan-js",
3
- "version": "1.0.0",
4
- "description": "工具库",
5
- "main": "lib/ddan-js.js",
6
- "module": "lib/ddan-js.esm.js",
7
- "typings": "lib/ddan-js.d.ts",
3
+ "version": "1.0.2",
4
+ "description": "",
5
+ "keywords": [],
6
+ "main": "bin/ddan-js.js",
7
+ "module": "bin/ddan-js.esm.js",
8
+ "typings": "bin/types/ddan-js.d.ts",
8
9
  "files": [
9
- "lib",
10
- "LICENSE",
11
- "CHANGELOG.md",
12
- "README.md"
10
+ "bin"
13
11
  ],
14
- "sideEffects": "false",
12
+ "author": "yry2580 <yry2580@qq.com>",
13
+ "publishConfig": {
14
+ "access": "public",
15
+ "registry": "https://registry.npmjs.org/"
16
+ },
17
+ "homepage": "https://github.com/yry2580/ddan-js#readme",
15
18
  "repository": {
16
19
  "type": "git",
17
20
  "url": "git+https://github.com/yry2580/ddan-js.git"
18
21
  },
19
- "author": "Simon",
20
22
  "license": "MIT",
21
- "bugs": {
22
- "url": "https://github.com/yry2580/ddan-js/issues"
23
- },
24
- "publishConfig": {
25
- "access": "public",
26
- "registry": "https://registry.npmjs.org/"
23
+ "engines": {
24
+ "node": ">=6.0.0"
27
25
  },
28
- "homepage": "https://github.com/yry2580/ddan-js#readme",
29
26
  "scripts": {
30
- "build": "gulp build",
31
- "api": "api-extractor run",
32
- "test": "jest --coverage --verbose -u",
33
- "test:watch": "jest --coverage --verbose --watch",
34
- "lint": "eslint --ext .js,.ts --format=pretty ./src",
35
- "lint:fix": "eslint --fix --ext .js,.ts --format=pretty ./src",
36
- "changelog": "gulp changelog",
37
- "version": "yarn changelog && git add CHANGELOG.md",
38
- "release": "yarn test && yarn build && np --no-cleanup --yolo --any-branch",
39
- "prepare": "husky install"
27
+ "lint": "tslint --project tsconfig.json -t codeFrame 'src/**/*.ts' 'test/**/*.ts'",
28
+ "prebuild": "rimraf bin",
29
+ "build": "tsc --module commonjs && rollup -c rollup.config.ts && typedoc --out docs src/index.ts --theme default",
30
+ "start": "rollup -c rollup.config.ts -w",
31
+ "test": "jest --coverage",
32
+ "test:watch": "jest --coverage --watch",
33
+ "test:prod": "npm run lint && npm run test -- --no-cache",
34
+ "deploy-docs": "ts-node tools/gh-pages-publish",
35
+ "report-coverage": "cat ./coverage/lcov.info | coveralls",
36
+ "commit": "git-cz",
37
+ "semantic-release": "semantic-release",
38
+ "semantic-release-prepare": "ts-node tools/semantic-release-prepare",
39
+ "precommit": "lint-staged",
40
+ "travis-deploy-once": "travis-deploy-once"
41
+ },
42
+ "lint-staged": {
43
+ "{src,test}/**/*.ts": [
44
+ "prettier --write",
45
+ "git add"
46
+ ]
47
+ },
48
+ "config": {
49
+ "commitizen": {
50
+ "path": "node_modules/cz-conventional-changelog"
51
+ }
52
+ },
53
+ "jest": {
54
+ "transform": {
55
+ ".(ts|tsx)": "ts-jest"
56
+ },
57
+ "testEnvironment": "node",
58
+ "testRegex": "(/__tests__/.*|\\.(test|spec))\\.(ts|tsx|js)$",
59
+ "moduleFileExtensions": [
60
+ "ts",
61
+ "tsx",
62
+ "js"
63
+ ],
64
+ "coveragePathIgnorePatterns": [
65
+ "/node_modules/",
66
+ "/test/"
67
+ ],
68
+ "coverageThreshold": {
69
+ "global": {
70
+ "branches": 90,
71
+ "functions": 95,
72
+ "lines": 95,
73
+ "statements": 95
74
+ }
75
+ },
76
+ "collectCoverageFrom": [
77
+ "src/*.{js,ts}"
78
+ ]
79
+ },
80
+ "prettier": {
81
+ "semi": false,
82
+ "singleQuote": true
83
+ },
84
+ "commitlint": {
85
+ "extends": [
86
+ "@commitlint/config-conventional"
87
+ ]
40
88
  },
41
89
  "devDependencies": {
42
- "@babel/core": "^7.17.9",
43
- "@babel/plugin-transform-runtime": "^7.17.0",
44
- "@babel/preset-env": "^7.16.11",
45
- "@babel/preset-typescript": "^7.16.7",
46
- "@microsoft/api-extractor": "^7.23.0",
47
- "@rollup/plugin-babel": "^5.3.1",
48
- "@rollup/plugin-commonjs": "^22.0.0",
49
- "@rollup/plugin-json": "^4.1.0",
50
- "@rollup/plugin-node-resolve": "^13.2.1",
51
- "@rollup/plugin-typescript": "^8.3.2",
52
- "@types/fs-extra": "^9.0.13",
53
- "@types/gulp": "^4.0.9",
54
- "@types/inquirer": "^9.0.3",
55
- "@types/jest": "^27.4.1",
56
- "@types/node": "^17.0.25",
57
- "@yueqing/lint": "^2.2.0",
58
- "chalk": "^4.1.2",
59
- "conventional-changelog": "^3.1.25",
60
- "fs-extra": "^10.1.0",
90
+ "@commitlint/cli": "^17.6.1",
91
+ "@commitlint/config-conventional": "^17.6.1",
92
+ "@types/babel__core": "7.1.19",
93
+ "@types/babel__traverse": "7.17.1",
94
+ "@types/jest": "^23.3.2",
95
+ "@types/node": "^14.17.0",
96
+ "colors": "^1.4.0",
97
+ "commitizen": "^4.3.0",
98
+ "coveralls": "^3.1.1",
99
+ "cross-env": "^7.0.3",
100
+ "cz-conventional-changelog": "^3.3.0",
61
101
  "gulp": "^4.0.2",
62
- "husky": "^7.0.4",
63
- "jest": "^27.5.1",
64
- "lint-staged": "^12.4.0",
65
- "np": "^7.6.1",
102
+ "gulp-uglify": "^3.0.2",
103
+ "jest": "^29.1.0",
104
+ "jest-config": "^29.1.0",
105
+ "lint-staged": "^13.2.1",
106
+ "lodash": "^4.17.21",
107
+ "prettier": "^2.8.8",
108
+ "prompt": "^1.3.0",
109
+ "replace-in-file": "^6.3.5",
110
+ "rimraf": "^5.0.0",
66
111
  "rollup": "^2.79.1",
67
- "rollup-plugin-terser": "^7.0.2",
112
+ "rollup-plugin-commonjs": "^10.1.0",
113
+ "rollup-plugin-json": "^4.0.0",
114
+ "rollup-plugin-node-resolve": "^5.2.0",
115
+ "rollup-plugin-sourcemaps": "^0.6.3",
68
116
  "rollup-plugin-typescript2": "^0.34.1",
69
- "ts-jest": "^27.1.4",
70
- "ts-node": "^10.7.0",
71
- "tslib": "^2.4.0",
72
- "typescript": "^4.9.5"
73
- },
74
- "dependencies": {
75
- "@babel/runtime": "^7.17.9"
76
- },
77
- "lint-staged": {
78
- "*.{ts,js}": [
79
- "eslint --fix --format=pretty"
80
- ]
117
+ "semantic-release": "^21.0.1",
118
+ "shelljs": "^0.8.5",
119
+ "travis-deploy-once": "^5.0.11",
120
+ "ts-jest": "^29.1.0",
121
+ "ts-node": "^10.9.1",
122
+ "tslib": "^2.5.0",
123
+ "tslint": "^5.20.1",
124
+ "tslint-config-prettier": "^1.18.0",
125
+ "tslint-config-standard": "^9.0.0",
126
+ "typedoc": "^0.24.0",
127
+ "typescript": "^5.0.4"
81
128
  }
82
129
  }
package/CHANGELOG.md DELETED
File without changes
@@ -1,235 +0,0 @@
1
- var toString = Object.prototype.toString;
2
- /**
3
- * 获取值的类型标签
4
- * @param value - 任意值
5
- * @returns [object Xxxx]
6
- *
7
- * @public
8
- */
9
- function getTag(value) {
10
- if (value == null) {
11
- return value === undefined ? "[object Undefined]" : "[object Null]";
12
- }
13
- return toString.call(value);
14
- }
15
- /**
16
- * 判断是否是数值类型
17
- * @param value - 任意值
18
- * @returns true / false
19
- * @example
20
- * ```ts
21
- * isNumber(2) // => true
22
- * ```
23
- *
24
- * @public
25
- */
26
- function isNumber(value) {
27
- return getTag(value) === "[object Number]";
28
- }
29
- /**
30
- * 判断是否是字符串类型
31
- * @param value - 任意值
32
- * @returns true / false
33
- * @example
34
- * ```ts
35
- * isString('abc') // => true
36
- * ```
37
- *
38
- * @public
39
- */
40
- function isString(value) {
41
- return getTag(value) === "[object String]";
42
- }
43
- function isChinese(content) {
44
- if (!content) return false;
45
- var reg = /^[\u4E00-\u9FA5]+$/;
46
- if (!reg.test(content)) {
47
- return false;
48
- }
49
- return true;
50
- }
51
-
52
- var is = /*#__PURE__*/Object.freeze({
53
- __proto__: null,
54
- getTag: getTag,
55
- isNumber: isNumber,
56
- isString: isString,
57
- isChinese: isChinese
58
- });
59
-
60
- /******************************************************************************
61
- Copyright (c) Microsoft Corporation.
62
-
63
- Permission to use, copy, modify, and/or distribute this software for any
64
- purpose with or without fee is hereby granted.
65
-
66
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
67
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
68
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
69
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
70
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
71
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
72
- PERFORMANCE OF THIS SOFTWARE.
73
- ***************************************************************************** */
74
-
75
- function __spreadArray(to, from, pack) {
76
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
77
- if (ar || !(i in from)) {
78
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
79
- ar[i] = from[i];
80
- }
81
- }
82
- return to.concat(ar || Array.prototype.slice.call(from));
83
- }
84
-
85
- /**
86
- * 休眠
87
- * @param {number} time
88
- * @returns
89
- */
90
- var sleep = function sleep(time) {
91
- if (time === void 0) {
92
- time = 1000;
93
- }
94
- return new Promise(function (resolve) {
95
- setTimeout(resolve, time);
96
- });
97
- };
98
- function run(cb) {
99
- try {
100
- if (!cb) return null;
101
- return cb();
102
- } catch (err) {
103
- return undefined;
104
- }
105
- }
106
- var task = function task(promise) {
107
- return promise.then(function (data) {
108
- return [data, null];
109
- })["catch"](function (err) {
110
- return [undefined, err];
111
- });
112
- };
113
- var debounce = function debounce(fn, interval) {
114
- if (interval === void 0) {
115
- interval = 300;
116
- }
117
- var timer;
118
- var intervalTime = interval || 300;
119
- return function func() {
120
- var args = [];
121
- for (var _i = 0; _i < arguments.length; _i++) {
122
- args[_i] = arguments[_i];
123
- }
124
- var context = this;
125
- if (timer) clearTimeout(timer);
126
- timer = setTimeout(function () {
127
- fn.call.apply(fn, __spreadArray([context], args, false));
128
- }, intervalTime);
129
- };
130
- };
131
- var throttle = function throttle(fn, delay) {
132
- if (delay === void 0) {
133
- delay = 300;
134
- }
135
- var timer;
136
- var delayTime = delay || 300;
137
- var lastTime = Date.now();
138
- return function func() {
139
- var args = [];
140
- for (var _i = 0; _i < arguments.length; _i++) {
141
- args[_i] = arguments[_i];
142
- }
143
- var context = this;
144
- var curTime = Date.now();
145
- var remaining = delayTime - (curTime - lastTime);
146
- if (remaining < 0) {
147
- timer && clearTimeout(timer);
148
- timer = null;
149
- fn.call.apply(fn, __spreadArray([context], args, false));
150
- lastTime = curTime;
151
- } else if (!timer) {
152
- timer = setTimeout(function () {
153
- fn.call.apply(fn, __spreadArray([context], args, false));
154
- lastTime = Date.now();
155
- }, delayTime);
156
- }
157
- };
158
- };
159
-
160
- var hook = /*#__PURE__*/Object.freeze({
161
- __proto__: null,
162
- sleep: sleep,
163
- run: run,
164
- task: task,
165
- debounce: debounce,
166
- throttle: throttle
167
- });
168
-
169
- /**
170
- * 是否是今天
171
- * @param {*} date
172
- * @returns
173
- */
174
- var isToday = function isToday(date) {
175
- return new Date().toDateString() === new Date(date).toDateString();
176
- };
177
- /**
178
- * 时间格式化
179
- * @param {string|number|Date} time
180
- * @param {string} reg "yyyyMMdd hhmmss"
181
- * @returns
182
- */
183
- var timeFormat = function timeFormat(time, reg) {
184
- var date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
185
- var map = {};
186
- map.yyyy = date.getFullYear();
187
- map.yy = "".concat(map.yyyy).substr(2);
188
- map.M = date.getMonth() + 1;
189
- map.MM = (map.M < 10 ? "0" : "") + map.M;
190
- map.d = date.getDate();
191
- map.dd = (map.d < 10 ? "0" : "") + map.d;
192
- map.h = date.getHours();
193
- map.hh = (map.h < 10 ? "0" : "") + map.h;
194
- map.m = date.getMinutes();
195
- map.mm = (map.m < 10 ? "0" : "") + map.m;
196
- map.s = date.getSeconds();
197
- map.ss = (map.s < 10 ? "0" : "") + map.s;
198
- map.S = date.getMilliseconds();
199
- map.SS = (map.S < 10 ? "0" : "") + map.S;
200
- map.SSS = map.S.toString().padStart(3, 0);
201
- return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, function ($1) {
202
- return map[$1];
203
- });
204
- };
205
- function parseTime(_a) {
206
- var _b = _a.year,
207
- year = _b === void 0 ? 0 : _b,
208
- _c = _a.month,
209
- month = _c === void 0 ? 0 : _c,
210
- _d = _a.date,
211
- date = _d === void 0 ? 0 : _d,
212
- _e = _a.hour,
213
- hour = _e === void 0 ? 0 : _e,
214
- _f = _a.minute,
215
- minute = _f === void 0 ? 0 : _f,
216
- _g = _a.second,
217
- second = _g === void 0 ? 0 : _g;
218
- var format = "".concat(year || "yyyy", "/").concat(month || "MM", "/").concat(date || "dd", " ").concat(hour, ":").concat(minute, ":").concat(second);
219
- return new Date(timeFormat(Date.now(), format)).getTime();
220
- }
221
-
222
- var time = /*#__PURE__*/Object.freeze({
223
- __proto__: null,
224
- isToday: isToday,
225
- timeFormat: timeFormat,
226
- parseTime: parseTime
227
- });
228
-
229
- var index = {
230
- is: is,
231
- hook: hook,
232
- time: time
233
- };
234
-
235
- export { index as default };
package/lib/ddan-js.js DELETED
@@ -1,237 +0,0 @@
1
- 'use strict';
2
-
3
- var toString = Object.prototype.toString;
4
- /**
5
- * 获取值的类型标签
6
- * @param value - 任意值
7
- * @returns [object Xxxx]
8
- *
9
- * @public
10
- */
11
- function getTag(value) {
12
- if (value == null) {
13
- return value === undefined ? "[object Undefined]" : "[object Null]";
14
- }
15
- return toString.call(value);
16
- }
17
- /**
18
- * 判断是否是数值类型
19
- * @param value - 任意值
20
- * @returns true / false
21
- * @example
22
- * ```ts
23
- * isNumber(2) // => true
24
- * ```
25
- *
26
- * @public
27
- */
28
- function isNumber(value) {
29
- return getTag(value) === "[object Number]";
30
- }
31
- /**
32
- * 判断是否是字符串类型
33
- * @param value - 任意值
34
- * @returns true / false
35
- * @example
36
- * ```ts
37
- * isString('abc') // => true
38
- * ```
39
- *
40
- * @public
41
- */
42
- function isString(value) {
43
- return getTag(value) === "[object String]";
44
- }
45
- function isChinese(content) {
46
- if (!content) return false;
47
- var reg = /^[\u4E00-\u9FA5]+$/;
48
- if (!reg.test(content)) {
49
- return false;
50
- }
51
- return true;
52
- }
53
-
54
- var is = /*#__PURE__*/Object.freeze({
55
- __proto__: null,
56
- getTag: getTag,
57
- isNumber: isNumber,
58
- isString: isString,
59
- isChinese: isChinese
60
- });
61
-
62
- /******************************************************************************
63
- Copyright (c) Microsoft Corporation.
64
-
65
- Permission to use, copy, modify, and/or distribute this software for any
66
- purpose with or without fee is hereby granted.
67
-
68
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
69
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
70
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
71
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
72
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
73
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
74
- PERFORMANCE OF THIS SOFTWARE.
75
- ***************************************************************************** */
76
-
77
- function __spreadArray(to, from, pack) {
78
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
79
- if (ar || !(i in from)) {
80
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
81
- ar[i] = from[i];
82
- }
83
- }
84
- return to.concat(ar || Array.prototype.slice.call(from));
85
- }
86
-
87
- /**
88
- * 休眠
89
- * @param {number} time
90
- * @returns
91
- */
92
- var sleep = function sleep(time) {
93
- if (time === void 0) {
94
- time = 1000;
95
- }
96
- return new Promise(function (resolve) {
97
- setTimeout(resolve, time);
98
- });
99
- };
100
- function run(cb) {
101
- try {
102
- if (!cb) return null;
103
- return cb();
104
- } catch (err) {
105
- return undefined;
106
- }
107
- }
108
- var task = function task(promise) {
109
- return promise.then(function (data) {
110
- return [data, null];
111
- })["catch"](function (err) {
112
- return [undefined, err];
113
- });
114
- };
115
- var debounce = function debounce(fn, interval) {
116
- if (interval === void 0) {
117
- interval = 300;
118
- }
119
- var timer;
120
- var intervalTime = interval || 300;
121
- return function func() {
122
- var args = [];
123
- for (var _i = 0; _i < arguments.length; _i++) {
124
- args[_i] = arguments[_i];
125
- }
126
- var context = this;
127
- if (timer) clearTimeout(timer);
128
- timer = setTimeout(function () {
129
- fn.call.apply(fn, __spreadArray([context], args, false));
130
- }, intervalTime);
131
- };
132
- };
133
- var throttle = function throttle(fn, delay) {
134
- if (delay === void 0) {
135
- delay = 300;
136
- }
137
- var timer;
138
- var delayTime = delay || 300;
139
- var lastTime = Date.now();
140
- return function func() {
141
- var args = [];
142
- for (var _i = 0; _i < arguments.length; _i++) {
143
- args[_i] = arguments[_i];
144
- }
145
- var context = this;
146
- var curTime = Date.now();
147
- var remaining = delayTime - (curTime - lastTime);
148
- if (remaining < 0) {
149
- timer && clearTimeout(timer);
150
- timer = null;
151
- fn.call.apply(fn, __spreadArray([context], args, false));
152
- lastTime = curTime;
153
- } else if (!timer) {
154
- timer = setTimeout(function () {
155
- fn.call.apply(fn, __spreadArray([context], args, false));
156
- lastTime = Date.now();
157
- }, delayTime);
158
- }
159
- };
160
- };
161
-
162
- var hook = /*#__PURE__*/Object.freeze({
163
- __proto__: null,
164
- sleep: sleep,
165
- run: run,
166
- task: task,
167
- debounce: debounce,
168
- throttle: throttle
169
- });
170
-
171
- /**
172
- * 是否是今天
173
- * @param {*} date
174
- * @returns
175
- */
176
- var isToday = function isToday(date) {
177
- return new Date().toDateString() === new Date(date).toDateString();
178
- };
179
- /**
180
- * 时间格式化
181
- * @param {string|number|Date} time
182
- * @param {string} reg "yyyyMMdd hhmmss"
183
- * @returns
184
- */
185
- var timeFormat = function timeFormat(time, reg) {
186
- var date = typeof time === "string" || typeof time === "number" ? new Date(time) : time;
187
- var map = {};
188
- map.yyyy = date.getFullYear();
189
- map.yy = "".concat(map.yyyy).substr(2);
190
- map.M = date.getMonth() + 1;
191
- map.MM = (map.M < 10 ? "0" : "") + map.M;
192
- map.d = date.getDate();
193
- map.dd = (map.d < 10 ? "0" : "") + map.d;
194
- map.h = date.getHours();
195
- map.hh = (map.h < 10 ? "0" : "") + map.h;
196
- map.m = date.getMinutes();
197
- map.mm = (map.m < 10 ? "0" : "") + map.m;
198
- map.s = date.getSeconds();
199
- map.ss = (map.s < 10 ? "0" : "") + map.s;
200
- map.S = date.getMilliseconds();
201
- map.SS = (map.S < 10 ? "0" : "") + map.S;
202
- map.SSS = map.S.toString().padStart(3, 0);
203
- return reg.replace(/\byyyy|yy|MM|M|dd|d|hh|h|mm|m|ss|s|SSS|SS|S\b/g, function ($1) {
204
- return map[$1];
205
- });
206
- };
207
- function parseTime(_a) {
208
- var _b = _a.year,
209
- year = _b === void 0 ? 0 : _b,
210
- _c = _a.month,
211
- month = _c === void 0 ? 0 : _c,
212
- _d = _a.date,
213
- date = _d === void 0 ? 0 : _d,
214
- _e = _a.hour,
215
- hour = _e === void 0 ? 0 : _e,
216
- _f = _a.minute,
217
- minute = _f === void 0 ? 0 : _f,
218
- _g = _a.second,
219
- second = _g === void 0 ? 0 : _g;
220
- var format = "".concat(year || "yyyy", "/").concat(month || "MM", "/").concat(date || "dd", " ").concat(hour, ":").concat(minute, ":").concat(second);
221
- return new Date(timeFormat(Date.now(), format)).getTime();
222
- }
223
-
224
- var time = /*#__PURE__*/Object.freeze({
225
- __proto__: null,
226
- isToday: isToday,
227
- timeFormat: timeFormat,
228
- parseTime: parseTime
229
- });
230
-
231
- var index = {
232
- is: is,
233
- hook: hook,
234
- time: time
235
- };
236
-
237
- module.exports = index;
package/lib/index.d.ts DELETED
@@ -1,111 +0,0 @@
1
- declare const debounce: (fn: Function, interval?: number) => (...args: any[]) => void;
2
-
3
- declare const _default: {
4
- is: typeof is;
5
- hook: typeof hook;
6
- time: typeof time;
7
- };
8
- export default _default;
9
-
10
- /**
11
- * 获取值的类型标签
12
- * @param value - 任意值
13
- * @returns [object Xxxx]
14
- *
15
- * @public
16
- */
17
- declare function getTag(value: any): string;
18
-
19
- declare namespace hook {
20
- export {
21
- run,
22
- sleep,
23
- task,
24
- debounce,
25
- throttle
26
- }
27
- }
28
-
29
- declare namespace is {
30
- export {
31
- getTag,
32
- isNumber,
33
- isString,
34
- isChinese
35
- }
36
- }
37
-
38
- declare function isChinese(content: string): boolean;
39
-
40
- /**
41
- * 判断是否是数值类型
42
- * @param value - 任意值
43
- * @returns true / false
44
- * @example
45
- * ```ts
46
- * isNumber(2) // => true
47
- * ```
48
- *
49
- * @public
50
- */
51
- declare function isNumber(value: any): boolean;
52
-
53
- /**
54
- * 判断是否是字符串类型
55
- * @param value - 任意值
56
- * @returns true / false
57
- * @example
58
- * ```ts
59
- * isString('abc') // => true
60
- * ```
61
- *
62
- * @public
63
- */
64
- declare function isString(value: any): boolean;
65
-
66
- /**
67
- * 是否是今天
68
- * @param {*} date
69
- * @returns
70
- */
71
- declare const isToday: (date: any) => boolean;
72
-
73
- declare function parseTime({ year, month, date, hour, minute, second }: {
74
- year?: number | undefined;
75
- month?: number | undefined;
76
- date?: number | undefined;
77
- hour?: number | undefined;
78
- minute?: number | undefined;
79
- second?: number | undefined;
80
- }): number;
81
-
82
- declare function run(cb: Function): any;
83
-
84
- /**
85
- * 休眠
86
- * @param {number} time
87
- * @returns
88
- */
89
- declare const sleep: (time?: number) => Promise<unknown>;
90
-
91
- declare const task: (promise: Promise<any>) => Promise<any[]>;
92
-
93
- declare const throttle: (fn: Function, delay?: number) => (...args: any[]) => void;
94
-
95
- declare namespace time {
96
- export {
97
- parseTime,
98
- isToday,
99
- timeFormat
100
- }
101
- }
102
-
103
- /**
104
- * 时间格式化
105
- * @param {string|number|Date} time
106
- * @param {string} reg "yyyyMMdd hhmmss"
107
- * @returns
108
- */
109
- declare const timeFormat: (time: string | number | Date, reg: string) => string;
110
-
111
- export { }
@@ -1,11 +0,0 @@
1
- // This file is read by tools that parse documentation comments conforming to the TSDoc standard.
2
- // It should be published with your NPM package. It should not be tracked by Git.
3
- {
4
- "tsdocVersion": "0.12",
5
- "toolPackages": [
6
- {
7
- "packageName": "@microsoft/api-extractor",
8
- "packageVersion": "7.34.4"
9
- }
10
- ]
11
- }