clear-af.js 1.0.4 → 1.0.6
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.d.ts +4 -245
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +26 -361
- package/dist/logging.d.ts +94 -0
- package/dist/logging.d.ts.map +1 -0
- package/dist/logging.js +129 -0
- package/dist/object_manipulation.d.ts +29 -0
- package/dist/object_manipulation.d.ts.map +1 -0
- package/dist/object_manipulation.js +44 -0
- package/dist/transformation.d.ts +50 -0
- package/dist/transformation.d.ts.map +1 -0
- package/dist/transformation.js +90 -0
- package/dist/validation.d.ts +58 -0
- package/dist/validation.d.ts.map +1 -0
- package/dist/validation.js +85 -0
- package/package.json +1 -1
- package/typedoc.json +10 -0
package/dist/index.d.ts
CHANGED
|
@@ -1,246 +1,5 @@
|
|
|
1
|
-
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
*/
|
|
6
|
-
declare function getDate(time?: boolean): string;
|
|
7
|
-
/**
|
|
8
|
-
* Show a pretty error log message with optional date information
|
|
9
|
-
* @category Logging
|
|
10
|
-
* @function prettyError
|
|
11
|
-
* @param err - Error message to display
|
|
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)
|
|
19
|
-
*/
|
|
20
|
-
declare function prettyError(err: string, time?: boolean): void;
|
|
21
|
-
/**
|
|
22
|
-
* Show a pretty warn log message with optional date information
|
|
23
|
-
* @category Logging
|
|
24
|
-
* @function prettyWarn
|
|
25
|
-
* @param warn - Warning message to display
|
|
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)
|
|
33
|
-
*/
|
|
34
|
-
declare function prettyWarn(warn: string, time?: boolean): void;
|
|
35
|
-
/**
|
|
36
|
-
* Show a pretty success log message with optional date information
|
|
37
|
-
* @category Logging
|
|
38
|
-
* @function prettySuccess
|
|
39
|
-
* @param success - Success message to display
|
|
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)
|
|
47
|
-
*/
|
|
48
|
-
declare function prettySuccess(success: string, time?: boolean): void;
|
|
49
|
-
/**
|
|
50
|
-
* Show a pretty information log message with optional date information
|
|
51
|
-
* @category Logging
|
|
52
|
-
* @function prettyInfo
|
|
53
|
-
* @param info - Information message to display
|
|
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)
|
|
61
|
-
*/
|
|
62
|
-
declare function prettyInfo(info: string, time?: boolean): void;
|
|
63
|
-
/**
|
|
64
|
-
* Show a pretty debug log message with optional date information
|
|
65
|
-
* @category Logging
|
|
66
|
-
* @function prettyDebug
|
|
67
|
-
* @param debug - Debug message to display
|
|
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)
|
|
75
|
-
*/
|
|
76
|
-
declare function prettyDebug(debug: string, time?: boolean): void;
|
|
77
|
-
/**
|
|
78
|
-
* Show a separator line in console
|
|
79
|
-
* @category Logging
|
|
80
|
-
* @function logSeparator
|
|
81
|
-
* @example
|
|
82
|
-
* logSeparator();
|
|
83
|
-
* // Output: ══════════════════════════════════════════════════
|
|
84
|
-
*/
|
|
85
|
-
declare function logSeparator(): void;
|
|
86
|
-
/**
|
|
87
|
-
* Display a header with a title in the center
|
|
88
|
-
* @category Logging
|
|
89
|
-
* @function logHeader
|
|
90
|
-
* @param title - The title of the header
|
|
91
|
-
* @example
|
|
92
|
-
* logHeader("Welcome");
|
|
93
|
-
* // Output:
|
|
94
|
-
* // ╔═════════╗
|
|
95
|
-
* // ║ Welcome ║
|
|
96
|
-
* // ╚═════════╝
|
|
97
|
-
*/
|
|
98
|
-
declare function logHeader(title: string): void;
|
|
99
|
-
/**
|
|
100
|
-
*
|
|
101
|
-
* Validation utilities
|
|
102
|
-
*
|
|
103
|
-
*/
|
|
104
|
-
/**
|
|
105
|
-
* Check if any type of variable is empty
|
|
106
|
-
* @category Validation
|
|
107
|
-
* @function isEmpty
|
|
108
|
-
* @param value - The variable to check
|
|
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
|
|
118
|
-
*/
|
|
119
|
-
declare function isEmpty(value: unknown): boolean;
|
|
120
|
-
/**
|
|
121
|
-
* Check if the variable is of the chosen type
|
|
122
|
-
* @category Validation
|
|
123
|
-
* @function isType
|
|
124
|
-
* @param value - The variable to check
|
|
125
|
-
* @param type - The type you want
|
|
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
|
|
132
|
-
*/
|
|
133
|
-
declare function isType(value: unknown, type: string): boolean;
|
|
134
|
-
/**
|
|
135
|
-
* Check if an email is valid
|
|
136
|
-
* @category Validation
|
|
137
|
-
* @function isEmail
|
|
138
|
-
* @param email - The email to check
|
|
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
|
|
145
|
-
*/
|
|
146
|
-
declare function isEmail(email: string): boolean;
|
|
147
|
-
/**
|
|
148
|
-
* Check if a URL is valid
|
|
149
|
-
* @category Validation
|
|
150
|
-
* @function isURL
|
|
151
|
-
* @param url - The URL to check
|
|
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
|
|
158
|
-
*/
|
|
159
|
-
declare function isURL(url: string): boolean;
|
|
160
|
-
/**
|
|
161
|
-
*
|
|
162
|
-
* Object manipulation
|
|
163
|
-
*
|
|
164
|
-
*/
|
|
165
|
-
/**
|
|
166
|
-
* Create a deep clone of any object or array
|
|
167
|
-
* @category Object Manipulation
|
|
168
|
-
* @function deepClone
|
|
169
|
-
* @param obj - The object or array to clone
|
|
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)
|
|
178
|
-
*/
|
|
179
|
-
declare function deepClone<T>(obj: T): T;
|
|
180
|
-
/**
|
|
181
|
-
* Remove duplicate values from an array
|
|
182
|
-
* @category Object Manipulation
|
|
183
|
-
* @function noTwins
|
|
184
|
-
* @param arr - The array to remove duplicates from
|
|
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"]
|
|
190
|
-
*/
|
|
191
|
-
declare function noTwins(arr: unknown[]): unknown[];
|
|
192
|
-
/**
|
|
193
|
-
*
|
|
194
|
-
* Transformation utilites
|
|
195
|
-
*
|
|
196
|
-
*/
|
|
197
|
-
/**
|
|
198
|
-
* Transform a string to camelCase format
|
|
199
|
-
* @category Transformation
|
|
200
|
-
* @function camelify
|
|
201
|
-
* @param str - The string to transform
|
|
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"
|
|
207
|
-
*/
|
|
208
|
-
declare function camelify(str: string): string;
|
|
209
|
-
/**
|
|
210
|
-
* Transform a string to kebab-case format
|
|
211
|
-
* @category Transformation
|
|
212
|
-
* @function kebabify
|
|
213
|
-
* @param str - The string to transform
|
|
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"
|
|
219
|
-
*/
|
|
220
|
-
declare function kebabify(str: string): string;
|
|
221
|
-
/**
|
|
222
|
-
* Transform a string to snake_case format
|
|
223
|
-
* @category Transformation
|
|
224
|
-
* @function snakify
|
|
225
|
-
* @param str - The string to transform
|
|
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"
|
|
231
|
-
*/
|
|
232
|
-
declare function snakify(str: string): string;
|
|
233
|
-
/**
|
|
234
|
-
* Capitalize the first character of a string
|
|
235
|
-
* @category Transformation
|
|
236
|
-
* @function capitalize
|
|
237
|
-
* @param str - The string to capitalize
|
|
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(""); // ""
|
|
243
|
-
*/
|
|
244
|
-
declare function capitalize(str: string): string;
|
|
245
|
-
export { getDate, prettyError, prettyWarn, prettySuccess, prettyInfo, prettyDebug, logSeparator, logHeader, isEmpty, isType, isEmail, isURL, deepClone, noTwins, camelify, kebabify, snakify, capitalize };
|
|
1
|
+
export { prettyError, prettyWarn, prettySuccess, prettyInfo, prettyDebug, logSeparator, logHeader } from './logging';
|
|
2
|
+
export * from './validation';
|
|
3
|
+
export * from './transformation';
|
|
4
|
+
export * from './object_manipulation';
|
|
246
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,WAAW,CAAC;AACrH,cAAc,cAAc,CAAC;AAC7B,cAAc,kBAAkB,CAAC;AACjC,cAAc,uBAAuB,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -7,365 +7,30 @@
|
|
|
7
7
|
|
|
8
8
|
Made by FroostDev | https://github.com/FroostDev - MIT Licence
|
|
9
9
|
*/
|
|
10
|
-
Object.
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
exports.prettyInfo = prettyInfo;
|
|
16
|
-
exports.prettyDebug = prettyDebug;
|
|
17
|
-
exports.logSeparator = logSeparator;
|
|
18
|
-
exports.logHeader = logHeader;
|
|
19
|
-
exports.isEmpty = isEmpty;
|
|
20
|
-
exports.isType = isType;
|
|
21
|
-
exports.isEmail = isEmail;
|
|
22
|
-
exports.isURL = isURL;
|
|
23
|
-
exports.deepClone = deepClone;
|
|
24
|
-
exports.noTwins = noTwins;
|
|
25
|
-
exports.camelify = camelify;
|
|
26
|
-
exports.kebabify = kebabify;
|
|
27
|
-
exports.snakify = snakify;
|
|
28
|
-
exports.capitalize = capitalize;
|
|
29
|
-
/**
|
|
30
|
-
* =======================
|
|
31
|
-
* Functions for utilities
|
|
32
|
-
* =======================
|
|
33
|
-
*/
|
|
34
|
-
function getDate(time = false) {
|
|
35
|
-
return time ? `[${new Date().toLocaleString()}]` : '';
|
|
36
|
-
}
|
|
37
|
-
/*
|
|
38
|
-
* =================
|
|
39
|
-
* Logging utilities
|
|
40
|
-
* =================
|
|
41
|
-
*/
|
|
42
|
-
/**
|
|
43
|
-
* Show a pretty error log message with optional date information
|
|
44
|
-
* @category Logging
|
|
45
|
-
* @function prettyError
|
|
46
|
-
* @param err - Error message to display
|
|
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)
|
|
54
|
-
*/
|
|
55
|
-
function prettyError(err, time = false) {
|
|
56
|
-
const date = getDate(time);
|
|
57
|
-
console.log(`\x1b[1;41m ✕ ${date} - ${err} \x1b[0m`);
|
|
58
|
-
}
|
|
59
|
-
/**
|
|
60
|
-
* Show a pretty warn log message with optional date information
|
|
61
|
-
* @category Logging
|
|
62
|
-
* @function prettyWarn
|
|
63
|
-
* @param warn - Warning message to display
|
|
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)
|
|
71
|
-
*/
|
|
72
|
-
function prettyWarn(warn, time = false) {
|
|
73
|
-
const date = getDate(time);
|
|
74
|
-
console.log(`\x1b[1;43m ⚠ ${date} - ${warn} \x1b[0m`);
|
|
75
|
-
}
|
|
76
|
-
/**
|
|
77
|
-
* Show a pretty success log message with optional date information
|
|
78
|
-
* @category Logging
|
|
79
|
-
* @function prettySuccess
|
|
80
|
-
* @param success - Success message to display
|
|
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)
|
|
88
|
-
*/
|
|
89
|
-
function prettySuccess(success, time = false) {
|
|
90
|
-
const date = getDate(time);
|
|
91
|
-
console.log(`\x1b[1;42m ✔ ${date} - ${success} \x1b[0m`);
|
|
92
|
-
}
|
|
93
|
-
/**
|
|
94
|
-
* Show a pretty information log message with optional date information
|
|
95
|
-
* @category Logging
|
|
96
|
-
* @function prettyInfo
|
|
97
|
-
* @param info - Information message to display
|
|
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)
|
|
105
|
-
*/
|
|
106
|
-
function prettyInfo(info, time = false) {
|
|
107
|
-
const date = getDate(time);
|
|
108
|
-
console.log(`\x1b[1;44m ℹ ${date} - ${info} \x1b[0m`);
|
|
109
|
-
}
|
|
110
|
-
/**
|
|
111
|
-
* Show a pretty debug log message with optional date information
|
|
112
|
-
* @category Logging
|
|
113
|
-
* @function prettyDebug
|
|
114
|
-
* @param debug - Debug message to display
|
|
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)
|
|
122
|
-
*/
|
|
123
|
-
function prettyDebug(debug, time = false) {
|
|
124
|
-
const date = getDate(time);
|
|
125
|
-
console.log(`\x1b[1;97m ⚙ ${date} - ${debug} \x1b[0m`);
|
|
126
|
-
}
|
|
127
|
-
/**
|
|
128
|
-
* Show a separator line in console
|
|
129
|
-
* @category Logging
|
|
130
|
-
* @function logSeparator
|
|
131
|
-
* @example
|
|
132
|
-
* logSeparator();
|
|
133
|
-
* // Output: ══════════════════════════════════════════════════
|
|
134
|
-
*/
|
|
135
|
-
function logSeparator() {
|
|
136
|
-
console.log(`\x1b[1m${'═'.repeat(50)}\x1b[0m`);
|
|
137
|
-
}
|
|
138
|
-
/**
|
|
139
|
-
* Display a header with a title in the center
|
|
140
|
-
* @category Logging
|
|
141
|
-
* @function logHeader
|
|
142
|
-
* @param title - The title of the header
|
|
143
|
-
* @example
|
|
144
|
-
* logHeader("Welcome");
|
|
145
|
-
* // Output:
|
|
146
|
-
* // ╔═════════╗
|
|
147
|
-
* // ║ Welcome ║
|
|
148
|
-
* // ╚═════════╝
|
|
149
|
-
*/
|
|
150
|
-
function logHeader(title) {
|
|
151
|
-
console.log(`\x1b[1m╔${'═'.repeat(title.length + 2)}╗\x1b[0m`);
|
|
152
|
-
console.log(`\x1b[1m║ ${title} ║\x1b[0m`);
|
|
153
|
-
console.log(`\x1b[1m╚${'═'.repeat(title.length + 2)}╝\x1b[0m`);
|
|
154
|
-
}
|
|
155
|
-
/**
|
|
156
|
-
*
|
|
157
|
-
* Validation utilities
|
|
158
|
-
*
|
|
159
|
-
*/
|
|
160
|
-
/**
|
|
161
|
-
* Check if any type of variable is empty
|
|
162
|
-
* @category Validation
|
|
163
|
-
* @function isEmpty
|
|
164
|
-
* @param value - The variable to check
|
|
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
|
|
174
|
-
*/
|
|
175
|
-
function isEmpty(value) {
|
|
176
|
-
if (value === null || value === undefined)
|
|
177
|
-
return true;
|
|
178
|
-
if (typeof value === "string")
|
|
179
|
-
return value.trim().length === 0;
|
|
180
|
-
if (Array.isArray(value))
|
|
181
|
-
return value.length === 0;
|
|
182
|
-
if (typeof value === "object")
|
|
183
|
-
return Object.keys(value).length === 0;
|
|
184
|
-
return false;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Check if the variable is of the chosen type
|
|
188
|
-
* @category Validation
|
|
189
|
-
* @function isType
|
|
190
|
-
* @param value - The variable to check
|
|
191
|
-
* @param type - The type you want
|
|
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
|
|
198
|
-
*/
|
|
199
|
-
function isType(value, type) {
|
|
200
|
-
return typeof value === type;
|
|
201
|
-
}
|
|
202
|
-
/**
|
|
203
|
-
* Check if an email is valid
|
|
204
|
-
* @category Validation
|
|
205
|
-
* @function isEmail
|
|
206
|
-
* @param email - The email to check
|
|
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
|
|
213
|
-
*/
|
|
214
|
-
function isEmail(email) {
|
|
215
|
-
const regex = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
216
|
-
return regex.test(email);
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* Check if a URL is valid
|
|
220
|
-
* @category Validation
|
|
221
|
-
* @function isURL
|
|
222
|
-
* @param url - The URL to check
|
|
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
|
|
229
|
-
*/
|
|
230
|
-
function isURL(url) {
|
|
231
|
-
try {
|
|
232
|
-
new URL(url);
|
|
233
|
-
return true;
|
|
234
|
-
}
|
|
235
|
-
catch (error) {
|
|
236
|
-
return false;
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
/**
|
|
240
|
-
*
|
|
241
|
-
* Object manipulation
|
|
242
|
-
*
|
|
243
|
-
*/
|
|
244
|
-
/**
|
|
245
|
-
* Create a deep clone of any object or array
|
|
246
|
-
* @category Object Manipulation
|
|
247
|
-
* @function deepClone
|
|
248
|
-
* @param obj - The object or array to clone
|
|
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)
|
|
257
|
-
*/
|
|
258
|
-
function deepClone(obj) {
|
|
259
|
-
if (obj === null || typeof obj !== "object")
|
|
260
|
-
return obj;
|
|
261
|
-
if (Array.isArray(obj))
|
|
262
|
-
return obj.map(item => deepClone(item));
|
|
263
|
-
const cloned = {};
|
|
264
|
-
for (const key in obj) {
|
|
265
|
-
if (obj.hasOwnProperty(key))
|
|
266
|
-
cloned[key] = deepClone(obj[key]);
|
|
10
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
11
|
+
if (k2 === undefined) k2 = k;
|
|
12
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
13
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
14
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
267
15
|
}
|
|
268
|
-
|
|
269
|
-
}
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
function
|
|
282
|
-
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
/**
|
|
290
|
-
* Transform a string to camelCase format
|
|
291
|
-
* @category Transformation
|
|
292
|
-
* @function camelify
|
|
293
|
-
* @param str - The string to transform
|
|
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"
|
|
299
|
-
*/
|
|
300
|
-
function camelify(str) {
|
|
301
|
-
let camelCased = "";
|
|
302
|
-
if (!isEmpty(str)) {
|
|
303
|
-
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
304
|
-
let toCamelify = cleaned.split(" ");
|
|
305
|
-
camelCased = toCamelify.map((word, index) => {
|
|
306
|
-
if (index === 0)
|
|
307
|
-
return word.toLowerCase();
|
|
308
|
-
return word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
309
|
-
})
|
|
310
|
-
.join('');
|
|
311
|
-
}
|
|
312
|
-
return camelCased;
|
|
313
|
-
}
|
|
314
|
-
/**
|
|
315
|
-
* Transform a string to kebab-case format
|
|
316
|
-
* @category Transformation
|
|
317
|
-
* @function kebabify
|
|
318
|
-
* @param str - The string to transform
|
|
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"
|
|
324
|
-
*/
|
|
325
|
-
function kebabify(str) {
|
|
326
|
-
let kebabised = "";
|
|
327
|
-
if (!isEmpty(str)) {
|
|
328
|
-
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
329
|
-
let toKebabify = cleaned.split(" ");
|
|
330
|
-
kebabised = toKebabify.map(word => word.toLowerCase())
|
|
331
|
-
.join("-");
|
|
332
|
-
}
|
|
333
|
-
return kebabised;
|
|
334
|
-
}
|
|
335
|
-
/**
|
|
336
|
-
* Transform a string to snake_case format
|
|
337
|
-
* @category Transformation
|
|
338
|
-
* @function snakify
|
|
339
|
-
* @param str - The string to transform
|
|
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"
|
|
345
|
-
*/
|
|
346
|
-
function snakify(str) {
|
|
347
|
-
let snaked = "";
|
|
348
|
-
if (!isEmpty(str)) {
|
|
349
|
-
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
350
|
-
let toSnakify = cleaned.split(" ");
|
|
351
|
-
snaked = toSnakify.map(word => word.toLowerCase())
|
|
352
|
-
.join("_");
|
|
353
|
-
}
|
|
354
|
-
return snaked;
|
|
355
|
-
}
|
|
356
|
-
/**
|
|
357
|
-
* Capitalize the first character of a string
|
|
358
|
-
* @category Transformation
|
|
359
|
-
* @function capitalize
|
|
360
|
-
* @param str - The string to capitalize
|
|
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(""); // ""
|
|
366
|
-
*/
|
|
367
|
-
function capitalize(str) {
|
|
368
|
-
if (isEmpty(str))
|
|
369
|
-
return str;
|
|
370
|
-
return str[0].toUpperCase() + str.slice(1);
|
|
371
|
-
}
|
|
16
|
+
Object.defineProperty(o, k2, desc);
|
|
17
|
+
}) : (function(o, m, k, k2) {
|
|
18
|
+
if (k2 === undefined) k2 = k;
|
|
19
|
+
o[k2] = m[k];
|
|
20
|
+
}));
|
|
21
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
22
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
23
|
+
};
|
|
24
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
25
|
+
exports.logHeader = exports.logSeparator = exports.prettyDebug = exports.prettyInfo = exports.prettySuccess = exports.prettyWarn = exports.prettyError = void 0;
|
|
26
|
+
var logging_1 = require("./logging");
|
|
27
|
+
Object.defineProperty(exports, "prettyError", { enumerable: true, get: function () { return logging_1.prettyError; } });
|
|
28
|
+
Object.defineProperty(exports, "prettyWarn", { enumerable: true, get: function () { return logging_1.prettyWarn; } });
|
|
29
|
+
Object.defineProperty(exports, "prettySuccess", { enumerable: true, get: function () { return logging_1.prettySuccess; } });
|
|
30
|
+
Object.defineProperty(exports, "prettyInfo", { enumerable: true, get: function () { return logging_1.prettyInfo; } });
|
|
31
|
+
Object.defineProperty(exports, "prettyDebug", { enumerable: true, get: function () { return logging_1.prettyDebug; } });
|
|
32
|
+
Object.defineProperty(exports, "logSeparator", { enumerable: true, get: function () { return logging_1.logSeparator; } });
|
|
33
|
+
Object.defineProperty(exports, "logHeader", { enumerable: true, get: function () { return logging_1.logHeader; } });
|
|
34
|
+
__exportStar(require("./validation"), exports);
|
|
35
|
+
__exportStar(require("./transformation"), exports);
|
|
36
|
+
__exportStar(require("./object_manipulation"), exports);
|
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Show a pretty error log message with optional date information
|
|
3
|
+
* @category Logging
|
|
4
|
+
* @function prettyError
|
|
5
|
+
* @param err - Error message to display
|
|
6
|
+
* @param time - Include or not a timestamp
|
|
7
|
+
* @example
|
|
8
|
+
* prettyError("Database connection failed");
|
|
9
|
+
* // Output: ✕ - Database connection failed (in red)
|
|
10
|
+
*
|
|
11
|
+
* prettyError("Critical error", true);
|
|
12
|
+
* // Output: ✕ [30/03/2026 10:30:45] - Critical error (in red with timestamp)
|
|
13
|
+
*/
|
|
14
|
+
declare function prettyError(err: string, time?: boolean): void;
|
|
15
|
+
/**
|
|
16
|
+
* Show a pretty warn log message with optional date information
|
|
17
|
+
* @category Logging
|
|
18
|
+
* @function prettyWarn
|
|
19
|
+
* @param warn - Warning message to display
|
|
20
|
+
* @param time - Include or not a timestamp
|
|
21
|
+
* @example
|
|
22
|
+
* prettyWarn("Deprecated function used");
|
|
23
|
+
* // Output: ⚠ - Deprecated function used (in orange)
|
|
24
|
+
*
|
|
25
|
+
* prettyWarn("Low memory", true);
|
|
26
|
+
* // Output: ⚠ [30/03/2026 10:30:45] - Low memory (in orange with timestamp)
|
|
27
|
+
*/
|
|
28
|
+
declare function prettyWarn(warn: string, time?: boolean): void;
|
|
29
|
+
/**
|
|
30
|
+
* Show a pretty success log message with optional date information
|
|
31
|
+
* @category Logging
|
|
32
|
+
* @function prettySuccess
|
|
33
|
+
* @param success - Success message to display
|
|
34
|
+
* @param time - Include or not a timestamp
|
|
35
|
+
* @example
|
|
36
|
+
* prettySuccess("User created successfully");
|
|
37
|
+
* // Output: ✔ - User created successfully (in green)
|
|
38
|
+
*
|
|
39
|
+
* prettySuccess("Data saved", true);
|
|
40
|
+
* // Output: ✔ [30/03/2026 10:30:45] - Data saved (in green with timestamp)
|
|
41
|
+
*/
|
|
42
|
+
declare function prettySuccess(success: string, time?: boolean): void;
|
|
43
|
+
/**
|
|
44
|
+
* Show a pretty information log message with optional date information
|
|
45
|
+
* @category Logging
|
|
46
|
+
* @function prettyInfo
|
|
47
|
+
* @param info - Information message to display
|
|
48
|
+
* @param time - Include or not a timestamp
|
|
49
|
+
* @example
|
|
50
|
+
* prettyInfo("Server is running on port 3000");
|
|
51
|
+
* // Output: ℹ - Server is running on port 3000 (in blue)
|
|
52
|
+
*
|
|
53
|
+
* prettyInfo("Cache cleared", true);
|
|
54
|
+
* // Output: ℹ [30/03/2026 10:30:45] - Cache cleared (in blue with timestamp)
|
|
55
|
+
*/
|
|
56
|
+
declare function prettyInfo(info: string, time?: boolean): void;
|
|
57
|
+
/**
|
|
58
|
+
* Show a pretty debug log message with optional date information
|
|
59
|
+
* @category Logging
|
|
60
|
+
* @function prettyDebug
|
|
61
|
+
* @param debug - Debug message to display
|
|
62
|
+
* @param time - Include or not a timestamp
|
|
63
|
+
* @example
|
|
64
|
+
* prettyDebug("Variable x = 42");
|
|
65
|
+
* // Output: ⚙ - Variable x = 42 (in white)
|
|
66
|
+
*
|
|
67
|
+
* prettyDebug("Function call trace", true);
|
|
68
|
+
* // Output: ⚙ [30/03/2026 10:30:45] - Function call trace (in white with timestamp)
|
|
69
|
+
*/
|
|
70
|
+
declare function prettyDebug(debug: string, time?: boolean): void;
|
|
71
|
+
/**
|
|
72
|
+
* Show a separator line in console
|
|
73
|
+
* @category Logging
|
|
74
|
+
* @function logSeparator
|
|
75
|
+
* @example
|
|
76
|
+
* logSeparator();
|
|
77
|
+
* // Output: ══════════════════════════════════════════════════
|
|
78
|
+
*/
|
|
79
|
+
declare function logSeparator(): void;
|
|
80
|
+
/**
|
|
81
|
+
* Display a header with a title in the center
|
|
82
|
+
* @category Logging
|
|
83
|
+
* @function logHeader
|
|
84
|
+
* @param title - The title of the header
|
|
85
|
+
* @example
|
|
86
|
+
* logHeader("Welcome");
|
|
87
|
+
* // Output:
|
|
88
|
+
* // ╔═════════╗
|
|
89
|
+
* // ║ Welcome ║
|
|
90
|
+
* // ╚═════════╝
|
|
91
|
+
*/
|
|
92
|
+
declare function logHeader(title: string): void;
|
|
93
|
+
export { prettyError, prettyWarn, prettySuccess, prettyInfo, prettyDebug, logSeparator, logHeader };
|
|
94
|
+
//# sourceMappingURL=logging.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logging.d.ts","sourceRoot":"","sources":["../src/logging.ts"],"names":[],"mappings":"AAQA;;;;;;;;;;;;GAYG;AACH,iBAAS,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,aAAa,CAAC,OAAO,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAG1D;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,UAAU,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGpD;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,WAAW,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,UAAQ,GAAG,IAAI,CAGtD;AAED;;;;;;;GAOG;AACH,iBAAS,YAAY,IAAI,IAAI,CAE5B;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,SAAS,CAAC,KAAK,EAAE,MAAM,GAAG,IAAI,CAItC;AAED,OAAO,EAAE,WAAW,EAAE,UAAU,EAAE,aAAa,EAAE,UAAU,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,CAAC"}
|
package/dist/logging.js
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.prettyError = prettyError;
|
|
4
|
+
exports.prettyWarn = prettyWarn;
|
|
5
|
+
exports.prettySuccess = prettySuccess;
|
|
6
|
+
exports.prettyInfo = prettyInfo;
|
|
7
|
+
exports.prettyDebug = prettyDebug;
|
|
8
|
+
exports.logSeparator = logSeparator;
|
|
9
|
+
exports.logHeader = logHeader;
|
|
10
|
+
/**
|
|
11
|
+
* Helper function to get formatted date
|
|
12
|
+
* @internal
|
|
13
|
+
*/
|
|
14
|
+
function getDate(time = false) {
|
|
15
|
+
return time ? `[${new Date().toLocaleString()}]` : '';
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Show a pretty error log message with optional date information
|
|
19
|
+
* @category Logging
|
|
20
|
+
* @function prettyError
|
|
21
|
+
* @param err - Error message to display
|
|
22
|
+
* @param time - Include or not a timestamp
|
|
23
|
+
* @example
|
|
24
|
+
* prettyError("Database connection failed");
|
|
25
|
+
* // Output: ✕ - Database connection failed (in red)
|
|
26
|
+
*
|
|
27
|
+
* prettyError("Critical error", true);
|
|
28
|
+
* // Output: ✕ [30/03/2026 10:30:45] - Critical error (in red with timestamp)
|
|
29
|
+
*/
|
|
30
|
+
function prettyError(err, time = false) {
|
|
31
|
+
const date = getDate(time);
|
|
32
|
+
console.log(`\x1b[1;41m ✕ ${date} - ${err} \x1b[0m`);
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Show a pretty warn log message with optional date information
|
|
36
|
+
* @category Logging
|
|
37
|
+
* @function prettyWarn
|
|
38
|
+
* @param warn - Warning message to display
|
|
39
|
+
* @param time - Include or not a timestamp
|
|
40
|
+
* @example
|
|
41
|
+
* prettyWarn("Deprecated function used");
|
|
42
|
+
* // Output: ⚠ - Deprecated function used (in orange)
|
|
43
|
+
*
|
|
44
|
+
* prettyWarn("Low memory", true);
|
|
45
|
+
* // Output: ⚠ [30/03/2026 10:30:45] - Low memory (in orange with timestamp)
|
|
46
|
+
*/
|
|
47
|
+
function prettyWarn(warn, time = false) {
|
|
48
|
+
const date = getDate(time);
|
|
49
|
+
console.log(`\x1b[1;43m ⚠ ${date} - ${warn} \x1b[0m`);
|
|
50
|
+
}
|
|
51
|
+
/**
|
|
52
|
+
* Show a pretty success log message with optional date information
|
|
53
|
+
* @category Logging
|
|
54
|
+
* @function prettySuccess
|
|
55
|
+
* @param success - Success message to display
|
|
56
|
+
* @param time - Include or not a timestamp
|
|
57
|
+
* @example
|
|
58
|
+
* prettySuccess("User created successfully");
|
|
59
|
+
* // Output: ✔ - User created successfully (in green)
|
|
60
|
+
*
|
|
61
|
+
* prettySuccess("Data saved", true);
|
|
62
|
+
* // Output: ✔ [30/03/2026 10:30:45] - Data saved (in green with timestamp)
|
|
63
|
+
*/
|
|
64
|
+
function prettySuccess(success, time = false) {
|
|
65
|
+
const date = getDate(time);
|
|
66
|
+
console.log(`\x1b[1;42m ✔ ${date} - ${success} \x1b[0m`);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* Show a pretty information log message with optional date information
|
|
70
|
+
* @category Logging
|
|
71
|
+
* @function prettyInfo
|
|
72
|
+
* @param info - Information message to display
|
|
73
|
+
* @param time - Include or not a timestamp
|
|
74
|
+
* @example
|
|
75
|
+
* prettyInfo("Server is running on port 3000");
|
|
76
|
+
* // Output: ℹ - Server is running on port 3000 (in blue)
|
|
77
|
+
*
|
|
78
|
+
* prettyInfo("Cache cleared", true);
|
|
79
|
+
* // Output: ℹ [30/03/2026 10:30:45] - Cache cleared (in blue with timestamp)
|
|
80
|
+
*/
|
|
81
|
+
function prettyInfo(info, time = false) {
|
|
82
|
+
const date = getDate(time);
|
|
83
|
+
console.log(`\x1b[1;44m ℹ ${date} - ${info} \x1b[0m`);
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Show a pretty debug log message with optional date information
|
|
87
|
+
* @category Logging
|
|
88
|
+
* @function prettyDebug
|
|
89
|
+
* @param debug - Debug message to display
|
|
90
|
+
* @param time - Include or not a timestamp
|
|
91
|
+
* @example
|
|
92
|
+
* prettyDebug("Variable x = 42");
|
|
93
|
+
* // Output: ⚙ - Variable x = 42 (in white)
|
|
94
|
+
*
|
|
95
|
+
* prettyDebug("Function call trace", true);
|
|
96
|
+
* // Output: ⚙ [30/03/2026 10:30:45] - Function call trace (in white with timestamp)
|
|
97
|
+
*/
|
|
98
|
+
function prettyDebug(debug, time = false) {
|
|
99
|
+
const date = getDate(time);
|
|
100
|
+
console.log(`\x1b[1;97m ⚙ ${date} - ${debug} \x1b[0m`);
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Show a separator line in console
|
|
104
|
+
* @category Logging
|
|
105
|
+
* @function logSeparator
|
|
106
|
+
* @example
|
|
107
|
+
* logSeparator();
|
|
108
|
+
* // Output: ══════════════════════════════════════════════════
|
|
109
|
+
*/
|
|
110
|
+
function logSeparator() {
|
|
111
|
+
console.log(`\x1b[1m${'═'.repeat(50)}\x1b[0m`);
|
|
112
|
+
}
|
|
113
|
+
/**
|
|
114
|
+
* Display a header with a title in the center
|
|
115
|
+
* @category Logging
|
|
116
|
+
* @function logHeader
|
|
117
|
+
* @param title - The title of the header
|
|
118
|
+
* @example
|
|
119
|
+
* logHeader("Welcome");
|
|
120
|
+
* // Output:
|
|
121
|
+
* // ╔═════════╗
|
|
122
|
+
* // ║ Welcome ║
|
|
123
|
+
* // ╚═════════╝
|
|
124
|
+
*/
|
|
125
|
+
function logHeader(title) {
|
|
126
|
+
console.log(`\x1b[1m╔${'═'.repeat(title.length + 2)}╗\x1b[0m`);
|
|
127
|
+
console.log(`\x1b[1m║ ${title} ║\x1b[0m`);
|
|
128
|
+
console.log(`\x1b[1m╚${'═'.repeat(title.length + 2)}╝\x1b[0m`);
|
|
129
|
+
}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create a deep clone of any object or array
|
|
3
|
+
* @category Object Manipulation
|
|
4
|
+
* @function deepClone
|
|
5
|
+
* @param obj - The object or array to clone
|
|
6
|
+
* @returns A deep clone of the object
|
|
7
|
+
* @example
|
|
8
|
+
* const user = { name: "Alice", skills: ["JS", "TS"] };
|
|
9
|
+
* const clone = deepClone(user);
|
|
10
|
+
* clone.name = "Bob";
|
|
11
|
+
* clone.skills[0] = "Python";
|
|
12
|
+
* console.log(user.name); // "Alice" (unchanged)
|
|
13
|
+
* console.log(user.skills[0]); // "JS" (unchanged)
|
|
14
|
+
*/
|
|
15
|
+
declare function deepClone<T>(obj: T): T;
|
|
16
|
+
/**
|
|
17
|
+
* Remove duplicate values from an array
|
|
18
|
+
* @category Object Manipulation
|
|
19
|
+
* @function noTwins
|
|
20
|
+
* @param arr - The array to remove duplicates from
|
|
21
|
+
* @returns {unknown[]} A new array with unique values only
|
|
22
|
+
* @example
|
|
23
|
+
* noTwins([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
|
|
24
|
+
* noTwins(["a", "b", "a", "c"]); // ["a", "b", "c"]
|
|
25
|
+
* noTwins([1, "1", 1, "1"]); // [1, "1"]
|
|
26
|
+
*/
|
|
27
|
+
declare function noTwins(arr: unknown[]): unknown[];
|
|
28
|
+
export { deepClone, noTwins };
|
|
29
|
+
//# sourceMappingURL=object_manipulation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"object_manipulation.d.ts","sourceRoot":"","sources":["../src/object_manipulation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;GAaG;AACH,iBAAS,SAAS,CAAC,CAAC,EAAE,GAAG,EAAE,CAAC,GAAG,CAAC,CAU/B;AAED;;;;;;;;;;GAUG;AACH,iBAAS,OAAO,CAAC,GAAG,EAAE,OAAO,EAAE,GAAG,OAAO,EAAE,CAE1C;AAED,OAAO,EAAC,SAAS,EAAE,OAAO,EAAC,CAAC"}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.deepClone = deepClone;
|
|
4
|
+
exports.noTwins = noTwins;
|
|
5
|
+
/**
|
|
6
|
+
* Create a deep clone of any object or array
|
|
7
|
+
* @category Object Manipulation
|
|
8
|
+
* @function deepClone
|
|
9
|
+
* @param obj - The object or array to clone
|
|
10
|
+
* @returns A deep clone of the object
|
|
11
|
+
* @example
|
|
12
|
+
* const user = { name: "Alice", skills: ["JS", "TS"] };
|
|
13
|
+
* const clone = deepClone(user);
|
|
14
|
+
* clone.name = "Bob";
|
|
15
|
+
* clone.skills[0] = "Python";
|
|
16
|
+
* console.log(user.name); // "Alice" (unchanged)
|
|
17
|
+
* console.log(user.skills[0]); // "JS" (unchanged)
|
|
18
|
+
*/
|
|
19
|
+
function deepClone(obj) {
|
|
20
|
+
if (obj === null || typeof obj !== "object")
|
|
21
|
+
return obj;
|
|
22
|
+
if (Array.isArray(obj))
|
|
23
|
+
return obj.map(item => deepClone(item));
|
|
24
|
+
const cloned = {};
|
|
25
|
+
for (const key in obj) {
|
|
26
|
+
if (obj.hasOwnProperty(key))
|
|
27
|
+
cloned[key] = deepClone(obj[key]);
|
|
28
|
+
}
|
|
29
|
+
return cloned;
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* Remove duplicate values from an array
|
|
33
|
+
* @category Object Manipulation
|
|
34
|
+
* @function noTwins
|
|
35
|
+
* @param arr - The array to remove duplicates from
|
|
36
|
+
* @returns {unknown[]} A new array with unique values only
|
|
37
|
+
* @example
|
|
38
|
+
* noTwins([1, 2, 2, 3, 3, 3]); // [1, 2, 3]
|
|
39
|
+
* noTwins(["a", "b", "a", "c"]); // ["a", "b", "c"]
|
|
40
|
+
* noTwins([1, "1", 1, "1"]); // [1, "1"]
|
|
41
|
+
*/
|
|
42
|
+
function noTwins(arr) {
|
|
43
|
+
return Array.from(new Set(arr));
|
|
44
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Transform a string to camelCase format
|
|
3
|
+
* @category Transformation
|
|
4
|
+
* @function camelify
|
|
5
|
+
* @param str - The string to transform
|
|
6
|
+
* @returns {string} The string in camelCase format
|
|
7
|
+
* @example
|
|
8
|
+
* camelify("hello world"); // "helloWorld"
|
|
9
|
+
* camelify("C'est un test"); // "cestUnTest"
|
|
10
|
+
* camelify("foo bar baz"); // "fooBarBaz"
|
|
11
|
+
*/
|
|
12
|
+
declare function camelify(str: string): string;
|
|
13
|
+
/**
|
|
14
|
+
* Transform a string to kebab-case format
|
|
15
|
+
* @category Transformation
|
|
16
|
+
* @function kebabify
|
|
17
|
+
* @param str - The string to transform
|
|
18
|
+
* @returns {string} The string in kebab-case format
|
|
19
|
+
* @example
|
|
20
|
+
* kebabify("hello world"); // "hello-world"
|
|
21
|
+
* kebabify("C'est un test"); // "ceststun-test"
|
|
22
|
+
* kebabify("foo bar baz"); // "foo-bar-baz"
|
|
23
|
+
*/
|
|
24
|
+
declare function kebabify(str: string): string;
|
|
25
|
+
/**
|
|
26
|
+
* Transform a string to snake_case format
|
|
27
|
+
* @category Transformation
|
|
28
|
+
* @function snakify
|
|
29
|
+
* @param str - The string to transform
|
|
30
|
+
* @returns {string} The string in snake_case format
|
|
31
|
+
* @example
|
|
32
|
+
* snakify("hello world"); // "hello_world"
|
|
33
|
+
* snakify("C'est un test"); // "ceststun_test"
|
|
34
|
+
* snakify("foo bar baz"); // "foo_bar_baz"
|
|
35
|
+
*/
|
|
36
|
+
declare function snakify(str: string): string;
|
|
37
|
+
/**
|
|
38
|
+
* Capitalize the first character of a string
|
|
39
|
+
* @category Transformation
|
|
40
|
+
* @function capitalize
|
|
41
|
+
* @param str - The string to capitalize
|
|
42
|
+
* @returns {string} The string with the first character in uppercase
|
|
43
|
+
* @example
|
|
44
|
+
* capitalize("hello"); // "Hello"
|
|
45
|
+
* capitalize("hello world"); // "Hello world"
|
|
46
|
+
* capitalize(""); // ""
|
|
47
|
+
*/
|
|
48
|
+
declare function capitalize(str: string): string;
|
|
49
|
+
export { camelify, kebabify, snakify, capitalize };
|
|
50
|
+
//# sourceMappingURL=transformation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"transformation.d.ts","sourceRoot":"","sources":["../src/transformation.ts"],"names":[],"mappings":"AAEA;;;;;;;;;;GAUG;AACH,iBAAS,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAarC;AAED;;;;;;;;;;GAUG;AACH,iBAAS,QAAQ,CAAC,GAAG,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;AAED,OAAO,EAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,EAAE,UAAU,EAAC,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.camelify = camelify;
|
|
4
|
+
exports.kebabify = kebabify;
|
|
5
|
+
exports.snakify = snakify;
|
|
6
|
+
exports.capitalize = capitalize;
|
|
7
|
+
const validation_1 = require("./validation");
|
|
8
|
+
/**
|
|
9
|
+
* Transform a string to camelCase format
|
|
10
|
+
* @category Transformation
|
|
11
|
+
* @function camelify
|
|
12
|
+
* @param str - The string to transform
|
|
13
|
+
* @returns {string} The string in camelCase format
|
|
14
|
+
* @example
|
|
15
|
+
* camelify("hello world"); // "helloWorld"
|
|
16
|
+
* camelify("C'est un test"); // "cestUnTest"
|
|
17
|
+
* camelify("foo bar baz"); // "fooBarBaz"
|
|
18
|
+
*/
|
|
19
|
+
function camelify(str) {
|
|
20
|
+
let camelCased = "";
|
|
21
|
+
if (!(0, validation_1.isEmpty)(str)) {
|
|
22
|
+
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
23
|
+
let toCamelify = cleaned.split(" ");
|
|
24
|
+
camelCased = toCamelify.map((word, index) => {
|
|
25
|
+
if (index === 0)
|
|
26
|
+
return word.toLowerCase();
|
|
27
|
+
return word[0].toUpperCase() + word.slice(1).toLowerCase();
|
|
28
|
+
})
|
|
29
|
+
.join('');
|
|
30
|
+
}
|
|
31
|
+
return camelCased;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Transform a string to kebab-case format
|
|
35
|
+
* @category Transformation
|
|
36
|
+
* @function kebabify
|
|
37
|
+
* @param str - The string to transform
|
|
38
|
+
* @returns {string} The string in kebab-case format
|
|
39
|
+
* @example
|
|
40
|
+
* kebabify("hello world"); // "hello-world"
|
|
41
|
+
* kebabify("C'est un test"); // "ceststun-test"
|
|
42
|
+
* kebabify("foo bar baz"); // "foo-bar-baz"
|
|
43
|
+
*/
|
|
44
|
+
function kebabify(str) {
|
|
45
|
+
let kebabised = "";
|
|
46
|
+
if (!(0, validation_1.isEmpty)(str)) {
|
|
47
|
+
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
48
|
+
let toKebabify = cleaned.split(" ");
|
|
49
|
+
kebabised = toKebabify.map(word => word.toLowerCase())
|
|
50
|
+
.join("-");
|
|
51
|
+
}
|
|
52
|
+
return kebabised;
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Transform a string to snake_case format
|
|
56
|
+
* @category Transformation
|
|
57
|
+
* @function snakify
|
|
58
|
+
* @param str - The string to transform
|
|
59
|
+
* @returns {string} The string in snake_case format
|
|
60
|
+
* @example
|
|
61
|
+
* snakify("hello world"); // "hello_world"
|
|
62
|
+
* snakify("C'est un test"); // "ceststun_test"
|
|
63
|
+
* snakify("foo bar baz"); // "foo_bar_baz"
|
|
64
|
+
*/
|
|
65
|
+
function snakify(str) {
|
|
66
|
+
let snaked = "";
|
|
67
|
+
if (!(0, validation_1.isEmpty)(str)) {
|
|
68
|
+
let cleaned = str.replace(/[^a-zA-Z0-9\s]/g, "");
|
|
69
|
+
let toSnakify = cleaned.split(" ");
|
|
70
|
+
snaked = toSnakify.map(word => word.toLowerCase())
|
|
71
|
+
.join("_");
|
|
72
|
+
}
|
|
73
|
+
return snaked;
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* Capitalize the first character of a string
|
|
77
|
+
* @category Transformation
|
|
78
|
+
* @function capitalize
|
|
79
|
+
* @param str - The string to capitalize
|
|
80
|
+
* @returns {string} The string with the first character in uppercase
|
|
81
|
+
* @example
|
|
82
|
+
* capitalize("hello"); // "Hello"
|
|
83
|
+
* capitalize("hello world"); // "Hello world"
|
|
84
|
+
* capitalize(""); // ""
|
|
85
|
+
*/
|
|
86
|
+
function capitalize(str) {
|
|
87
|
+
if ((0, validation_1.isEmpty)(str))
|
|
88
|
+
return str;
|
|
89
|
+
return str[0].toUpperCase() + str.slice(1);
|
|
90
|
+
}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Check if any type of variable is empty
|
|
3
|
+
* @category Validation
|
|
4
|
+
* @function isEmpty
|
|
5
|
+
* @param value - The variable to check
|
|
6
|
+
* @returns {boolean} True if the value is empty, false otherwise
|
|
7
|
+
* @example
|
|
8
|
+
* isEmpty(""); // true
|
|
9
|
+
* isEmpty(" "); // true
|
|
10
|
+
* isEmpty(null); // true
|
|
11
|
+
* isEmpty([]); // true
|
|
12
|
+
* isEmpty({}); // true
|
|
13
|
+
* isEmpty("hello"); // false
|
|
14
|
+
* isEmpty([1, 2]); // false
|
|
15
|
+
*/
|
|
16
|
+
declare function isEmpty(value: unknown): boolean;
|
|
17
|
+
/**
|
|
18
|
+
* Check if the variable is of the chosen type
|
|
19
|
+
* @category Validation
|
|
20
|
+
* @function isType
|
|
21
|
+
* @param value - The variable to check
|
|
22
|
+
* @param type - The type you want
|
|
23
|
+
* @returns {boolean} True if the value is of the chosen type, false otherwise
|
|
24
|
+
* @example
|
|
25
|
+
* isType("hello", "string"); // true
|
|
26
|
+
* isType(42, "number"); // true
|
|
27
|
+
* isType([], "object"); // true
|
|
28
|
+
* isType("42", "number"); // false
|
|
29
|
+
*/
|
|
30
|
+
declare function isType(value: unknown, type: string): boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Check if an email is valid
|
|
33
|
+
* @category Validation
|
|
34
|
+
* @function isEmail
|
|
35
|
+
* @param email - The email to check
|
|
36
|
+
* @returns {boolean} True if the email is valid, false otherwise
|
|
37
|
+
* @example
|
|
38
|
+
* isEmail("alice@example.com"); // true
|
|
39
|
+
* isEmail("bob.smith@company.co.uk"); // true
|
|
40
|
+
* isEmail("invalid@.com"); // false
|
|
41
|
+
* isEmail("no-at-sign.com"); // false
|
|
42
|
+
*/
|
|
43
|
+
declare function isEmail(email: string): boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Check if a URL is valid
|
|
46
|
+
* @category Validation
|
|
47
|
+
* @function isURL
|
|
48
|
+
* @param url - The URL to check
|
|
49
|
+
* @returns {boolean} True if the URL is valid, false otherwise
|
|
50
|
+
* @example
|
|
51
|
+
* isURL("https://www.example.com"); // true
|
|
52
|
+
* isURL("http://example.com/path"); // true
|
|
53
|
+
* isURL("www.example.com"); // false (missing protocol)
|
|
54
|
+
* isURL("not a url"); // false
|
|
55
|
+
*/
|
|
56
|
+
declare function isURL(url: string): boolean;
|
|
57
|
+
export { isEmpty, isType, isEmail, isURL };
|
|
58
|
+
//# sourceMappingURL=validation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"validation.d.ts","sourceRoot":"","sources":["../src/validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;GAcG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,OAAO,GAAG,OAAO,CAMxC;AAED;;;;;;;;;;;;GAYG;AACH,iBAAS,MAAM,CAAC,KAAK,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAErD;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,OAAO,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO,CAGvC;AAED;;;;;;;;;;;GAWG;AACH,iBAAS,KAAK,CAAC,GAAG,EAAE,MAAM,GAAG,OAAO,CAOnC;AAED,OAAO,EAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,KAAK,EAAC,CAAC"}
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.isEmpty = isEmpty;
|
|
4
|
+
exports.isType = isType;
|
|
5
|
+
exports.isEmail = isEmail;
|
|
6
|
+
exports.isURL = isURL;
|
|
7
|
+
/**
|
|
8
|
+
* Check if any type of variable is empty
|
|
9
|
+
* @category Validation
|
|
10
|
+
* @function isEmpty
|
|
11
|
+
* @param value - The variable to check
|
|
12
|
+
* @returns {boolean} True if the value is empty, false otherwise
|
|
13
|
+
* @example
|
|
14
|
+
* isEmpty(""); // true
|
|
15
|
+
* isEmpty(" "); // true
|
|
16
|
+
* isEmpty(null); // true
|
|
17
|
+
* isEmpty([]); // true
|
|
18
|
+
* isEmpty({}); // true
|
|
19
|
+
* isEmpty("hello"); // false
|
|
20
|
+
* isEmpty([1, 2]); // false
|
|
21
|
+
*/
|
|
22
|
+
function isEmpty(value) {
|
|
23
|
+
if (value === null || value === undefined)
|
|
24
|
+
return true;
|
|
25
|
+
if (typeof value === "string")
|
|
26
|
+
return value.trim().length === 0;
|
|
27
|
+
if (Array.isArray(value))
|
|
28
|
+
return value.length === 0;
|
|
29
|
+
if (typeof value === "object")
|
|
30
|
+
return Object.keys(value).length === 0;
|
|
31
|
+
return false;
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Check if the variable is of the chosen type
|
|
35
|
+
* @category Validation
|
|
36
|
+
* @function isType
|
|
37
|
+
* @param value - The variable to check
|
|
38
|
+
* @param type - The type you want
|
|
39
|
+
* @returns {boolean} True if the value is of the chosen type, false otherwise
|
|
40
|
+
* @example
|
|
41
|
+
* isType("hello", "string"); // true
|
|
42
|
+
* isType(42, "number"); // true
|
|
43
|
+
* isType([], "object"); // true
|
|
44
|
+
* isType("42", "number"); // false
|
|
45
|
+
*/
|
|
46
|
+
function isType(value, type) {
|
|
47
|
+
return typeof value === type;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Check if an email is valid
|
|
51
|
+
* @category Validation
|
|
52
|
+
* @function isEmail
|
|
53
|
+
* @param email - The email to check
|
|
54
|
+
* @returns {boolean} True if the email is valid, false otherwise
|
|
55
|
+
* @example
|
|
56
|
+
* isEmail("alice@example.com"); // true
|
|
57
|
+
* isEmail("bob.smith@company.co.uk"); // true
|
|
58
|
+
* isEmail("invalid@.com"); // false
|
|
59
|
+
* isEmail("no-at-sign.com"); // false
|
|
60
|
+
*/
|
|
61
|
+
function isEmail(email) {
|
|
62
|
+
const regex = /^[a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}$/;
|
|
63
|
+
return regex.test(email);
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Check if a URL is valid
|
|
67
|
+
* @category Validation
|
|
68
|
+
* @function isURL
|
|
69
|
+
* @param url - The URL to check
|
|
70
|
+
* @returns {boolean} True if the URL is valid, false otherwise
|
|
71
|
+
* @example
|
|
72
|
+
* isURL("https://www.example.com"); // true
|
|
73
|
+
* isURL("http://example.com/path"); // true
|
|
74
|
+
* isURL("www.example.com"); // false (missing protocol)
|
|
75
|
+
* isURL("not a url"); // false
|
|
76
|
+
*/
|
|
77
|
+
function isURL(url) {
|
|
78
|
+
try {
|
|
79
|
+
new URL(url);
|
|
80
|
+
return true;
|
|
81
|
+
}
|
|
82
|
+
catch (error) {
|
|
83
|
+
return false;
|
|
84
|
+
}
|
|
85
|
+
}
|
package/package.json
CHANGED