ayiin 2.0.18 → 2.0.19
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/bin/cli.cjs +1 -1
- package/dist/bin/cli.js +1 -1
- package/dist/cjs/methods/tools.cjs +27 -4
- package/dist/cjs/methods/tools.cjs.map +1 -1
- package/dist/cjs/package.json.cjs +1 -1
- package/dist/esm/methods/tools.js +27 -4
- package/dist/esm/methods/tools.js.map +1 -1
- package/dist/esm/package.json.js +1 -1
- package/dist/methods/response.d.ts +1 -1
- package/dist/methods/tools.d.ts +9 -4
- package/package.json +1 -1
package/dist/bin/cli.cjs
CHANGED
package/dist/bin/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ class Tools {
|
|
|
4
4
|
/**
|
|
5
5
|
* Format money ke string sesuai locale
|
|
6
6
|
* @memberof Tools
|
|
7
|
-
* @param {number} amount - jumlah uang
|
|
7
|
+
* @param {number | string} amount - jumlah uang
|
|
8
8
|
* @param {Intl.LocalesArgument} locales - default "id-ID"
|
|
9
9
|
* @param {Intl.NumberFormatOptions} options - default currency IDR
|
|
10
10
|
* @returns {string} string
|
|
@@ -13,7 +13,7 @@ class Tools {
|
|
|
13
13
|
currency: "IDR",
|
|
14
14
|
minimumFractionDigits: 0
|
|
15
15
|
})=>{
|
|
16
|
-
return new Intl.NumberFormat(locales, options).format(amount);
|
|
16
|
+
return new Intl.NumberFormat(locales, options).format(Number(amount));
|
|
17
17
|
};
|
|
18
18
|
/**
|
|
19
19
|
* Generate unique ID dengan pilihan tipe
|
|
@@ -33,7 +33,7 @@ class Tools {
|
|
|
33
33
|
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
34
34
|
}
|
|
35
35
|
let id = "";
|
|
36
|
-
for(let i = 0; i < length; i++){
|
|
36
|
+
for(let i = 0; i < Number(length); i++){
|
|
37
37
|
id += chars[Math.floor(Math.random() * chars.length)];
|
|
38
38
|
}
|
|
39
39
|
return prefix ? prefix + id : id;
|
|
@@ -72,7 +72,7 @@ class Tools {
|
|
|
72
72
|
copy[i]
|
|
73
73
|
];
|
|
74
74
|
}
|
|
75
|
-
return copy.slice(0, count);
|
|
75
|
+
return copy.slice(0, Number(count));
|
|
76
76
|
};
|
|
77
77
|
/**
|
|
78
78
|
* Validasi apakah string adalah email
|
|
@@ -133,6 +133,29 @@ class Tools {
|
|
|
133
133
|
if (!input) return "";
|
|
134
134
|
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
135
135
|
};
|
|
136
|
+
slugify = (str)=>{
|
|
137
|
+
return str.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "");
|
|
138
|
+
};
|
|
139
|
+
deepClone = (obj)=>{
|
|
140
|
+
return JSON.parse(JSON.stringify(obj));
|
|
141
|
+
};
|
|
142
|
+
isEmptyObject = (obj)=>{
|
|
143
|
+
return Object.keys(obj).length === 0;
|
|
144
|
+
};
|
|
145
|
+
sleep = (ms)=>{
|
|
146
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
147
|
+
};
|
|
148
|
+
retry = async (fn, retries = 3)=>{
|
|
149
|
+
let error;
|
|
150
|
+
for(let i = 0; i < retries; i++){
|
|
151
|
+
try {
|
|
152
|
+
return await fn();
|
|
153
|
+
} catch (err) {
|
|
154
|
+
error = err;
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
throw error;
|
|
158
|
+
};
|
|
136
159
|
}
|
|
137
160
|
|
|
138
161
|
module.exports = Tools;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.cjs","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
|
@@ -2,7 +2,7 @@ class Tools {
|
|
|
2
2
|
/**
|
|
3
3
|
* Format money ke string sesuai locale
|
|
4
4
|
* @memberof Tools
|
|
5
|
-
* @param {number} amount - jumlah uang
|
|
5
|
+
* @param {number | string} amount - jumlah uang
|
|
6
6
|
* @param {Intl.LocalesArgument} locales - default "id-ID"
|
|
7
7
|
* @param {Intl.NumberFormatOptions} options - default currency IDR
|
|
8
8
|
* @returns {string} string
|
|
@@ -11,7 +11,7 @@ class Tools {
|
|
|
11
11
|
currency: "IDR",
|
|
12
12
|
minimumFractionDigits: 0
|
|
13
13
|
})=>{
|
|
14
|
-
return new Intl.NumberFormat(locales, options).format(amount);
|
|
14
|
+
return new Intl.NumberFormat(locales, options).format(Number(amount));
|
|
15
15
|
};
|
|
16
16
|
/**
|
|
17
17
|
* Generate unique ID dengan pilihan tipe
|
|
@@ -31,7 +31,7 @@ class Tools {
|
|
|
31
31
|
chars = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
|
|
32
32
|
}
|
|
33
33
|
let id = "";
|
|
34
|
-
for(let i = 0; i < length; i++){
|
|
34
|
+
for(let i = 0; i < Number(length); i++){
|
|
35
35
|
id += chars[Math.floor(Math.random() * chars.length)];
|
|
36
36
|
}
|
|
37
37
|
return prefix ? prefix + id : id;
|
|
@@ -70,7 +70,7 @@ class Tools {
|
|
|
70
70
|
copy[i]
|
|
71
71
|
];
|
|
72
72
|
}
|
|
73
|
-
return copy.slice(0, count);
|
|
73
|
+
return copy.slice(0, Number(count));
|
|
74
74
|
};
|
|
75
75
|
/**
|
|
76
76
|
* Validasi apakah string adalah email
|
|
@@ -131,6 +131,29 @@ class Tools {
|
|
|
131
131
|
if (!input) return "";
|
|
132
132
|
return input.charAt(0).toUpperCase() + input.slice(1);
|
|
133
133
|
};
|
|
134
|
+
slugify = (str)=>{
|
|
135
|
+
return str.toLowerCase().replace(/\s+/g, "-").replace(/[^\w-]+/g, "");
|
|
136
|
+
};
|
|
137
|
+
deepClone = (obj)=>{
|
|
138
|
+
return JSON.parse(JSON.stringify(obj));
|
|
139
|
+
};
|
|
140
|
+
isEmptyObject = (obj)=>{
|
|
141
|
+
return Object.keys(obj).length === 0;
|
|
142
|
+
};
|
|
143
|
+
sleep = (ms)=>{
|
|
144
|
+
return new Promise((resolve)=>setTimeout(resolve, ms));
|
|
145
|
+
};
|
|
146
|
+
retry = async (fn, retries = 3)=>{
|
|
147
|
+
let error;
|
|
148
|
+
for(let i = 0; i < retries; i++){
|
|
149
|
+
try {
|
|
150
|
+
return await fn();
|
|
151
|
+
} catch (err) {
|
|
152
|
+
error = err;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
throw error;
|
|
156
|
+
};
|
|
134
157
|
}
|
|
135
158
|
|
|
136
159
|
export { Tools as default };
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"tools.js","sources":[],"sourcesContent":[],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"tools.js","sources":[],"sourcesContent":[],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
|
package/dist/esm/package.json.js
CHANGED
package/dist/methods/tools.d.ts
CHANGED
|
@@ -2,12 +2,12 @@ declare class Tools {
|
|
|
2
2
|
/**
|
|
3
3
|
* Format money ke string sesuai locale
|
|
4
4
|
* @memberof Tools
|
|
5
|
-
* @param {number} amount - jumlah uang
|
|
5
|
+
* @param {number | string} amount - jumlah uang
|
|
6
6
|
* @param {Intl.LocalesArgument} locales - default "id-ID"
|
|
7
7
|
* @param {Intl.NumberFormatOptions} options - default currency IDR
|
|
8
8
|
* @returns {string} string
|
|
9
9
|
*/
|
|
10
|
-
formatMoney: (amount: number, locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions) => string;
|
|
10
|
+
formatMoney: (amount: number | string, locales?: Intl.LocalesArgument, options?: Intl.NumberFormatOptions) => string;
|
|
11
11
|
/**
|
|
12
12
|
* Generate unique ID dengan pilihan tipe
|
|
13
13
|
* @param {"number"|"string"|"mixed"} type - tipe ID (angka, string, atau campuran)
|
|
@@ -16,7 +16,7 @@ declare class Tools {
|
|
|
16
16
|
*/
|
|
17
17
|
uniqueId: ({ type, length, prefix, }: {
|
|
18
18
|
type?: "number" | "string" | "mixed";
|
|
19
|
-
length?: number;
|
|
19
|
+
length?: number | string;
|
|
20
20
|
prefix?: string;
|
|
21
21
|
}) => string;
|
|
22
22
|
/**
|
|
@@ -37,7 +37,7 @@ declare class Tools {
|
|
|
37
37
|
* @param {number} count - jumlah item
|
|
38
38
|
* @returns {T[]} array item acak unik dari array
|
|
39
39
|
*/
|
|
40
|
-
randomMany: <T>(array: T[], count: number) => T[];
|
|
40
|
+
randomMany: <T>(array: T[], count: number | string) => T[];
|
|
41
41
|
/**
|
|
42
42
|
* Validasi apakah string adalah email
|
|
43
43
|
* @param {string} str
|
|
@@ -75,5 +75,10 @@ declare class Tools {
|
|
|
75
75
|
* @returns {string} string dengan huruf pertama kapital
|
|
76
76
|
*/
|
|
77
77
|
capitalize: (input: string) => string;
|
|
78
|
+
slugify: (str: string) => string;
|
|
79
|
+
deepClone: <T>(obj: T) => T;
|
|
80
|
+
isEmptyObject: (obj: object) => boolean;
|
|
81
|
+
sleep: (ms: number) => Promise<void>;
|
|
82
|
+
retry: <T>(fn: () => Promise<T>, retries?: number) => Promise<T>;
|
|
78
83
|
}
|
|
79
84
|
export default Tools;
|