qmwts 1.0.9 → 1.0.10
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/dist/index.d.ts +3 -3
- package/dist/index.js +3 -3
- package/package.json +5 -2
- package/index.test.js +0 -9
- package/index.ts +0 -11
- package/jest.config.js +0 -5
- package/src/utils/json-utils.ts +0 -42
- package/src/utils/number-utils.ts +0 -26
- package/src/utils/uuid-utils.ts +0 -9
- package/tsconfig.json +0 -9
- /package/dist/{src/utils → utils}/json-utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/json-utils.js +0 -0
- /package/dist/{src/utils → utils}/number-utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/number-utils.js +0 -0
- /package/dist/{src/utils → utils}/uuid-utils.d.ts +0 -0
- /package/dist/{src/utils → utils}/uuid-utils.js +0 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import NumberUtils from './
|
|
2
|
-
import JsonUtils from './
|
|
3
|
-
import UUIDUtils from './
|
|
1
|
+
import NumberUtils from './utils/number-utils';
|
|
2
|
+
import JsonUtils from './utils/json-utils';
|
|
3
|
+
import UUIDUtils from './utils/uuid-utils';
|
|
4
4
|
export { NumberUtils, JsonUtils, UUIDUtils };
|
package/dist/index.js
CHANGED
|
@@ -2,9 +2,9 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = void 0;
|
|
4
4
|
// https://www.jianshu.com/p/8fa2c50720e4
|
|
5
|
-
var number_utils_1 = require("./
|
|
5
|
+
var number_utils_1 = require("./utils/number-utils");
|
|
6
6
|
exports.NumberUtils = number_utils_1.default;
|
|
7
|
-
var json_utils_1 = require("./
|
|
7
|
+
var json_utils_1 = require("./utils/json-utils");
|
|
8
8
|
exports.JsonUtils = json_utils_1.default;
|
|
9
|
-
var uuid_utils_1 = require("./
|
|
9
|
+
var uuid_utils_1 = require("./utils/uuid-utils");
|
|
10
10
|
exports.UUIDUtils = uuid_utils_1.default;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "qmwts",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "",
|
|
5
5
|
"main": "index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -13,5 +13,8 @@
|
|
|
13
13
|
"jest": "^29.6.2",
|
|
14
14
|
"ts-jest": "^29.1.1",
|
|
15
15
|
"typescript": "^5.1.6"
|
|
16
|
-
}
|
|
16
|
+
},
|
|
17
|
+
"files": [
|
|
18
|
+
"dist"
|
|
19
|
+
]
|
|
17
20
|
}
|
package/index.test.js
DELETED
|
@@ -1,9 +0,0 @@
|
|
|
1
|
-
const { NumberUtils, JsonUtils, UUIDUtils } = require('./index')
|
|
2
|
-
test('isNumber', () => {
|
|
3
|
-
expect(NumberUtils.thousandths(1)).toBe('1.00')
|
|
4
|
-
expect(JsonUtils.toJSONArray("{\"1\":1}")).toStrictEqual([])
|
|
5
|
-
console.log(UUIDUtils.uuid())
|
|
6
|
-
console.log(UUIDUtils.uuid())
|
|
7
|
-
console.log(UUIDUtils.uuid())
|
|
8
|
-
console.log(UUIDUtils.uuid())
|
|
9
|
-
})
|
package/index.ts
DELETED
package/jest.config.js
DELETED
package/src/utils/json-utils.ts
DELETED
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
isPrototypeObject(o: any): boolean {
|
|
3
|
-
return Object.prototype.toString.call(o) === '[object Object]'
|
|
4
|
-
},
|
|
5
|
-
isPrototypeArray(o: any): boolean {
|
|
6
|
-
return Object.prototype.toString.call(o) === '[object Array]'
|
|
7
|
-
},
|
|
8
|
-
isJSONObject(o: any): boolean {
|
|
9
|
-
if (this.isPrototypeObject(o))
|
|
10
|
-
return true
|
|
11
|
-
try {
|
|
12
|
-
return this.isPrototypeObject(JSON.parse(o))
|
|
13
|
-
} catch (e) {
|
|
14
|
-
return false
|
|
15
|
-
}
|
|
16
|
-
},
|
|
17
|
-
isJSONArray(o: any): boolean {
|
|
18
|
-
if (this.isPrototypeArray(o))
|
|
19
|
-
return true
|
|
20
|
-
try {
|
|
21
|
-
return this.isPrototypeArray(JSON.parse(o))
|
|
22
|
-
} catch (e) {
|
|
23
|
-
return false
|
|
24
|
-
}
|
|
25
|
-
},
|
|
26
|
-
toJSONObject<T>(o: any): T {
|
|
27
|
-
if (this.isPrototypeObject(o))
|
|
28
|
-
return <T>o
|
|
29
|
-
return this.isJSONObject(o) ? <T>JSON.parse(o) : <T>{}
|
|
30
|
-
},
|
|
31
|
-
toJSONArray<T>(o: any): T[] {
|
|
32
|
-
if (this.isPrototypeArray(o))
|
|
33
|
-
return <T[]>o
|
|
34
|
-
return this.isJSONArray(o) ? <T[]>JSON.parse(o) : <T[]>[]
|
|
35
|
-
},
|
|
36
|
-
optionalChaining(o: any = {}, chain: string): any {
|
|
37
|
-
const chaining = chain.split('.')
|
|
38
|
-
for (const key of chaining)
|
|
39
|
-
o = o[key] || ''
|
|
40
|
-
return o
|
|
41
|
-
}
|
|
42
|
-
}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
export default {
|
|
2
|
-
// 判断是否数字
|
|
3
|
-
ifNaN(number: any, substitute: any): any {
|
|
4
|
-
return this.isNumber(number) ? +number : substitute
|
|
5
|
-
},
|
|
6
|
-
isNumber(number: any): boolean {
|
|
7
|
-
number = String(number).trim()
|
|
8
|
-
return number !== '' && isFinite(+number) && !isNaN(+number)
|
|
9
|
-
},
|
|
10
|
-
// 增加千分位分隔符
|
|
11
|
-
thousandths(number: any, fixed: number = 2): string {
|
|
12
|
-
if (!this.isNumber(number))
|
|
13
|
-
return ''
|
|
14
|
-
number = (+number).toFixed(fixed)
|
|
15
|
-
return number.replace(/\d+/, (x: string) => {
|
|
16
|
-
return x.replace(/(\d)(?=(\d{3})+$)/g, (y: string) => {
|
|
17
|
-
return y + ','
|
|
18
|
-
})
|
|
19
|
-
})
|
|
20
|
-
},
|
|
21
|
-
summation(array: any[] = []): number {
|
|
22
|
-
return array.reduce((prev, curr) => {
|
|
23
|
-
return prev + this.ifNaN(curr, 0)
|
|
24
|
-
}, 0)
|
|
25
|
-
}
|
|
26
|
-
}
|
package/src/utils/uuid-utils.ts
DELETED
package/tsconfig.json
DELETED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|