qmwts 1.0.8 → 1.0.9

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.
@@ -0,0 +1,4 @@
1
+ import NumberUtils from './src/utils/number-utils';
2
+ import JsonUtils from './src/utils/json-utils';
3
+ import UUIDUtils from './src/utils/uuid-utils';
4
+ export { NumberUtils, JsonUtils, UUIDUtils };
package/dist/index.js ADDED
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.UUIDUtils = exports.JsonUtils = exports.NumberUtils = void 0;
4
+ // https://www.jianshu.com/p/8fa2c50720e4
5
+ var number_utils_1 = require("./src/utils/number-utils");
6
+ exports.NumberUtils = number_utils_1.default;
7
+ var json_utils_1 = require("./src/utils/json-utils");
8
+ exports.JsonUtils = json_utils_1.default;
9
+ var uuid_utils_1 = require("./src/utils/uuid-utils");
10
+ exports.UUIDUtils = uuid_utils_1.default;
@@ -0,0 +1,10 @@
1
+ declare const _default: {
2
+ isPrototypeObject(o: any): boolean;
3
+ isPrototypeArray(o: any): boolean;
4
+ isJSONObject(o: any): boolean;
5
+ isJSONArray(o: any): boolean;
6
+ toJSONObject<T>(o: any): T;
7
+ toJSONArray<T_1>(o: any): T_1[];
8
+ optionalChaining(o: any, chain: string): any;
9
+ };
10
+ export default _default;
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ isPrototypeObject: function (o) {
5
+ return Object.prototype.toString.call(o) === '[object Object]';
6
+ },
7
+ isPrototypeArray: function (o) {
8
+ return Object.prototype.toString.call(o) === '[object Array]';
9
+ },
10
+ isJSONObject: function (o) {
11
+ if (this.isPrototypeObject(o))
12
+ return true;
13
+ try {
14
+ return this.isPrototypeObject(JSON.parse(o));
15
+ }
16
+ catch (e) {
17
+ return false;
18
+ }
19
+ },
20
+ isJSONArray: function (o) {
21
+ if (this.isPrototypeArray(o))
22
+ return true;
23
+ try {
24
+ return this.isPrototypeArray(JSON.parse(o));
25
+ }
26
+ catch (e) {
27
+ return false;
28
+ }
29
+ },
30
+ toJSONObject: function (o) {
31
+ if (this.isPrototypeObject(o))
32
+ return o;
33
+ return this.isJSONObject(o) ? JSON.parse(o) : {};
34
+ },
35
+ toJSONArray: function (o) {
36
+ if (this.isPrototypeArray(o))
37
+ return o;
38
+ return this.isJSONArray(o) ? JSON.parse(o) : [];
39
+ },
40
+ optionalChaining: function (o, chain) {
41
+ if (o === void 0) { o = {}; }
42
+ var chaining = chain.split('.');
43
+ for (var _i = 0, chaining_1 = chaining; _i < chaining_1.length; _i++) {
44
+ var key = chaining_1[_i];
45
+ o = o[key] || '';
46
+ }
47
+ return o;
48
+ }
49
+ };
@@ -0,0 +1,7 @@
1
+ declare const _default: {
2
+ ifNaN(number: any, substitute: any): any;
3
+ isNumber(number: any): boolean;
4
+ thousandths(number: any, fixed?: number): string;
5
+ summation(array?: any[]): number;
6
+ };
7
+ export default _default;
@@ -0,0 +1,31 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ // 判断是否数字
5
+ ifNaN: function (number, substitute) {
6
+ return this.isNumber(number) ? +number : substitute;
7
+ },
8
+ isNumber: function (number) {
9
+ number = String(number).trim();
10
+ return number !== '' && isFinite(+number) && !isNaN(+number);
11
+ },
12
+ // 增加千分位分隔符
13
+ thousandths: function (number, fixed) {
14
+ if (fixed === void 0) { fixed = 2; }
15
+ if (!this.isNumber(number))
16
+ return '';
17
+ number = (+number).toFixed(fixed);
18
+ return number.replace(/\d+/, function (x) {
19
+ return x.replace(/(\d)(?=(\d{3})+$)/g, function (y) {
20
+ return y + ',';
21
+ });
22
+ });
23
+ },
24
+ summation: function (array) {
25
+ var _this = this;
26
+ if (array === void 0) { array = []; }
27
+ return array.reduce(function (prev, curr) {
28
+ return prev + _this.ifNaN(curr, 0);
29
+ }, 0);
30
+ }
31
+ };
@@ -0,0 +1,4 @@
1
+ declare const _default: {
2
+ uuid(): string;
3
+ };
4
+ export default _default;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
4
+ uuid: function () {
5
+ return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(/[xy]/g, function (c) {
6
+ var r = (Math.random() * 16) | 0;
7
+ var v = c === 'x' ? r : (r & 0x3) | 0x8;
8
+ return v.toString(16);
9
+ });
10
+ }
11
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.0.8",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "index.js",
6
6
  "scripts": {