qmwts 1.1.65 → 1.1.67

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.
@@ -3,6 +3,7 @@ export default class LocalDate {
3
3
  constructor();
4
4
  constructor(date: Date);
5
5
  static now(): LocalDate;
6
+ static parse(date: string | number): LocalDate;
6
7
  static of(year: number, month: number, date: number): LocalDate;
7
8
  getYear(): number;
8
9
  getMonth(): number;
@@ -3,14 +3,17 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  // https://juejin.cn/post/7098891689955164168
4
4
  class LocalDate {
5
5
  constructor(date) {
6
- if (date == void 0)
7
- this.date = new Date();
8
- else
6
+ if (date instanceof Date)
9
7
  this.date = date;
8
+ else
9
+ this.date = new Date();
10
10
  }
11
11
  static now() {
12
12
  return new LocalDate();
13
13
  }
14
+ static parse(date) {
15
+ return new LocalDate(new Date(date));
16
+ }
14
17
  static of(year, month, date) {
15
18
  return new LocalDate(new Date(year, month - 1, date));
16
19
  }
@@ -1,9 +1,10 @@
1
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
- isBetween(a: number, min: number, max: number): boolean;
7
- isInside(a: number, min: number, max: number): boolean;
2
+ ifNaN(value: any, substitute: any): any;
3
+ isNumber(...values: any[]): boolean;
4
+ thousandths(value: any, fixed?: number): string;
5
+ summation(...values: any[]): number;
6
+ isBetween(value: number, min: number, max: number): boolean;
7
+ isInside(value: number, min: number, max: number): boolean;
8
+ extractNumbers(value: any): string;
8
9
  };
9
10
  export default _default;
@@ -2,42 +2,62 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  // 判断是否数字
5
- ifNaN(number, substitute) {
6
- return this.isNumber(number) ? +number : substitute;
5
+ ifNaN(value, substitute) {
6
+ return this.isNumber(value) ? +value : substitute;
7
7
  },
8
- isNumber(...number) {
9
- for (let i = number.length - 1; i >= 0; i--) {
10
- const e = String(number[i]).trim();
11
- if (e === '' || !isFinite(+e) || isNaN(+e))
8
+ isNumber(...values) {
9
+ for (let i = values.length - 1; i >= 0; i--) {
10
+ const e = String(values[i]).trim();
11
+ if (e === '' || !Number.isFinite(+e) || Number.isNaN(+e))
12
12
  return false;
13
13
  }
14
14
  return true;
15
15
  },
16
16
  // 增加千分位分隔符
17
- thousandths(number, fixed = 2) {
18
- if (!this.isNumber(number))
17
+ thousandths(value, fixed = 2) {
18
+ if (!this.isNumber(value))
19
19
  return '';
20
- number = new Intl.NumberFormat('en-US', {
20
+ value = new Intl.NumberFormat('en-US', {
21
21
  minimumFractionDigits: fixed,
22
22
  maximumFractionDigits: fixed,
23
- }).format(number);
24
- if (+number === 0) // -0转为普通0
23
+ }).format(value);
24
+ if (+value === 0) // -0转为0
25
25
  return (0).toFixed(fixed);
26
- return number;
26
+ return value;
27
27
  },
28
- summation(array = []) {
28
+ summation(...values) {
29
29
  let sum = 0;
30
- for (let i = array.length - 1; i >= 0; i--) {
31
- const e = +array[i];
30
+ const values0 = values.flat(Infinity);
31
+ for (let i = values0.length - 1; i >= 0; i--) {
32
+ const e = +values0[i];
32
33
  if (this.isNumber(e))
33
34
  sum += e;
34
35
  }
35
36
  return sum;
36
37
  },
37
- isBetween(a, min, max) {
38
- return a >= Math.min(min, max) && a <= Math.max(max, min);
38
+ isBetween(value, min, max) {
39
+ return value >= Math.min(min, max) && value <= Math.max(max, min);
39
40
  },
40
- isInside(a, min, max) {
41
- return a > Math.min(min, max) && a < Math.max(max, min);
41
+ isInside(value, min, max) {
42
+ return value > Math.min(min, max) && value < Math.max(max, min);
43
+ },
44
+ extractNumbers(value) {
45
+ const v = String(value);
46
+ let result = '';
47
+ let hasDot = false;
48
+ for (let i = 0; i < v.length; i++) {
49
+ const ch = v[i];
50
+ if (/[0-9]/.test(ch)) {
51
+ result += ch;
52
+ }
53
+ else if (ch === '-' && result === '') { // 负号只能在最前
54
+ result += ch;
55
+ }
56
+ else if (ch === '.' && !hasDot) { // 只能有一个小数点
57
+ result += ch;
58
+ hasDot = true;
59
+ }
60
+ }
61
+ return result;
42
62
  }
43
63
  };
@@ -12,7 +12,7 @@ exports.default = {
12
12
  o = '';
13
13
  }
14
14
  }
15
- if ([void 0, null].includes(o))
15
+ if (o == null)
16
16
  return substitute;
17
17
  return o;
18
18
  },
@@ -6,12 +6,9 @@ exports.default = {
6
6
  if (Array.isArray(value))
7
7
  for (const i of value)
8
8
  params.append(key, i);
9
- else if (isValidValue(value))
9
+ else if (value != null)
10
10
  params.append(key, value);
11
11
  }
12
12
  return params;
13
13
  }
14
14
  };
15
- function isValidValue(value) {
16
- return value !== null && value !== void 0;
17
- }
@@ -2,7 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.default = {
4
4
  trimAll(str) {
5
- if ([void 0, null].includes(str))
5
+ if (str == null)
6
6
  return '';
7
7
  return String(str).split('').map(e => e.trim()).join('');
8
8
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.1.65",
3
+ "version": "1.1.67",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",