@jiakun-zhao/utils 1.2.0 → 1.2.1

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.cjs CHANGED
@@ -16,10 +16,6 @@ function safe(fn) {
16
16
  }
17
17
  }
18
18
 
19
- function random(max, min = 0) {
20
- return Math.floor(Math.random() * max) + min;
21
- }
22
-
23
19
  const colors = {
24
20
  /** 重置颜色 */
25
21
  reset: "\x1B[0m",
@@ -83,7 +79,18 @@ function print(msg, type) {
83
79
 
84
80
  const timestamp = () => +Date.now();
85
81
  const isArray = Array.isArray;
82
+ function getValueOrUndefined(condition, value) {
83
+ return condition ? value : void 0;
84
+ }
85
+ function cleanString(str, regexp) {
86
+ return str.replace(regexp, "");
87
+ }
88
+ function random(max, min = 0) {
89
+ return Math.floor(Math.random() * max) + min;
90
+ }
86
91
 
92
+ exports.cleanString = cleanString;
93
+ exports.getValueOrUndefined = getValueOrUndefined;
87
94
  exports.isArray = isArray;
88
95
  exports.print = print;
89
96
  exports.random = random;
package/dist/index.d.cts CHANGED
@@ -5,11 +5,6 @@ declare function singleOrNull<T>(arr: T[]): T | null;
5
5
  declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
6
6
  declare function safe<R>(fn: () => R): R | undefined;
7
7
 
8
- /**
9
- * @description min <= result < max
10
- */
11
- declare function random(max: number, min?: number): number;
12
-
13
8
  declare const map: {
14
9
  info: {
15
10
  color: string;
@@ -36,5 +31,11 @@ declare function print(msg: any, type?: keyof typeof map): void;
36
31
 
37
32
  declare const timestamp: () => number;
38
33
  declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
39
40
 
40
- export { isArray, print, random, safe, singleOrNull, timestamp, transform };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.d.mts CHANGED
@@ -5,11 +5,6 @@ declare function singleOrNull<T>(arr: T[]): T | null;
5
5
  declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
6
6
  declare function safe<R>(fn: () => R): R | undefined;
7
7
 
8
- /**
9
- * @description min <= result < max
10
- */
11
- declare function random(max: number, min?: number): number;
12
-
13
8
  declare const map: {
14
9
  info: {
15
10
  color: string;
@@ -36,5 +31,11 @@ declare function print(msg: any, type?: keyof typeof map): void;
36
31
 
37
32
  declare const timestamp: () => number;
38
33
  declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
39
40
 
40
- export { isArray, print, random, safe, singleOrNull, timestamp, transform };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.d.ts CHANGED
@@ -5,11 +5,6 @@ declare function singleOrNull<T>(arr: T[]): T | null;
5
5
  declare function transform<T, R = void>(value: T, fn: (it: T) => R): R;
6
6
  declare function safe<R>(fn: () => R): R | undefined;
7
7
 
8
- /**
9
- * @description min <= result < max
10
- */
11
- declare function random(max: number, min?: number): number;
12
-
13
8
  declare const map: {
14
9
  info: {
15
10
  color: string;
@@ -36,5 +31,11 @@ declare function print(msg: any, type?: keyof typeof map): void;
36
31
 
37
32
  declare const timestamp: () => number;
38
33
  declare const isArray: (arg: any) => arg is any[];
34
+ declare function getValueOrUndefined<T>(condition: unknown, value: T): T | undefined;
35
+ declare function cleanString(str: string, regexp: RegExp): string;
36
+ /**
37
+ * @description min <= result < max
38
+ */
39
+ declare function random(max: number, min?: number): number;
39
40
 
40
- export { isArray, print, random, safe, singleOrNull, timestamp, transform };
41
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/dist/index.mjs CHANGED
@@ -14,10 +14,6 @@ function safe(fn) {
14
14
  }
15
15
  }
16
16
 
17
- function random(max, min = 0) {
18
- return Math.floor(Math.random() * max) + min;
19
- }
20
-
21
17
  const colors = {
22
18
  /** 重置颜色 */
23
19
  reset: "\x1B[0m",
@@ -81,5 +77,14 @@ function print(msg, type) {
81
77
 
82
78
  const timestamp = () => +Date.now();
83
79
  const isArray = Array.isArray;
80
+ function getValueOrUndefined(condition, value) {
81
+ return condition ? value : void 0;
82
+ }
83
+ function cleanString(str, regexp) {
84
+ return str.replace(regexp, "");
85
+ }
86
+ function random(max, min = 0) {
87
+ return Math.floor(Math.random() * max) + min;
88
+ }
84
89
 
85
- export { isArray, print, random, safe, singleOrNull, timestamp, transform };
90
+ export { cleanString, getValueOrUndefined, isArray, print, random, safe, singleOrNull, timestamp, transform };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@jiakun-zhao/utils",
3
3
  "type": "module",
4
- "version": "1.2.0",
4
+ "version": "1.2.1",
5
5
  "description": "Utils.",
6
6
  "author": "Jiakun Zhao <hi@zhaojiakun.com>",
7
7
  "license": "MIT",