clear-af.js 1.0.1 → 1.0.3

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/README.md CHANGED
@@ -4,6 +4,8 @@ A JavaScript package packed with utilities to make your code **readable af**. Be
4
4
 
5
5
  📖 **Languages** : [🇬🇧 English](#) | [🇫🇷 Français](README_FR.md)
6
6
 
7
+ 📚 **[Full Documentation](https://froostdev.github.io/clear-af.js/)**
8
+
7
9
  ---
8
10
 
9
11
  ## 📦 Installation
package/dist/index.d.ts CHANGED
@@ -6,48 +6,94 @@
6
6
  declare function getDate(time?: boolean): string;
7
7
  /**
8
8
  * Show a pretty error log message with optional date information
9
+ * @category Logging
9
10
  * @function prettyError
10
11
  * @param err - Error message to display
11
12
  * @param time - Include or not a timestamp
13
+ * @example
14
+ * prettyError("Database connection failed");
15
+ * // Output: ✕ - Database connection failed (in red)
16
+ *
17
+ * prettyError("Critical error", true);
18
+ * // Output: ✕ [30/03/2026 10:30:45] - Critical error (in red with timestamp)
12
19
  */
13
20
  declare function prettyError(err: string, time?: boolean): void;
14
21
  /**
15
22
  * Show a pretty warn log message with optional date information
23
+ * @category Logging
16
24
  * @function prettyWarn
17
25
  * @param warn - Warning message to display
18
26
  * @param time - Include or not a timestamp
27
+ * @example
28
+ * prettyWarn("Deprecated function used");
29
+ * // Output: ⚠ - Deprecated function used (in orange)
30
+ *
31
+ * prettyWarn("Low memory", true);
32
+ * // Output: ⚠ [30/03/2026 10:30:45] - Low memory (in orange with timestamp)
19
33
  */
20
34
  declare function prettyWarn(warn: string, time?: boolean): void;
21
35
  /**
22
36
  * Show a pretty success log message with optional date information
37
+ * @category Logging
23
38
  * @function prettySuccess
24
39
  * @param success - Success message to display
25
40
  * @param time - Include or not a timestamp
41
+ * @example
42
+ * prettySuccess("User created successfully");
43
+ * // Output: ✔ - User created successfully (in green)
44
+ *
45
+ * prettySuccess("Data saved", true);
46
+ * // Output: ✔ [30/03/2026 10:30:45] - Data saved (in green with timestamp)
26
47
  */
27
48
  declare function prettySuccess(success: string, time?: boolean): void;
28
49
  /**
29
50
  * Show a pretty information log message with optional date information
51
+ * @category Logging
30
52
  * @function prettyInfo
31
53
  * @param info - Information message to display
32
54
  * @param time - Include or not a timestamp
55
+ * @example
56
+ * prettyInfo("Server is running on port 3000");
57
+ * // Output: ℹ - Server is running on port 3000 (in blue)
58
+ *
59
+ * prettyInfo("Cache cleared", true);
60
+ * // Output: ℹ [30/03/2026 10:30:45] - Cache cleared (in blue with timestamp)
33
61
  */
34
62
  declare function prettyInfo(info: string, time?: boolean): void;
35
63
  /**
36
64
  * Show a pretty debug log message with optional date information
65
+ * @category Logging
37
66
  * @function prettyDebug
38
67
  * @param debug - Debug message to display
39
68
  * @param time - Include or not a timestamp
69
+ * @example
70
+ * prettyDebug("Variable x = 42");
71
+ * // Output: ⚙ - Variable x = 42 (in white)
72
+ *
73
+ * prettyDebug("Function call trace", true);
74
+ * // Output: ⚙ [30/03/2026 10:30:45] - Function call trace (in white with timestamp)
40
75
  */
41
76
  declare function prettyDebug(debug: string, time?: boolean): void;
42
77
  /**
43
78
  * Show a separator line in console
79
+ * @category Logging
44
80
  * @function logSeparator
81
+ * @example
82
+ * logSeparator();
83
+ * // Output: ══════════════════════════════════════════════════
45
84
  */
46
85
  declare function logSeparator(): void;
47
86
  /**
48
87
  * Display a header with a title in the center
88
+ * @category Logging
49
89
  * @function logHeader
50
90
  * @param title - The title of the header
91
+ * @example
92
+ * logHeader("Welcome");
93
+ * // Output:
94
+ * // ╔═════════╗
95
+ * // ║ Welcome ║
96
+ * // ╚═════════╝
51
97
  */
52
98
  declare function logHeader(title: string): void;
53
99
  /**
@@ -57,31 +103,58 @@ declare function logHeader(title: string): void;
57
103
  */
58
104
  /**
59
105
  * Check if any type of variable is empty
106
+ * @category Validation
60
107
  * @function isEmpty
61
108
  * @param value - The variable to check
62
109
  * @returns {boolean} True if the value is empty, false otherwise
110
+ * @example
111
+ * isEmpty(""); // true
112
+ * isEmpty(" "); // true
113
+ * isEmpty(null); // true
114
+ * isEmpty([]); // true
115
+ * isEmpty({}); // true
116
+ * isEmpty("hello"); // false
117
+ * isEmpty([1, 2]); // false
63
118
  */
64
119
  declare function isEmpty(value: unknown): boolean;
65
120
  /**
66
121
  * Check if the variable is of the chosen type
122
+ * @category Validation
67
123
  * @function isType
68
124
  * @param value - The variable to check
69
125
  * @param type - The type you want
70
126
  * @returns {boolean} True if the value is of the chosen type, false otherwise
127
+ * @example
128
+ * isType("hello", "string"); // true
129
+ * isType(42, "number"); // true
130
+ * isType([], "object"); // true
131
+ * isType("42", "number"); // false
71
132
  */
72
133
  declare function isType(value: unknown, type: string): boolean;
73
134
  /**
74
135
  * Check if an email is valid
136
+ * @category Validation
75
137
  * @function isEmail
76
138
  * @param email - The email to check
77
139
  * @returns {boolean} True if the email is valid, false otherwise
140
+ * @example
141
+ * isEmail("alice@example.com"); // true
142
+ * isEmail("bob.smith@company.co.uk"); // true
143
+ * isEmail("invalid@.com"); // false
144
+ * isEmail("no-at-sign.com"); // false
78
145
  */
79
146
  declare function isEmail(email: string): boolean;
80
147
  /**
81
148
  * Check if a URL is valid
149
+ * @category Validation
82
150
  * @function isURL
83
151
  * @param url - The URL to check
84
152
  * @returns {boolean} True if the URL is valid, false otherwise
153
+ * @example
154
+ * isURL("https://www.example.com"); // true
155
+ * isURL("http://example.com/path"); // true
156
+ * isURL("www.example.com"); // false (missing protocol)
157
+ * isURL("not a url"); // false
85
158
  */
86
159
  declare function isURL(url: string): boolean;
87
160
  /**
@@ -91,49 +164,82 @@ declare function isURL(url: string): boolean;
91
164
  */
92
165
  /**
93
166
  * Create a deep clone of any object or array
167
+ * @category Object Manipulation
94
168
  * @function deepClone
95
169
  * @param obj - The object or array to clone
96
170
  * @returns A deep clone of the object
171
+ * @example
172
+ * const user = { name: "Alice", skills: ["JS", "TS"] };
173
+ * const clone = deepClone(user);
174
+ * clone.name = "Bob";
175
+ * clone.skills[0] = "Python";
176
+ * console.log(user.name); // "Alice" (unchanged)
177
+ * console.log(user.skills[0]); // "JS" (unchanged)
97
178
  */
98
179
  declare function deepClone<T>(obj: T): T;
99
180
  /**
100
181
  * Remove duplicate values from an array
182
+ * @category Object Manipulation
101
183
  * @function noTwins
102
184
  * @param arr - The array to remove duplicates from
103
185
  * @returns {unknown[]} A new array with unique values only
186
+ * @example
187
+ * noTwins([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
188
+ * noTwins(["a", "b", "a", "c"]); // ["a", "b", "c"]
189
+ * noTwins([1, "1", 1, "1"]); // [1, "1"]
104
190
  */
105
191
  declare function noTwins(arr: unknown[]): unknown[];
106
192
  /**
107
193
  *
108
- * Transforamtion utilites
194
+ * Transformation utilites
109
195
  *
110
196
  */
111
197
  /**
112
198
  * Transform a string to camelCase format
199
+ * @category Transformation
113
200
  * @function camelify
114
201
  * @param str - The string to transform
115
202
  * @returns {string} The string in camelCase format
203
+ * @example
204
+ * camelify("hello world"); // "helloWorld"
205
+ * camelify("C'est un test"); // "cestUnTest"
206
+ * camelify("foo bar baz"); // "fooBarBaz"
116
207
  */
117
208
  declare function camelify(str: string): string;
118
209
  /**
119
210
  * Transform a string to kebab-case format
211
+ * @category Transformation
120
212
  * @function kebabify
121
213
  * @param str - The string to transform
122
214
  * @returns {string} The string in kebab-case format
215
+ * @example
216
+ * kebabify("hello world"); // "hello-world"
217
+ * kebabify("C'est un test"); // "ceststun-test"
218
+ * kebabify("foo bar baz"); // "foo-bar-baz"
123
219
  */
124
220
  declare function kebabify(str: string): string;
125
221
  /**
126
222
  * Transform a string to snake_case format
223
+ * @category Transformation
127
224
  * @function snakify
128
225
  * @param str - The string to transform
129
226
  * @returns {string} The string in snake_case format
227
+ * @example
228
+ * snakify("hello world"); // "hello_world"
229
+ * snakify("C'est un test"); // "ceststun_test"
230
+ * snakify("foo bar baz"); // "foo_bar_baz"
130
231
  */
131
232
  declare function snakify(str: string): string;
132
233
  /**
133
234
  * Capitalize the first character of a string
235
+ * @category Transformation
134
236
  * @function capitalize
135
237
  * @param str - The string to capitalize
136
238
  * @returns {string} The string with the first character in uppercase
239
+ * @example
240
+ * capitalize("hello"); // "Hello"
241
+ * capitalize("hello world"); // "Hello world"
242
+ * capitalize(""); // ""
137
243
  */
138
244
  declare function capitalize(str: string): string;
139
245
  export { getDate, prettyError, prettyWarn, prettySuccess, prettyInfo, prettyDebug, logSeparator, logHeader, isEmpty, isType, isEmail, isURL, deepClone, noTwins, camelify, kebabify, snakify, capitalize };
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA;;;;GAIG;AACH,iBAAS,OAAO,CAAC,IAAI,GAAE,OAAe,GAAG,MAAM,CAE9C;AAQD;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;GAKG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;GAKG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAG1D;AAED;;;;;GAKG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;GAKG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGtD;AAED;;;GAGG;AACH,iBAAS,YAAY,IAAI,IAAI,CAE5B;AAED;;;;GAIG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAItC;AAED;;;;GAIG;AAEH;;;;;GAKG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMxC;AAED;;;;;;GAMG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EA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G,EAAE,MAAM,GAAG,MAAM,CASrC;AAED;;;;;;;;;;GAUG;AACH,iBAAS,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CASpC;AAED;;;;;;;;;;GAUG;AACH,iBAAS,UAAU,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAGvC;AAKD,OAAO,EACH,OAAO,EACP,WAAW,EACX,UAAU,EACV,aAAa,EACb,UAAU,EACV,WAAW,EACX,YAAY,EACZ,SAAS,EACT,OAAO,EACP,MAAM,EACN,OAAO,EACP,KAAK,EACL,SAAS,EACT,OAAO,EACP,QAAQ,EACR,QAAQ,EACR,OAAO,EACP,UAAU,EACb,CAAC"}
package/dist/index.js CHANGED
@@ -41,9 +41,16 @@ function getDate(time = false) {
41
41
  */
42
42
  /**
43
43
  * Show a pretty error log message with optional date information
44
+ * @category Logging
44
45
  * @function prettyError
45
46
  * @param err - Error message to display
46
47
  * @param time - Include or not a timestamp
48
+ * @example
49
+ * prettyError("Database connection failed");
50
+ * // Output: ✕ - Database connection failed (in red)
51
+ *
52
+ * prettyError("Critical error", true);
53
+ * // Output: ✕ [30/03/2026 10:30:45] - Critical error (in red with timestamp)
47
54
  */
48
55
  function prettyError(err, time = false) {
49
56
  const date = getDate(time);
@@ -51,9 +58,16 @@ function prettyError(err, time = false) {
51
58
  }
52
59
  /**
53
60
  * Show a pretty warn log message with optional date information
61
+ * @category Logging
54
62
  * @function prettyWarn
55
63
  * @param warn - Warning message to display
56
64
  * @param time - Include or not a timestamp
65
+ * @example
66
+ * prettyWarn("Deprecated function used");
67
+ * // Output: ⚠ - Deprecated function used (in orange)
68
+ *
69
+ * prettyWarn("Low memory", true);
70
+ * // Output: ⚠ [30/03/2026 10:30:45] - Low memory (in orange with timestamp)
57
71
  */
58
72
  function prettyWarn(warn, time = false) {
59
73
  const date = getDate(time);
@@ -61,9 +75,16 @@ function prettyWarn(warn, time = false) {
61
75
  }
62
76
  /**
63
77
  * Show a pretty success log message with optional date information
78
+ * @category Logging
64
79
  * @function prettySuccess
65
80
  * @param success - Success message to display
66
81
  * @param time - Include or not a timestamp
82
+ * @example
83
+ * prettySuccess("User created successfully");
84
+ * // Output: ✔ - User created successfully (in green)
85
+ *
86
+ * prettySuccess("Data saved", true);
87
+ * // Output: ✔ [30/03/2026 10:30:45] - Data saved (in green with timestamp)
67
88
  */
68
89
  function prettySuccess(success, time = false) {
69
90
  const date = getDate(time);
@@ -71,9 +92,16 @@ function prettySuccess(success, time = false) {
71
92
  }
72
93
  /**
73
94
  * Show a pretty information log message with optional date information
95
+ * @category Logging
74
96
  * @function prettyInfo
75
97
  * @param info - Information message to display
76
98
  * @param time - Include or not a timestamp
99
+ * @example
100
+ * prettyInfo("Server is running on port 3000");
101
+ * // Output: ℹ - Server is running on port 3000 (in blue)
102
+ *
103
+ * prettyInfo("Cache cleared", true);
104
+ * // Output: ℹ [30/03/2026 10:30:45] - Cache cleared (in blue with timestamp)
77
105
  */
78
106
  function prettyInfo(info, time = false) {
79
107
  const date = getDate(time);
@@ -81,9 +109,16 @@ function prettyInfo(info, time = false) {
81
109
  }
82
110
  /**
83
111
  * Show a pretty debug log message with optional date information
112
+ * @category Logging
84
113
  * @function prettyDebug
85
114
  * @param debug - Debug message to display
86
115
  * @param time - Include or not a timestamp
116
+ * @example
117
+ * prettyDebug("Variable x = 42");
118
+ * // Output: ⚙ - Variable x = 42 (in white)
119
+ *
120
+ * prettyDebug("Function call trace", true);
121
+ * // Output: ⚙ [30/03/2026 10:30:45] - Function call trace (in white with timestamp)
87
122
  */
88
123
  function prettyDebug(debug, time = false) {
89
124
  const date = getDate(time);
@@ -91,15 +126,26 @@ function prettyDebug(debug, time = false) {
91
126
  }
92
127
  /**
93
128
  * Show a separator line in console
129
+ * @category Logging
94
130
  * @function logSeparator
131
+ * @example
132
+ * logSeparator();
133
+ * // Output: ══════════════════════════════════════════════════
95
134
  */
96
135
  function logSeparator() {
97
136
  console.log(`\x1b[1m${'═'.repeat(50)}\x1b[0m`);
98
137
  }
99
138
  /**
100
139
  * Display a header with a title in the center
140
+ * @category Logging
101
141
  * @function logHeader
102
142
  * @param title - The title of the header
143
+ * @example
144
+ * logHeader("Welcome");
145
+ * // Output:
146
+ * // ╔═════════╗
147
+ * // ║ Welcome ║
148
+ * // ╚═════════╝
103
149
  */
104
150
  function logHeader(title) {
105
151
  console.log(`\x1b[1m╔${'═'.repeat(title.length + 2)}╗\x1b[0m`);
@@ -113,9 +159,18 @@ function logHeader(title) {
113
159
  */
114
160
  /**
115
161
  * Check if any type of variable is empty
162
+ * @category Validation
116
163
  * @function isEmpty
117
164
  * @param value - The variable to check
118
165
  * @returns {boolean} True if the value is empty, false otherwise
166
+ * @example
167
+ * isEmpty(""); // true
168
+ * isEmpty(" "); // true
169
+ * isEmpty(null); // true
170
+ * isEmpty([]); // true
171
+ * isEmpty({}); // true
172
+ * isEmpty("hello"); // false
173
+ * isEmpty([1, 2]); // false
119
174
  */
120
175
  function isEmpty(value) {
121
176
  if (value === null || value === undefined)
@@ -130,19 +185,31 @@ function isEmpty(value) {
130
185
  }
131
186
  /**
132
187
  * Check if the variable is of the chosen type
188
+ * @category Validation
133
189
  * @function isType
134
190
  * @param value - The variable to check
135
191
  * @param type - The type you want
136
192
  * @returns {boolean} True if the value is of the chosen type, false otherwise
193
+ * @example
194
+ * isType("hello", "string"); // true
195
+ * isType(42, "number"); // true
196
+ * isType([], "object"); // true
197
+ * isType("42", "number"); // false
137
198
  */
138
199
  function isType(value, type) {
139
200
  return typeof value === type;
140
201
  }
141
202
  /**
142
203
  * Check if an email is valid
204
+ * @category Validation
143
205
  * @function isEmail
144
206
  * @param email - The email to check
145
207
  * @returns {boolean} True if the email is valid, false otherwise
208
+ * @example
209
+ * isEmail("alice@example.com"); // true
210
+ * isEmail("bob.smith@company.co.uk"); // true
211
+ * isEmail("invalid@.com"); // false
212
+ * isEmail("no-at-sign.com"); // false
146
213
  */
147
214
  function isEmail(email) {
148
215
  const regex = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
@@ -150,9 +217,15 @@ function isEmail(email) {
150
217
  }
151
218
  /**
152
219
  * Check if a URL is valid
220
+ * @category Validation
153
221
  * @function isURL
154
222
  * @param url - The URL to check
155
223
  * @returns {boolean} True if the URL is valid, false otherwise
224
+ * @example
225
+ * isURL("https://www.example.com"); // true
226
+ * isURL("http://example.com/path"); // true
227
+ * isURL("www.example.com"); // false (missing protocol)
228
+ * isURL("not a url"); // false
156
229
  */
157
230
  function isURL(url) {
158
231
  try {
@@ -170,9 +243,17 @@ function isURL(url) {
170
243
  */
171
244
  /**
172
245
  * Create a deep clone of any object or array
246
+ * @category Object Manipulation
173
247
  * @function deepClone
174
248
  * @param obj - The object or array to clone
175
249
  * @returns A deep clone of the object
250
+ * @example
251
+ * const user = { name: "Alice", skills: ["JS", "TS"] };
252
+ * const clone = deepClone(user);
253
+ * clone.name = "Bob";
254
+ * clone.skills[0] = "Python";
255
+ * console.log(user.name); // "Alice" (unchanged)
256
+ * console.log(user.skills[0]); // "JS" (unchanged)
176
257
  */
177
258
  function deepClone(obj) {
178
259
  if (obj === null || typeof obj !== "object")
@@ -188,23 +269,33 @@ function deepClone(obj) {
188
269
  }
189
270
  /**
190
271
  * Remove duplicate values from an array
272
+ * @category Object Manipulation
191
273
  * @function noTwins
192
274
  * @param arr - The array to remove duplicates from
193
275
  * @returns {unknown[]} A new array with unique values only
276
+ * @example
277
+ * noTwins([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
278
+ * noTwins(["a", "b", "a", "c"]); // ["a", "b", "c"]
279
+ * noTwins([1, "1", 1, "1"]); // [1, "1"]
194
280
  */
195
281
  function noTwins(arr) {
196
282
  return Array.from(new Set(arr));
197
283
  }
198
284
  /**
199
285
  *
200
- * Transforamtion utilites
286
+ * Transformation utilites
201
287
  *
202
288
  */
203
289
  /**
204
290
  * Transform a string to camelCase format
291
+ * @category Transformation
205
292
  * @function camelify
206
293
  * @param str - The string to transform
207
294
  * @returns {string} The string in camelCase format
295
+ * @example
296
+ * camelify("hello world"); // "helloWorld"
297
+ * camelify("C'est un test"); // "cestUnTest"
298
+ * camelify("foo bar baz"); // "fooBarBaz"
208
299
  */
209
300
  function camelify(str) {
210
301
  let camelCased = "";
@@ -222,9 +313,14 @@ function camelify(str) {
222
313
  }
223
314
  /**
224
315
  * Transform a string to kebab-case format
316
+ * @category Transformation
225
317
  * @function kebabify
226
318
  * @param str - The string to transform
227
319
  * @returns {string} The string in kebab-case format
320
+ * @example
321
+ * kebabify("hello world"); // "hello-world"
322
+ * kebabify("C'est un test"); // "ceststun-test"
323
+ * kebabify("foo bar baz"); // "foo-bar-baz"
228
324
  */
229
325
  function kebabify(str) {
230
326
  let kebabised = "";
@@ -238,9 +334,14 @@ function kebabify(str) {
238
334
  }
239
335
  /**
240
336
  * Transform a string to snake_case format
337
+ * @category Transformation
241
338
  * @function snakify
242
339
  * @param str - The string to transform
243
340
  * @returns {string} The string in snake_case format
341
+ * @example
342
+ * snakify("hello world"); // "hello_world"
343
+ * snakify("C'est un test"); // "ceststun_test"
344
+ * snakify("foo bar baz"); // "foo_bar_baz"
244
345
  */
245
346
  function snakify(str) {
246
347
  let snaked = "";
@@ -254,9 +355,14 @@ function snakify(str) {
254
355
  }
255
356
  /**
256
357
  * Capitalize the first character of a string
358
+ * @category Transformation
257
359
  * @function capitalize
258
360
  * @param str - The string to capitalize
259
361
  * @returns {string} The string with the first character in uppercase
362
+ * @example
363
+ * capitalize("hello"); // "Hello"
364
+ * capitalize("hello world"); // "Hello world"
365
+ * capitalize(""); // ""
260
366
  */
261
367
  function capitalize(str) {
262
368
  if (isEmpty(str))
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "clear-af.js",
3
- "version": "1.0.1",
3
+ "version": "1.0.3",
4
4
  "description": "Make your code readable af with zero bullsh*t utilities.",
5
5
  "keywords": [
6
6
  "javascript",
package/README_FR.md DELETED
@@ -1,123 +0,0 @@
1
- # clear-af.js
2
-
3
- Un package JavaScript rempli d'utilitaires pour rendre votre code **lisible af**. Parce que la clarté, c'est la clé de la survie en programmation.
4
-
5
- 📖 **Languages** : [🇬🇧 English](README.md) | [🇫🇷 Français](#)
6
-
7
- ---
8
-
9
- ## 📦 Installation
10
- ```bash
11
- npm install clear-af
12
- ```
13
-
14
- ---
15
-
16
- ## 🚀 Utilisation rapide
17
- ```javascript
18
- const clear = require('clear-af');
19
-
20
- clear.prettyError("Une erreur !");
21
- clear.camelify("hello world"); // "helloWorld"
22
- clear.isEmpty(data);
23
- ```
24
-
25
- ---
26
-
27
- ## ✨ Fonctionnalités
28
-
29
- ### 🔍 Logging amélioré
30
- Messages colorés et formatés pour un meilleur debugging.
31
- ```javascript
32
- clear.prettyError(error);
33
- clear.prettySuccess(message);
34
- clear.prettyWarn(warning);
35
- ```
36
-
37
- ### ✅ Validation facile
38
- Vérifiez vos données rapidement.
39
- ```javascript
40
- clear.isEmpty(value);
41
- clear.isEmail("test@example.com");
42
- clear.isURL("https://example.com");
43
- ```
44
-
45
- ### 🔄 Manipulation d'objets
46
- Clonez profondément et manipulez vos données.
47
- ```javascript
48
- clear.deepClone(obj);
49
- clear.noTwins([1, 2, 2, 3]); // [1, 2, 3]
50
- ```
51
-
52
- ### 📝 Transformation de strings
53
- Convertissez vos strings en différents formats.
54
- ```javascript
55
- clear.camelify("hello world"); // "helloWorld"
56
- clear.kebabify("hello world"); // "hello-world"
57
- clear.snakify("hello world"); // "hello_world"
58
- clear.capitalize("hello"); // "Hello"
59
- ```
60
-
61
- ---
62
-
63
- ## 📚 API Complète
64
-
65
- ### Logging
66
- - `prettyError(message, showTime?)`
67
- - `prettyWarn(message, showTime?)`
68
- - `prettySuccess(message, showTime?)`
69
- - `prettyInfo(message, showTime?)`
70
- - `prettyDebug(message, showTime?)`
71
- - `logSeparator()`
72
- - `logHeader(title)`
73
-
74
- ### Validation
75
- - `isEmpty(value)`
76
- - `isType(value, type)`
77
- - `isEmail(email)`
78
- - `isURL(url)`
79
-
80
- ### Objets & Arrays
81
- - `deepClone(obj)`
82
- - `noTwins(array)`
83
-
84
- ### Transformation de strings
85
- - `camelify(string)`
86
- - `kebabify(string)`
87
- - `snakify(string)`
88
- - `capitalize(string)`
89
-
90
- ---
91
-
92
- ## 🤔 FAQ
93
-
94
- **Q: Pourquoi "-af" dans le nom ?**
95
- R: Parce que ton code doit être lisible *af*, mec.
96
-
97
- **Q: Compatible avec TypeScript ?**
98
- R: Oui ! Les types TypeScript sont inclus.
99
-
100
- **Q: Ça ralentit mon app ?**
101
- R: Non, zéro overhead. Ce ne sont que des helpers.
102
-
103
- ---
104
-
105
- ## 📝 Licence
106
-
107
- MIT - Libre de l'utiliser comme bon vous semble.
108
-
109
- ---
110
-
111
- ## 🤝 Contribution
112
-
113
- Les contributions sont bienvenues !
114
- ```bash
115
- git clone https://github.com/FroostDev/clear-af.js
116
- cd clear-af.js
117
- npm install
118
- npm run build
119
- ```
120
-
121
- ---
122
-
123
- **clear-af.js** - *Parce que la clarté, c'est la santé mentale du dev.* 🖤
package/docs/.nojekyll DELETED
@@ -1 +0,0 @@
1
- TypeDoc added this file to prevent GitHub Pages from using Jekyll. You can turn off this behavior by setting the `githubPages` option to false.
@@ -1 +0,0 @@
1
- window.hierarchyData = "eJyrVirKzy8pVrKKjtVRKkpNy0lNLsnMzytWsqqurQUAmx4Kpg=="