@alextheman/utility 2.6.0 → 2.8.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 +29 -32
- package/dist/index.d.cts +4 -2
- package/dist/index.d.ts +4 -2
- package/dist/index.js +29 -32
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -158,21 +158,42 @@ function formatDateAndTime(inputDate) {
|
|
|
158
158
|
}
|
|
159
159
|
var formatDateAndTime_default = formatDateAndTime;
|
|
160
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
|
+
|
|
161
185
|
// src/functions/getRandomNumber.ts
|
|
162
186
|
function getRandomNumber(lowerBound, upperBound) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
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);
|
|
167
190
|
}
|
|
168
191
|
var getRandomNumber_default = getRandomNumber;
|
|
169
192
|
|
|
170
193
|
// src/functions/isLeapYear.ts
|
|
171
194
|
function isLeapYear(year) {
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
}
|
|
175
|
-
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;
|
|
176
197
|
}
|
|
177
198
|
var isLeapYear_default = isLeapYear;
|
|
178
199
|
|
|
@@ -224,30 +245,6 @@ function omitProperties(object, keysToOmit) {
|
|
|
224
245
|
}
|
|
225
246
|
var omitProperties_default = omitProperties;
|
|
226
247
|
|
|
227
|
-
// src/functions/parseIntStrict.ts
|
|
228
|
-
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
229
|
-
function parseIntStrict(string, radix) {
|
|
230
|
-
const trimmedString = string.trim();
|
|
231
|
-
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
232
|
-
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
233
|
-
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
234
|
-
) : /^[+-]?\d+$/;
|
|
235
|
-
if (!pattern.test(trimmedString)) {
|
|
236
|
-
throw IntegerParsingError;
|
|
237
|
-
}
|
|
238
|
-
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
239
|
-
return parseInt(character) >= radix;
|
|
240
|
-
})) {
|
|
241
|
-
throw IntegerParsingError;
|
|
242
|
-
}
|
|
243
|
-
const parseIntResult = parseInt(trimmedString, radix);
|
|
244
|
-
if (isNaN(parseIntResult)) {
|
|
245
|
-
throw IntegerParsingError;
|
|
246
|
-
}
|
|
247
|
-
return parseIntResult;
|
|
248
|
-
}
|
|
249
|
-
var parseIntStrict_default = parseIntStrict;
|
|
250
|
-
|
|
251
248
|
// src/functions/randomiseArray.ts
|
|
252
249
|
function randomiseArray(array) {
|
|
253
250
|
const mutableArray = [...array];
|
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
|
|
|
@@ -74,4 +74,6 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
74
74
|
|
|
75
75
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
type OptionalOnCondition<Condition extends boolean, T> = Condition extends true ? T : T | undefined;
|
|
78
|
+
|
|
79
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, 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
|
|
|
@@ -74,4 +74,6 @@ type DisallowUndefined<T> = undefined extends T ? ["Error: Generic type cannot i
|
|
|
74
74
|
|
|
75
75
|
type NonUndefined<T> = T extends undefined ? never : T;
|
|
76
76
|
|
|
77
|
-
|
|
77
|
+
type OptionalOnCondition<Condition extends boolean, T> = Condition extends true ? T : T | undefined;
|
|
78
|
+
|
|
79
|
+
export { APIError, type DisallowUndefined, type Email, type Env, type HTTPErrorCode, type HTTPErrorCodes, type NonUndefined, type OptionalOnCondition, 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];
|