qmwts 1.0.4 → 1.0.5

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "qmwts",
3
- "version": "1.0.4",
3
+ "version": "1.0.5",
4
4
  "description": "",
5
5
  "main": "index.ts",
6
6
  "scripts": {
@@ -1,11 +1,11 @@
1
1
  export default {
2
- isPrototypeObject(o: any) {
2
+ isPrototypeObject(o: any): boolean {
3
3
  return Object.prototype.toString.call(o) === '[object Object]'
4
4
  },
5
- isPrototypeArray(o: any) {
5
+ isPrototypeArray(o: any): boolean {
6
6
  return Object.prototype.toString.call(o) === '[object Array]'
7
7
  },
8
- isJSONObject(o: any) {
8
+ isJSONObject(o: any): boolean {
9
9
  if (this.isPrototypeObject(o))
10
10
  return true
11
11
  try {
@@ -14,7 +14,7 @@ export default {
14
14
  return false
15
15
  }
16
16
  },
17
- isJSONArray(o: any) {
17
+ isJSONArray(o: any): boolean {
18
18
  if (this.isPrototypeArray(o))
19
19
  return true
20
20
  try {
@@ -23,17 +23,17 @@ export default {
23
23
  return false
24
24
  }
25
25
  },
26
- toJSONObject(o: any) {
26
+ toJSONObject<T>(o: any): T {
27
27
  if (this.isPrototypeObject(o))
28
28
  return o
29
29
  return this.isJSONObject(o) ? JSON.parse(o) : {}
30
30
  },
31
- toJSONArray(o: any) {
31
+ toJSONArray<T>(o: any): T[] {
32
32
  if (this.isPrototypeArray(o))
33
33
  return o
34
34
  return this.isJSONArray(o) ? JSON.parse(o) : []
35
35
  },
36
- optionalChaining(o: any = {}, chain: string) {
36
+ optionalChaining(o: any = {}, chain: string): any {
37
37
  const chaining = chain.split('.')
38
38
  for (const key of chaining)
39
39
  o = o[key] || ''
@@ -1,14 +1,14 @@
1
1
  export default {
2
2
  // 判断是否数字
3
- ifNaN(number: any, substitute: any) {
3
+ ifNaN(number: any, substitute: any): any {
4
4
  return this.isNumber(number) ? +number : substitute
5
5
  },
6
- isNumber(number: any) {
6
+ isNumber(number: any): boolean {
7
7
  number = String(number).trim()
8
8
  return number !== '' && isFinite(+number) && !isNaN(+number)
9
9
  },
10
10
  // 增加千分位分隔符
11
- thousandths(number: any, fixed: number = 2) {
11
+ thousandths(number: any, fixed: number = 2): string {
12
12
  if (!this.isNumber(number))
13
13
  return ''
14
14
  number = (+number).toFixed(fixed)
@@ -18,7 +18,7 @@ export default {
18
18
  })
19
19
  })
20
20
  },
21
- summation(array: any[] = []) {
21
+ summation(array: any[] = []): number {
22
22
  return array.reduce((prev, curr) => {
23
23
  return prev + this.ifNaN(curr, 0)
24
24
  }, 0)
package/test.js ADDED
@@ -0,0 +1,9 @@
1
+ var Color;
2
+ (function (Color) {
3
+ Color[Color["Red"] = 1] = "Red";
4
+ Color[Color["Y"] = 1] = "Y";
5
+ Color[Color["S"] = 2] = "S";
6
+ })(Color || (Color = {}));
7
+ var c = Color.S;
8
+ console.log(Color.Red);
9
+ console.log(Color.Y);
package/test.ts ADDED
@@ -0,0 +1,11 @@
1
+ enum Color {Red = 1, Y = 1, S}
2
+
3
+ const c = Color.S
4
+ console.log(Color.Red)
5
+ console.log(Color.Y)
6
+
7
+ function a(o: { label?: number }) {
8
+ console.log(o.label)
9
+ }
10
+
11
+ a({})