@alextheman/utility 2.1.0 → 2.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +19 -2
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +18 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -48,6 +48,7 @@ __export(index_exports, {
|
|
|
48
48
|
APIError: () => APIError_default,
|
|
49
49
|
addDaysToDate: () => addDaysToDate_default,
|
|
50
50
|
appendSemicolon: () => appendSemicolon_default,
|
|
51
|
+
camelToKebab: () => camelToKebab_default,
|
|
51
52
|
convertFileToBase64: () => convertFileToBase64_default,
|
|
52
53
|
fillArray: () => fillArray_default,
|
|
53
54
|
formatDateAndTime: () => formatDateAndTime_default,
|
|
@@ -91,6 +92,12 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
91
92
|
}
|
|
92
93
|
var appendSemicolon_default = appendSemicolon;
|
|
93
94
|
|
|
95
|
+
// src/functions/camelToKebab.ts
|
|
96
|
+
function camelToKebab(string) {
|
|
97
|
+
return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
98
|
+
}
|
|
99
|
+
var camelToKebab_default = camelToKebab;
|
|
100
|
+
|
|
94
101
|
// src/functions/convertFileToBase64.ts
|
|
95
102
|
function convertFileToBase64(file) {
|
|
96
103
|
return new Promise((resolve, reject) => {
|
|
@@ -216,15 +223,24 @@ function omitProperties(object, keysToOmit) {
|
|
|
216
223
|
var omitProperties_default = omitProperties;
|
|
217
224
|
|
|
218
225
|
// src/functions/parseIntStrict.ts
|
|
226
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
219
227
|
function parseIntStrict(string, radix) {
|
|
220
228
|
const trimmedString = string.trim();
|
|
221
229
|
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
222
230
|
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
223
231
|
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
224
232
|
) : /^[+-]?\d+$/;
|
|
233
|
+
if (!pattern.test(trimmedString)) {
|
|
234
|
+
throw IntegerParsingError;
|
|
235
|
+
}
|
|
236
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
237
|
+
return parseInt(character) >= radix;
|
|
238
|
+
})) {
|
|
239
|
+
throw IntegerParsingError;
|
|
240
|
+
}
|
|
225
241
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
226
|
-
if (isNaN(parseIntResult)
|
|
227
|
-
throw
|
|
242
|
+
if (isNaN(parseIntResult)) {
|
|
243
|
+
throw IntegerParsingError;
|
|
228
244
|
}
|
|
229
245
|
return parseIntResult;
|
|
230
246
|
}
|
|
@@ -365,6 +381,7 @@ var UUID_default = parseUUID;
|
|
|
365
381
|
APIError,
|
|
366
382
|
addDaysToDate,
|
|
367
383
|
appendSemicolon,
|
|
384
|
+
camelToKebab,
|
|
368
385
|
convertFileToBase64,
|
|
369
386
|
fillArray,
|
|
370
387
|
formatDateAndTime,
|
package/dist/index.d.cts
CHANGED
|
@@ -4,6 +4,8 @@ declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
|
4
4
|
|
|
5
5
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
6
6
|
|
|
7
|
+
declare function camelToKebab(string: string): string;
|
|
8
|
+
|
|
7
9
|
declare function convertFileToBase64(file: File): Promise<string>;
|
|
8
10
|
|
|
9
11
|
declare function fillArray<T>(callback: (index: number) => T | Promise<T>, length?: number): T[] | Promise<T[]>;
|
|
@@ -62,4 +64,4 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
62
64
|
|
|
63
65
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
64
66
|
|
|
65
|
-
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCodes, type NonUndefined, type UUID, addDaysToDate, appendSemicolon, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, stringToBoolean, truncate, wait };
|
|
67
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCodes, type NonUndefined, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, stringToBoolean, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -4,6 +4,8 @@ declare function addDaysToDate(currentDate?: Date, dayIncrement?: number): Date;
|
|
|
4
4
|
|
|
5
5
|
declare function appendSemicolon(stringToAppendTo: string): string;
|
|
6
6
|
|
|
7
|
+
declare function camelToKebab(string: string): string;
|
|
8
|
+
|
|
7
9
|
declare function convertFileToBase64(file: File): Promise<string>;
|
|
8
10
|
|
|
9
11
|
declare function fillArray<T>(callback: (index: number) => T | Promise<T>, length?: number): T[] | Promise<T[]>;
|
|
@@ -62,4 +64,4 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
62
64
|
|
|
63
65
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
64
66
|
|
|
65
|
-
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCodes, type NonUndefined, type UUID, addDaysToDate, appendSemicolon, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, stringToBoolean, truncate, wait };
|
|
67
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCodes, type NonUndefined, type UUID, addDaysToDate, appendSemicolon, camelToKebab, convertFileToBase64, fillArray, formatDateAndTime, getRandomNumber, httpErrorCodeLookup, interpolateObjects, isLeapYear, isMonthlyMultiple, isSameDate, omitProperties, parseEmail, parseEnv, parseIntStrict, parseUUID, randomiseArray, range, stringToBoolean, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -37,6 +37,12 @@ function appendSemicolon(stringToAppendTo) {
|
|
|
37
37
|
}
|
|
38
38
|
var appendSemicolon_default = appendSemicolon;
|
|
39
39
|
|
|
40
|
+
// src/functions/camelToKebab.ts
|
|
41
|
+
function camelToKebab(string) {
|
|
42
|
+
return string.replace(/([a-z0-9])([A-Z])/g, "$1-$2").replace(/([A-Z])([A-Z][a-z])/g, "$1-$2").toLowerCase();
|
|
43
|
+
}
|
|
44
|
+
var camelToKebab_default = camelToKebab;
|
|
45
|
+
|
|
40
46
|
// src/functions/convertFileToBase64.ts
|
|
41
47
|
function convertFileToBase64(file) {
|
|
42
48
|
return new Promise((resolve, reject) => {
|
|
@@ -162,15 +168,24 @@ function omitProperties(object, keysToOmit) {
|
|
|
162
168
|
var omitProperties_default = omitProperties;
|
|
163
169
|
|
|
164
170
|
// src/functions/parseIntStrict.ts
|
|
171
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
165
172
|
function parseIntStrict(string, radix) {
|
|
166
173
|
const trimmedString = string.trim();
|
|
167
174
|
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
168
175
|
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
169
176
|
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
170
177
|
) : /^[+-]?\d+$/;
|
|
178
|
+
if (!pattern.test(trimmedString)) {
|
|
179
|
+
throw IntegerParsingError;
|
|
180
|
+
}
|
|
181
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
182
|
+
return parseInt(character) >= radix;
|
|
183
|
+
})) {
|
|
184
|
+
throw IntegerParsingError;
|
|
185
|
+
}
|
|
171
186
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
172
|
-
if (isNaN(parseIntResult)
|
|
173
|
-
throw
|
|
187
|
+
if (isNaN(parseIntResult)) {
|
|
188
|
+
throw IntegerParsingError;
|
|
174
189
|
}
|
|
175
190
|
return parseIntResult;
|
|
176
191
|
}
|
|
@@ -310,6 +325,7 @@ export {
|
|
|
310
325
|
APIError_default as APIError,
|
|
311
326
|
addDaysToDate_default as addDaysToDate,
|
|
312
327
|
appendSemicolon_default as appendSemicolon,
|
|
328
|
+
camelToKebab_default as camelToKebab,
|
|
313
329
|
convertFileToBase64_default as convertFileToBase64,
|
|
314
330
|
fillArray_default as fillArray,
|
|
315
331
|
formatDateAndTime_default as formatDateAndTime,
|