@alextheman/utility 2.1.0 → 2.1.1
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 +11 -2
- package/dist/index.js +11 -2
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -216,15 +216,24 @@ function omitProperties(object, keysToOmit) {
|
|
|
216
216
|
var omitProperties_default = omitProperties;
|
|
217
217
|
|
|
218
218
|
// src/functions/parseIntStrict.ts
|
|
219
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
219
220
|
function parseIntStrict(string, radix) {
|
|
220
221
|
const trimmedString = string.trim();
|
|
221
222
|
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
222
223
|
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
223
224
|
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
224
225
|
) : /^[+-]?\d+$/;
|
|
226
|
+
if (!pattern.test(trimmedString)) {
|
|
227
|
+
throw IntegerParsingError;
|
|
228
|
+
}
|
|
229
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
230
|
+
return parseInt(character) >= radix;
|
|
231
|
+
})) {
|
|
232
|
+
throw IntegerParsingError;
|
|
233
|
+
}
|
|
225
234
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
226
|
-
if (isNaN(parseIntResult)
|
|
227
|
-
throw
|
|
235
|
+
if (isNaN(parseIntResult)) {
|
|
236
|
+
throw IntegerParsingError;
|
|
228
237
|
}
|
|
229
238
|
return parseIntResult;
|
|
230
239
|
}
|
package/dist/index.js
CHANGED
|
@@ -162,15 +162,24 @@ function omitProperties(object, keysToOmit) {
|
|
|
162
162
|
var omitProperties_default = omitProperties;
|
|
163
163
|
|
|
164
164
|
// src/functions/parseIntStrict.ts
|
|
165
|
+
var IntegerParsingError = new TypeError("INTEGER_PARSING_ERROR");
|
|
165
166
|
function parseIntStrict(string, radix) {
|
|
166
167
|
const trimmedString = string.trim();
|
|
167
168
|
const pattern = radix && radix > 10 && radix <= 36 ? (
|
|
168
169
|
// String.fromCharCode() gets the maximum possible alphabetical character for a base above 10
|
|
169
170
|
new RegExp(`^[+-]?[0-9a-${String.fromCharCode(87 + radix - 1)}]+$`, "i")
|
|
170
171
|
) : /^[+-]?\d+$/;
|
|
172
|
+
if (!pattern.test(trimmedString)) {
|
|
173
|
+
throw IntegerParsingError;
|
|
174
|
+
}
|
|
175
|
+
if (radix && radix < 10 && [...trimmedString].some((character) => {
|
|
176
|
+
return parseInt(character) >= radix;
|
|
177
|
+
})) {
|
|
178
|
+
throw IntegerParsingError;
|
|
179
|
+
}
|
|
171
180
|
const parseIntResult = parseInt(trimmedString, radix);
|
|
172
|
-
if (isNaN(parseIntResult)
|
|
173
|
-
throw
|
|
181
|
+
if (isNaN(parseIntResult)) {
|
|
182
|
+
throw IntegerParsingError;
|
|
174
183
|
}
|
|
175
184
|
return parseIntResult;
|
|
176
185
|
}
|