ayiin 2.0.18 → 2.0.20

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  'use strict';
3
3
 
4
- var version = "2.0.18";
4
+ var version = "2.0.20";
5
5
  var pkg = {
6
6
  version: version};
7
7
 
package/dist/bin/cli.js CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
- var version = "2.0.18";
2
+ var version = "2.0.20";
3
3
  var pkg = {
4
4
  version: version};
5
5
 
@@ -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 @@
2
2
 
3
3
  Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
- var version = "2.0.18";
5
+ var version = "2.0.20";
6
6
  var pkg = {
7
7
  version: version};
8
8
 
@@ -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":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;"}
@@ -1,4 +1,4 @@
1
- var version = "2.0.18";
1
+ var version = "2.0.20";
2
2
  var pkg = {
3
3
  version: version};
4
4
 
@@ -2,7 +2,7 @@ declare class ResponseApi {
2
2
  success: ({ caption, data, code, }: {
3
3
  caption: string;
4
4
  data: any;
5
- code?: number;
5
+ code?: number | string;
6
6
  }) => {
7
7
  responseCode: number;
8
8
  responseSuccess: boolean;
@@ -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;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ayiin",
3
- "version": "2.0.18",
3
+ "version": "2.0.20",
4
4
  "description": "Library Pribadi Yang Gak Ada Isinya",
5
5
  "bin": {
6
6
  "ayiin": "./dist/bin/cli.js"
@@ -14,6 +14,26 @@
14
14
  "require": "./dist/cjs/index.cjs",
15
15
  "import": "./dist/esm/index.js",
16
16
  "types": "./dist/index.d.ts"
17
+ },
18
+ "./methods": {
19
+ "require": "./dist/cjs/methods.cjs",
20
+ "import": "./dist/esm/methods.js",
21
+ "types": "./dist/methods.d.ts"
22
+ },
23
+ "./methods/crypt": {
24
+ "require": "./dist/cjs/methods/crypt.cjs",
25
+ "import": "./dist/esm/methods/crypt.js",
26
+ "types": "./dist/methods/crypt.d.ts"
27
+ },
28
+ "./methods/response": {
29
+ "require": "./dist/cjs/methods/response.cjs",
30
+ "import": "./dist/esm/methods/response.js",
31
+ "types": "./dist/methods/response.d.ts"
32
+ },
33
+ "./methods/tools": {
34
+ "require": "./dist/cjs/methods/tools.cjs",
35
+ "import": "./dist/esm/methods/tools.js",
36
+ "types": "./dist/methods/tools.d.ts"
17
37
  }
18
38
  },
19
39
  "scripts": {