@alextheman/utility 2.5.0 → 2.7.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 +43 -32
- package/dist/index.d.cts +8 -2
- package/dist/index.d.ts +8 -2
- package/dist/index.js +42 -32
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -66,6 +66,7 @@ __export(index_exports, {
|
|
|
66
66
|
randomiseArray: () => randomiseArray_default,
|
|
67
67
|
range: () => range_default,
|
|
68
68
|
removeDuplicates: () => removeDuplicates_default,
|
|
69
|
+
stringListToArray: () => stringListToArray_default,
|
|
69
70
|
stringToBoolean: () => stringToBoolean_default,
|
|
70
71
|
truncate: () => truncate_default,
|
|
71
72
|
wait: () => wait_default
|
|
@@ -157,21 +158,42 @@ function formatDateAndTime(inputDate) {
|
|
|
157
158
|
}
|
|
158
159
|
var formatDateAndTime_default = formatDateAndTime;
|
|
159
160
|
|
|
161
|
+
// src/functions/parseIntStrict.ts
|
|
162
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
163
|
+
function parseIntStrict(...[string, radix]) {
|
|
164
|
+
const trimmedString = string.trim();
|
|
165
|
+
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
166
|
+
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
167
|
+
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
168
|
+
) : /^[+-]?\d+$/;
|
|
169
|
+
if (!pattern.test(trimmedString)) {
|
|
170
|
+
throw IntegerParsingError;
|
|
171
|
+
}
|
|
172
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
173
|
+
return parseInt(character) >= radix;
|
|
174
|
+
})) {
|
|
175
|
+
throw IntegerParsingError;
|
|
176
|
+
}
|
|
177
|
+
const parseIntResult = parseInt(trimmedString, radix);
|
|
178
|
+
if (isNaN(parseIntResult)) {
|
|
179
|
+
throw IntegerParsingError;
|
|
180
|
+
}
|
|
181
|
+
return parseIntResult;
|
|
182
|
+
}
|
|
183
|
+
var parseIntStrict_default = parseIntStrict;
|
|
184
|
+
|
|
160
185
|
// src/functions/getRandomNumber.ts
|
|
161
186
|
function getRandomNumber(lowerBound, upperBound) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
|
|
187
|
+
const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
|
|
188
|
+
const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
|
|
189
|
+
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
166
190
|
}
|
|
167
191
|
var getRandomNumber_default = getRandomNumber;
|
|
168
192
|
|
|
169
193
|
// src/functions/isLeapYear.ts
|
|
170
194
|
function isLeapYear(year) {
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
}
|
|
174
|
-
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
195
|
+
const parsedYear = parseIntStrict_default(`${year}`);
|
|
196
|
+
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
175
197
|
}
|
|
176
198
|
var isLeapYear_default = isLeapYear;
|
|
177
199
|
|
|
@@ -223,30 +245,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
223
245
|
}
|
|
224
246
|
var omitProperties_default = omitProperties;
|
|
225
247
|
|
|
226
|
-
// src/functions/parseIntStrict.ts
|
|
227
|
-
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
228
|
-
function parseIntStrict(string, radix) {
|
|
229
|
-
const trimmedString = string.trim();
|
|
230
|
-
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
231
|
-
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
232
|
-
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
233
|
-
) : /^[+-]?\d+$/;
|
|
234
|
-
if (!pattern.test(trimmedString)) {
|
|
235
|
-
throw IntegerParsingError;
|
|
236
|
-
}
|
|
237
|
-
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
238
|
-
return parseInt(character) >= radix;
|
|
239
|
-
})) {
|
|
240
|
-
throw IntegerParsingError;
|
|
241
|
-
}
|
|
242
|
-
const parseIntResult = parseInt(trimmedString, radix);
|
|
243
|
-
if (isNaN(parseIntResult)) {
|
|
244
|
-
throw IntegerParsingError;
|
|
245
|
-
}
|
|
246
|
-
return parseIntResult;
|
|
247
|
-
}
|
|
248
|
-
var parseIntStrict_default = parseIntStrict;
|
|
249
|
-
|
|
250
248
|
// src/functions/randomiseArray.ts
|
|
251
249
|
function randomiseArray(array) {
|
|
252
250
|
const mutableArray = [...array];
|
|
@@ -295,6 +293,18 @@ function removeDuplicates(array) {
|
|
|
295
293
|
}
|
|
296
294
|
var removeDuplicates_default = removeDuplicates;
|
|
297
295
|
|
|
296
|
+
// src/functions/stringListToArray.ts
|
|
297
|
+
function stringListToArray(stringList, { separator = ",", trimWhitespace = true } = {}) {
|
|
298
|
+
if (trimWhitespace && stringList.trim() === "") {
|
|
299
|
+
return [];
|
|
300
|
+
}
|
|
301
|
+
const arrayList = stringList.split(separator != null ? separator : "");
|
|
302
|
+
return trimWhitespace ? arrayList.map((item) => {
|
|
303
|
+
return item.trim();
|
|
304
|
+
}) : arrayList;
|
|
305
|
+
}
|
|
306
|
+
var stringListToArray_default = stringListToArray;
|
|
307
|
+
|
|
298
308
|
// src/functions/stringToBoolean.ts
|
|
299
309
|
function stringToBoolean(inputString) {
|
|
300
310
|
const normalisedString = inputString.toLowerCase();
|
|
@@ -412,6 +422,7 @@ var UUID_default = parseUUID;
|
|
|
412
422
|
randomiseArray,
|
|
413
423
|
range,
|
|
414
424
|
removeDuplicates,
|
|
425
|
+
stringListToArray,
|
|
415
426
|
stringToBoolean,
|
|
416
427
|
truncate,
|
|
417
428
|
wait
|
package/dist/index.d.cts
CHANGED
|
@@ -22,7 +22,7 @@ declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
|
22
22
|
|
|
23
23
|
declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
|
|
24
24
|
|
|
25
|
-
declare function parseIntStrict(string
|
|
25
|
+
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
26
26
|
|
|
27
27
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
28
28
|
|
|
@@ -30,6 +30,12 @@ declare function range(start: number, stop: number, step?: number): number[];
|
|
|
30
30
|
|
|
31
31
|
declare function removeDuplicates<T>(array: T[] | readonly T[]): T[];
|
|
32
32
|
|
|
33
|
+
interface StringListToArrayOptions {
|
|
34
|
+
separator?: string;
|
|
35
|
+
trimWhitespace?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare function stringListToArray(stringList: string, { separator, trimWhitespace }?: StringListToArrayOptions): string[];
|
|
38
|
+
|
|
33
39
|
declare function stringToBoolean(inputString: string): boolean;
|
|
34
40
|
|
|
35
41
|
declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
@@ -68,4 +74,4 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
68
74
|
|
|
69
75
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
70
76
|
|
|
71
|
-
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, 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, removeDuplicates, stringToBoolean, truncate, wait };
|
|
77
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, 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, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
|
package/dist/index.d.ts
CHANGED
|
@@ -22,7 +22,7 @@ declare function isSameDate(firstDate: Date, secondDate: Date): boolean;
|
|
|
22
22
|
|
|
23
23
|
declare function omitProperties<T extends Record<string, unknown> | Readonly<Record<string, unknown>>, K extends keyof T>(object: T, keysToOmit: K | readonly K[]): Omit<T, K>;
|
|
24
24
|
|
|
25
|
-
declare function parseIntStrict(string
|
|
25
|
+
declare function parseIntStrict(...[string, radix]: Parameters<typeof parseInt>): number;
|
|
26
26
|
|
|
27
27
|
declare function randomiseArray<T>(array: T[]): T[];
|
|
28
28
|
|
|
@@ -30,6 +30,12 @@ declare function range(start: number, stop: number, step?: number): number[];
|
|
|
30
30
|
|
|
31
31
|
declare function removeDuplicates<T>(array: T[] | readonly T[]): T[];
|
|
32
32
|
|
|
33
|
+
interface StringListToArrayOptions {
|
|
34
|
+
separator?: string;
|
|
35
|
+
trimWhitespace?: boolean;
|
|
36
|
+
}
|
|
37
|
+
declare function stringListToArray(stringList: string, { separator, trimWhitespace }?: StringListToArrayOptions): string[];
|
|
38
|
+
|
|
33
39
|
declare function stringToBoolean(inputString: string): boolean;
|
|
34
40
|
|
|
35
41
|
declare function truncate(stringToTruncate: string, maxLength?: number): string;
|
|
@@ -68,4 +74,4 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
68
74
|
|
|
69
75
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
70
76
|
|
|
71
|
-
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, 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, removeDuplicates, stringToBoolean, truncate, wait };
|
|
77
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, 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, removeDuplicates, stringListToArray, stringToBoolean, truncate, wait };
|
package/dist/index.js
CHANGED
|
@@ -101,21 +101,42 @@ function formatDateAndTime(inputDate) {
|
|
|
101
101
|
}
|
|
102
102
|
var formatDateAndTime_default = formatDateAndTime;
|
|
103
103
|
|
|
104
|
+
// src/functions/parseIntStrict.ts
|
|
105
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
106
|
+
function parseIntStrict(...[string, radix]) {
|
|
107
|
+
const trimmedString = string.trim();
|
|
108
|
+
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
109
|
+
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
110
|
+
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
111
|
+
) : /^[+-]?\d+$/;
|
|
112
|
+
if (!pattern.test(trimmedString)) {
|
|
113
|
+
throw IntegerParsingError;
|
|
114
|
+
}
|
|
115
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
116
|
+
return parseInt(character) >= radix;
|
|
117
|
+
})) {
|
|
118
|
+
throw IntegerParsingError;
|
|
119
|
+
}
|
|
120
|
+
const parseIntResult = parseInt(trimmedString, radix);
|
|
121
|
+
if (isNaN(parseIntResult)) {
|
|
122
|
+
throw IntegerParsingError;
|
|
123
|
+
}
|
|
124
|
+
return parseIntResult;
|
|
125
|
+
}
|
|
126
|
+
var parseIntStrict_default = parseIntStrict;
|
|
127
|
+
|
|
104
128
|
// src/functions/getRandomNumber.ts
|
|
105
129
|
function getRandomNumber(lowerBound, upperBound) {
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
return Math.floor(Math.random() * (upperBound - lowerBound + 1) + lowerBound);
|
|
130
|
+
const parsedLowerBound = parseIntStrict_default(`${lowerBound}`);
|
|
131
|
+
const parsedUpperBound = parseIntStrict_default(`${upperBound}`);
|
|
132
|
+
return Math.floor(Math.random() * (parsedUpperBound - parsedLowerBound + 1) + parsedLowerBound);
|
|
110
133
|
}
|
|
111
134
|
var getRandomNumber_default = getRandomNumber;
|
|
112
135
|
|
|
113
136
|
// src/functions/isLeapYear.ts
|
|
114
137
|
function isLeapYear(year) {
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
}
|
|
118
|
-
return year % 4 === 0 && year % 100 !== 0 || year % 400 === 0;
|
|
138
|
+
const parsedYear = parseIntStrict_default(`${year}`);
|
|
139
|
+
return parsedYear % 4 === 0 && parsedYear % 100 !== 0 || parsedYear % 400 === 0;
|
|
119
140
|
}
|
|
120
141
|
var isLeapYear_default = isLeapYear;
|
|
121
142
|
|
|
@@ -167,30 +188,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
167
188
|
}
|
|
168
189
|
var omitProperties_default = omitProperties;
|
|
169
190
|
|
|
170
|
-
// src/functions/parseIntStrict.ts
|
|
171
|
-
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
172
|
-
function parseIntStrict(string, radix) {
|
|
173
|
-
const trimmedString = string.trim();
|
|
174
|
-
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
175
|
-
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
176
|
-
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
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
|
-
}
|
|
186
|
-
const parseIntResult = parseInt(trimmedString, radix);
|
|
187
|
-
if (isNaN(parseIntResult)) {
|
|
188
|
-
throw IntegerParsingError;
|
|
189
|
-
}
|
|
190
|
-
return parseIntResult;
|
|
191
|
-
}
|
|
192
|
-
var parseIntStrict_default = parseIntStrict;
|
|
193
|
-
|
|
194
191
|
// src/functions/randomiseArray.ts
|
|
195
192
|
function randomiseArray(array) {
|
|
196
193
|
const mutableArray = [...array];
|
|
@@ -239,6 +236,18 @@ function removeDuplicates(array) {
|
|
|
239
236
|
}
|
|
240
237
|
var removeDuplicates_default = removeDuplicates;
|
|
241
238
|
|
|
239
|
+
// src/functions/stringListToArray.ts
|
|
240
|
+
function stringListToArray(stringList, { separator = ",", trimWhitespace = true } = {}) {
|
|
241
|
+
if (trimWhitespace && stringList.trim() === "") {
|
|
242
|
+
return [];
|
|
243
|
+
}
|
|
244
|
+
const arrayList = stringList.split(separator != null ? separator : "");
|
|
245
|
+
return trimWhitespace ? arrayList.map((item) => {
|
|
246
|
+
return item.trim();
|
|
247
|
+
}) : arrayList;
|
|
248
|
+
}
|
|
249
|
+
var stringListToArray_default = stringListToArray;
|
|
250
|
+
|
|
242
251
|
// src/functions/stringToBoolean.ts
|
|
243
252
|
function stringToBoolean(inputString) {
|
|
244
253
|
const normalisedString = inputString.toLowerCase();
|
|
@@ -355,6 +364,7 @@ export {
|
|
|
355
364
|
randomiseArray_default as randomiseArray,
|
|
356
365
|
range_default as range,
|
|
357
366
|
removeDuplicates_default as removeDuplicates,
|
|
367
|
+
stringListToArray_default as stringListToArray,
|
|
358
368
|
stringToBoolean_default as stringToBoolean,
|
|
359
369
|
truncate_default as truncate,
|
|
360
370
|
wait_default as wait
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@alextheman/utility",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "Helpful utility functions",
|
|
5
5
|
"license": "ISC",
|
|
6
6
|
"author": "alextheman",
|
|
@@ -36,20 +36,20 @@
|
|
|
36
36
|
"zod": "^4.1.12"
|
|
37
37
|
},
|
|
38
38
|
"devDependencies": {
|
|
39
|
-
"@alextheman/eslint-plugin": "^2.
|
|
40
|
-
"@eslint/js": "^9.
|
|
41
|
-
"@types/node": "^24.9.
|
|
42
|
-
"eslint": "^9.
|
|
39
|
+
"@alextheman/eslint-plugin": "^2.4.1",
|
|
40
|
+
"@eslint/js": "^9.39.0",
|
|
41
|
+
"@types/node": "^24.9.2",
|
|
42
|
+
"eslint": "^9.39.0",
|
|
43
43
|
"eslint-import-resolver-typescript": "^4.4.4",
|
|
44
44
|
"eslint-plugin-import": "^2.32.0",
|
|
45
45
|
"globals": "^16.4.0",
|
|
46
46
|
"husky": "^9.1.7",
|
|
47
|
-
"jsdom": "^27.0
|
|
47
|
+
"jsdom": "^27.1.0",
|
|
48
48
|
"prettier": "^3.6.2",
|
|
49
49
|
"tsup": "^8.5.0",
|
|
50
50
|
"typescript": "^5.9.3",
|
|
51
51
|
"typescript-eslint": "^8.46.2",
|
|
52
52
|
"vite-tsconfig-paths": "^5.1.4",
|
|
53
|
-
"vitest": "^4.0.
|
|
53
|
+
"vitest": "^4.0.6"
|
|
54
54
|
}
|
|
55
55
|
}
|