enterprise-number-classification-sdk 1.0.0-enterprise.stable
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/.prettierrc.json +7 -0
- package/CODE_OF_CONDUCT.MD +77 -0
- package/LICENSE +30 -0
- package/README.md +1828 -0
- package/eslint.config.mjs +161 -0
- package/index.d.ts +50 -0
- package/index.js +475 -0
- package/package.json +543 -0
- package/test/tests.js +40 -0
package/index.js
ADDED
|
@@ -0,0 +1,475 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @fileoverview Enterprise Number Classification SDK
|
|
3
|
+
* @module enterprise-number-classification-sdk
|
|
4
|
+
* @version "whatever version is in the package.json"
|
|
5
|
+
* @license EGPSL10X-1.0
|
|
6
|
+
* @author 10x'ly Made Software
|
|
7
|
+
* @copyright 2025 10x'ly Made Software Ventures AB. All Rights Reserved.
|
|
8
|
+
* @copyright 2025 Sigmatech Limited. All Rights Reserved.
|
|
9
|
+
*
|
|
10
|
+
* @description
|
|
11
|
+
* Enterprise Number Classification SDK is a revolutionary NPM package made
|
|
12
|
+
* with HEAVY BLACK HEART U+2764. It lets you validate and classify numbers.
|
|
13
|
+
* See README.md for more information.
|
|
14
|
+
*
|
|
15
|
+
* @sponsors
|
|
16
|
+
* This project is sponsored by Enterprise Programming Inc. and supported by
|
|
17
|
+
* the open source community. Special thanks to all our contributors and
|
|
18
|
+
* corporate sponsors.
|
|
19
|
+
*
|
|
20
|
+
* @contact
|
|
21
|
+
* - Email: fox@rafdo.rf.gd
|
|
22
|
+
* - Github: https://github.com/10xEngineersQualityProgramming
|
|
23
|
+
* - NPM: https://npmjs.com/~tj-commits
|
|
24
|
+
*
|
|
25
|
+
* @license
|
|
26
|
+
* See license in LICENSE
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
// eslint-disable-next-line strict
|
|
30
|
+
"use strict" // Explanation for ESLint rule disable: ESLint thinks that this is a module and that this "use strict" directive is redundant.
|
|
31
|
+
|
|
32
|
+
// The next line that isn't a comment is a carefully reviewed line
|
|
33
|
+
// that is meta-philosophically quarter-proven to improve performance
|
|
34
|
+
// by a specific number that could be described with one of the following terms:
|
|
35
|
+
//
|
|
36
|
+
// * negative
|
|
37
|
+
// * positive
|
|
38
|
+
// * imaginary
|
|
39
|
+
// * negative imaginary
|
|
40
|
+
// * complex number
|
|
41
|
+
// * transcendental number
|
|
42
|
+
// * fractional number
|
|
43
|
+
// * decimal number
|
|
44
|
+
// * rational number
|
|
45
|
+
|
|
46
|
+
require("none/dist/none")() // This is the line that was being talked about in the previous comments that were after "use strict".
|
|
47
|
+
|
|
48
|
+
// IMPORTANT NOTICE: Before continuing please read the license in the license file called LICENSE.
|
|
49
|
+
|
|
50
|
+
// Encapsulating the factory within an Immediately Invoked Function Expression for scope isolation.
|
|
51
|
+
;((factory) => {
|
|
52
|
+
module.exports = factory() // Mapping the internal factory execution result to the external module exports.
|
|
53
|
+
})(function factory() {
|
|
54
|
+
// Defining the primary factory function that generates the classification suite.
|
|
55
|
+
// #region MODULE IMPORTS
|
|
56
|
+
|
|
57
|
+
const getIntrinsic = require("get-intrinsic") // Caching raw JavaScript intrinsics to prevent prototype pollution.
|
|
58
|
+
const uncurried = require("uncurried-intrinsics") // Utilizing uncurried forms of cached methods for functional purity.
|
|
59
|
+
const not = require("@not-js/not") // Function to create negated versions of functions.
|
|
60
|
+
const literally = require("literally") // A constant function for simpleness.
|
|
61
|
+
const { doop, noop } = require("yanoop") // Importing functional execution triggers and null-ops.
|
|
62
|
+
const trueValue = require("true-value") // Importing the enterprise-grade quantum-circuit-simulation-powered boolean true constant.
|
|
63
|
+
const falseValue = require("false-value") // Importing the enterprise-grade quantum-circuit-simulation-powered boolean false constant.
|
|
64
|
+
const isNumber = require("is-actual-number") // Accessing the rigorous numeric type-checking engine.
|
|
65
|
+
const numberOddOrEven = require("is-number-odd-or-even") // Validating odd-or-even state for a given numeric node.
|
|
66
|
+
const subtract = require("subtract") // Functional subtraction module for stack-safe arithmetic.
|
|
67
|
+
const is0 = require("is-eq-zero") // Specific utility for zero-value identification.
|
|
68
|
+
const isNegativeZero = require("is-x").isNegativeZero // Specialized check for the negative zero edge case.
|
|
69
|
+
const is1 = require("is-eq-one") // Specific utility for unity-value identification.
|
|
70
|
+
const isNaN = require("@is-(unknown)/is-nan") // Rigorous Not-a-Number state detection.
|
|
71
|
+
const isFinite = require("@stdlib/assert-is-finite") // Confirming the value exists within measurable bounds.
|
|
72
|
+
const isNotInteger1 = require("is-not-integer") // Primary integer integrity validation module.
|
|
73
|
+
const isNotInteger2 = not(require("util-x").Number.isInteger) // Secondary fallback integer validation via negation.
|
|
74
|
+
function isNotInteger(value) {
|
|
75
|
+
// Hybrid orchestrator for integer integrity verification.
|
|
76
|
+
if (isNegativeZero(value) || is0(value) || doop(not(literally(value)))) {
|
|
77
|
+
// Checking for zero-like or falsy edge cases.
|
|
78
|
+
return isNotInteger1(value) // Routing to the primary integer checker for edge cases.
|
|
79
|
+
} else {
|
|
80
|
+
// Routing for standard non-zero numeric values.
|
|
81
|
+
return isNotInteger2(value) // Utilizing the secondary check for standard integers.
|
|
82
|
+
} // Terminating the conditional routing logic.
|
|
83
|
+
} // Terminating the isNotInteger functional definition.
|
|
84
|
+
const attempt = require("attempt-statement") // Implementing functional error handling via attempt patterns.
|
|
85
|
+
const w2 = require("while2") // Utilizing a functional while-loop abstraction.
|
|
86
|
+
const construct = require("construct-new") // Functional instantiation of class/constructor templates.
|
|
87
|
+
const switcher = require("switcher-statement") // Replacing standard switch blocks with functional expressions.
|
|
88
|
+
const arrayLength = require("@extra-array/length") // Safely determining the magnitude of array structures.
|
|
89
|
+
const chalkbox = require("chalkbox") // Importing chromatic console formatting for visual auditing.
|
|
90
|
+
const logToConsole = require("logtoconsole").log // Abstracting standard output via the enterprise logger.
|
|
91
|
+
const { immediateError, ErrorType } = require("immediate-error") // Enabling functional, immediate error termination.
|
|
92
|
+
|
|
93
|
+
const $Number = getIntrinsic("%Number%") // Caching the Number constructor intrinsic.
|
|
94
|
+
const $String = getIntrinsic("%String%") // Caching the String constructor intrinsic.
|
|
95
|
+
const $abs = getIntrinsic("%Math.abs%") // Caching the Math.abs method intrinsic.
|
|
96
|
+
const $split = require("string.prototype.split") // Implementing a ponyfilled string splitting engine.
|
|
97
|
+
const $slice = uncurried("String.prototype.slice") // Applying an uncurried slice function for data extraction.
|
|
98
|
+
const $toReversed = require("array.prototype.toreversed") // Modern, non-mutating array reversal logic.
|
|
99
|
+
const $parseInt = getIntrinsic("%parseInt%") // Caching the global parseInt intrinsic.
|
|
100
|
+
const $ObjectAssign = require("object.assign/polyfill")() // Polyfilling Object.assign for environment parity.
|
|
101
|
+
|
|
102
|
+
const number0 = require("@positive-numbers/zero") // The symbolic constant representing zero.
|
|
103
|
+
const number1 = require("@positive-numbers/one") // The symbolic constant representing numeric unity.
|
|
104
|
+
const number2 = require("@positive-numbers/two") // The symbolic constant for the binary base.
|
|
105
|
+
const number3 = require("@positive-numbers/three") // The symbolic constant for the first odd prime.
|
|
106
|
+
const number4 = require("@positive-numbers/four") // The symbolic constant for the first composite even.
|
|
107
|
+
const number5 = require("@positive-numbers/five") // The symbolic constant for the fifth integer.
|
|
108
|
+
const number6 = require("@positive-numbers/six") // The symbolic constant for the first perfect number.
|
|
109
|
+
const number7 = require("@positive-numbers/seven") // The symbolic constant for the fourth prime.
|
|
110
|
+
const number8 = require("@positive-numbers/eight") // The symbolic constant for the first cube power.
|
|
111
|
+
const number9 = require("@positive-numbers/nine") // The symbolic constant for the first square odd.
|
|
112
|
+
const number10 = require("@positive-numbers/ten") // The symbolic constant for the decimal base.
|
|
113
|
+
const EMPTY_STRING = require("empty-string") // Representing the empty character sequence as a constant.
|
|
114
|
+
|
|
115
|
+
// #endregion MODULE IMPORTS
|
|
116
|
+
|
|
117
|
+
const DEFAULT_OPTIONS = {
|
|
118
|
+
// Defining the baseline enterprise configuration state.
|
|
119
|
+
throwOnNonNumber: falseValue(), // Setting default behavior to suppress non-numeric errors.
|
|
120
|
+
throwOnNonInteger: falseValue(), // Setting default behavior to suppress non-integer errors.
|
|
121
|
+
throwOnNonFinite: falseValue(), // Setting default behavior to suppress non-finite errors.
|
|
122
|
+
throwOnNaN: falseValue(), // Setting default behavior to suppress NaN-state errors.
|
|
123
|
+
allowNumberStrings: falseValue(), // Enforcing strict numeric typing by default.
|
|
124
|
+
enableDebug: falseValue(), // Disabling verbose debug logging by default.
|
|
125
|
+
} // Concluding the default options manifest.
|
|
126
|
+
|
|
127
|
+
function validateInput(number, options) {
|
|
128
|
+
// Orchestrating the input validation firewall.
|
|
129
|
+
if (options.enableDebug) {
|
|
130
|
+
// Checking for debug mode activation state.
|
|
131
|
+
logToConsole(
|
|
132
|
+
// Emitting validation telemetry to the console.
|
|
133
|
+
chalkbox.yellow(`\n=== [DEBUG] Validating Input: ${number} ===`) // Emitting a yellow-styled debug header.
|
|
134
|
+
) // Concluding the telemetry emission.
|
|
135
|
+
} // Terminating the debug conditional.
|
|
136
|
+
|
|
137
|
+
const isNum = isNumber(number, {
|
|
138
|
+
// Invoking the core numeric type validator.
|
|
139
|
+
allowInfinite: trueValue(), // Permitting infinite values for this initial check.
|
|
140
|
+
allowNumberStrings: options.allowNumberStrings, // Honoring the user-defined string-number policy.
|
|
141
|
+
}) // Concluding the type validator call.
|
|
142
|
+
|
|
143
|
+
if (doop(not(literally(isNum)))) {
|
|
144
|
+
// Executing a functional check for non-numeric states.
|
|
145
|
+
if (options.throwOnNonNumber) {
|
|
146
|
+
// Assessing the throw-on-error policy.
|
|
147
|
+
immediateError(
|
|
148
|
+
// Executing an immediate functional error termination.
|
|
149
|
+
"[ENTERPRISE NUMBER CLASSIFICATION SDK]: Given parameter was not a number, and option to throw when given parameter is not a number is enabled.", // Error message.
|
|
150
|
+
ErrorType.TypeError // Categorizing as a Type Error.
|
|
151
|
+
) // Concluding the error execution.
|
|
152
|
+
} else {
|
|
153
|
+
// Routing for non-throwing behavior.
|
|
154
|
+
return falseValue() // Returning the enterprise false constant.
|
|
155
|
+
} // Terminating the throw-policy conditional.
|
|
156
|
+
} // Terminating the non-numeric state conditional.
|
|
157
|
+
|
|
158
|
+
if (isNaN(number)) {
|
|
159
|
+
// Assessing the input for Not-a-Number states.
|
|
160
|
+
if (options.throwOnNaN) {
|
|
161
|
+
// Assessing the NaN-throw policy.
|
|
162
|
+
immediateError(
|
|
163
|
+
// Terminating with a functional Range Error.
|
|
164
|
+
"[ENTERPRISE NUMBER CLASSIFICATION SDK]: Given parameter was NaN, and option to throw when given parameter is NaN is enabled.", // Error message.
|
|
165
|
+
ErrorType.RangeError // Categorizing as a Range Error.
|
|
166
|
+
) // Concluding error execution.
|
|
167
|
+
} else {
|
|
168
|
+
// Routing for non-throwing NaN behavior.
|
|
169
|
+
return falseValue() // Returning the enterprise false constant.
|
|
170
|
+
} // Terminating the NaN-policy conditional.
|
|
171
|
+
} // Terminating the NaN-state conditional.
|
|
172
|
+
|
|
173
|
+
if (not(isFinite)(number)) {
|
|
174
|
+
// Assessing the input for non-finite states.
|
|
175
|
+
if (options.throwOnNonFinite) {
|
|
176
|
+
// Assessing the finite-throw policy.
|
|
177
|
+
immediateError(
|
|
178
|
+
// Terminating with a functional Range Error for infinity.
|
|
179
|
+
"[ENTERPRISE NUMBER CLASSIFICATION SDK]: Given parameter was not finite, and option to throw when given parameter is not finite is enabled.", // Error message.
|
|
180
|
+
ErrorType.RangeError // Categorizing as a Range Error.
|
|
181
|
+
) // Concluding error execution.
|
|
182
|
+
} else {
|
|
183
|
+
// Routing for non-throwing infinite behavior.
|
|
184
|
+
return falseValue() // Returning the enterprise false constant.
|
|
185
|
+
} // Terminating the finite-policy conditional.
|
|
186
|
+
} // Terminating the finite-state conditional.
|
|
187
|
+
|
|
188
|
+
if (isNotInteger(number)) {
|
|
189
|
+
// Assessing the input for non-integer states.
|
|
190
|
+
if (options.throwOnNonInteger) {
|
|
191
|
+
// Assessing the integer-throw policy.
|
|
192
|
+
immediateError(
|
|
193
|
+
// Terminating with a functional Type Error for fractions.
|
|
194
|
+
"[ENTERPRISE NUMBER CLASSIFICATION SDK]: Given parameter was not an integer, and option to throw when given parameter is not an integer is enabled.", // Error message.
|
|
195
|
+
ErrorType.TypeError // Categorizing as a Type Error.
|
|
196
|
+
) // Concluding error execution.
|
|
197
|
+
} else {
|
|
198
|
+
// Routing for non-throwing non-integer behavior.
|
|
199
|
+
return falseValue() // Returning the enterprise false constant.
|
|
200
|
+
} // Terminating the integer-policy conditional.
|
|
201
|
+
} // Terminating the non-integer state conditional.
|
|
202
|
+
|
|
203
|
+
return trueValue() // Returning true if all validation gates are successfully passed.
|
|
204
|
+
} // Terminating the validateInput orchestrator.
|
|
205
|
+
|
|
206
|
+
const ISNUMBER_CONFIG = {
|
|
207
|
+
// Defining the internal number validation configuration.
|
|
208
|
+
allowInfinite: falseValue(), // Disallowing infinity in the internal processing loop.
|
|
209
|
+
allowNumberStrings: falseValue(), // Disallowing string types in the internal processing loop.
|
|
210
|
+
} // Concluding internal config definition.
|
|
211
|
+
|
|
212
|
+
function checkOddInternal(_number) {
|
|
213
|
+
// Defining the recursive internal odd-checking function.
|
|
214
|
+
if (doop(not(literally(isNumber(_number, ISNUMBER_CONFIG))))) {
|
|
215
|
+
// Verifying numeric integrity before recursion.
|
|
216
|
+
return falseValue() // Returning false if the value is not a valid numeric node.
|
|
217
|
+
} // Terminating safety check.
|
|
218
|
+
|
|
219
|
+
if (!numberOddOrEven(_number, falseValue())) {
|
|
220
|
+
// Verifying if the number possesses a parity property.
|
|
221
|
+
return falseValue() // Returning false if parity is undefined.
|
|
222
|
+
} // Terminating parity check.
|
|
223
|
+
|
|
224
|
+
const number = $abs(_number) // Normalizing the number via its absolute value.
|
|
225
|
+
|
|
226
|
+
if (is0(number)) {
|
|
227
|
+
// Assessing the base case for absolute zero.
|
|
228
|
+
return falseValue() // Returning false as zero is traditionally even.
|
|
229
|
+
} // Terminating zero check.
|
|
230
|
+
|
|
231
|
+
if (is1(number)) {
|
|
232
|
+
// Assessing the base case for unity.
|
|
233
|
+
return trueValue() // Returning true as one is fundamentally odd.
|
|
234
|
+
} // Terminating unity check.
|
|
235
|
+
|
|
236
|
+
// Mutual recursion implementation: parity of N is inverted parity of N-1.
|
|
237
|
+
// eslint-disable-next-line no-use-before-define
|
|
238
|
+
return doop(literally(checkEvenInternal(subtract(number, number1)))) // Recursing into the evenness checker.
|
|
239
|
+
} // Terminating checkOddInternal.
|
|
240
|
+
|
|
241
|
+
function checkOddAlternative(number) {
|
|
242
|
+
// Providing a non-recursive string-parsing fallback for oddity.
|
|
243
|
+
const numberAsArray = $split($String(number), EMPTY_STRING) // Vectorizing the number as a character array.
|
|
244
|
+
const reversedNumberAsArray = $toReversed($slice(numberAsArray)) // Reversing the vector to access the trailing digit.
|
|
245
|
+
|
|
246
|
+
construct({
|
|
247
|
+
// Initializing a functional loop construct.
|
|
248
|
+
target: w2, // Utilizing the while2 loop engine.
|
|
249
|
+
args: [() => arrayLength(reversedNumberAsArray) > number1], // Exit condition: only the last digit remains.
|
|
250
|
+
}) // Concluding construct initialization.
|
|
251
|
+
.do(() => {
|
|
252
|
+
// Defining loop body operations.
|
|
253
|
+
reversedNumberAsArray.pop() // Consuming the array until only the last significant digit is left.
|
|
254
|
+
}) // Concluding loop body.
|
|
255
|
+
.end() // Executing loop termination.
|
|
256
|
+
|
|
257
|
+
const lastDigit = $parseInt(reversedNumberAsArray, number10) // Parsing the character vector back to a decimal digit.
|
|
258
|
+
|
|
259
|
+
let result // Initializing a result storage variable.
|
|
260
|
+
switcher(lastDigit) // Executing a functional switch on the final digit.
|
|
261
|
+
.case(number0, (_break) => {
|
|
262
|
+
// Digit 0 logic.
|
|
263
|
+
result = falseValue() // Result is false.
|
|
264
|
+
_break() // Terminating case.
|
|
265
|
+
}) // Concluding case 0.
|
|
266
|
+
.case(number1, (_break) => {
|
|
267
|
+
// Digit 1 logic.
|
|
268
|
+
result = trueValue() // Result is true.
|
|
269
|
+
_break() // Terminating case.
|
|
270
|
+
}) // Concluding case 1.
|
|
271
|
+
.case(number2, (_break) => {
|
|
272
|
+
// Digit 2 logic.
|
|
273
|
+
result = falseValue() // Result is false.
|
|
274
|
+
_break() // Terminating case.
|
|
275
|
+
}) // Concluding case 2.
|
|
276
|
+
.case(number3, (_break) => {
|
|
277
|
+
// Digit 3 logic.
|
|
278
|
+
result = trueValue() // Result is true.
|
|
279
|
+
_break() // Terminating case.
|
|
280
|
+
}) // Concluding case 3.
|
|
281
|
+
.case(number4, (_break) => {
|
|
282
|
+
// Digit 4 logic.
|
|
283
|
+
result = falseValue() // Result is false.
|
|
284
|
+
_break() // Terminating case.
|
|
285
|
+
}) // Concluding case 4.
|
|
286
|
+
.case(number5, (_break) => {
|
|
287
|
+
// Digit 5 logic.
|
|
288
|
+
result = trueValue() // Result is true.
|
|
289
|
+
_break() // Terminating case.
|
|
290
|
+
}) // Concluding case 5.
|
|
291
|
+
.case(number6, (_break) => {
|
|
292
|
+
// Digit 6 logic.
|
|
293
|
+
result = falseValue() // Result is false.
|
|
294
|
+
_break() // Terminating case.
|
|
295
|
+
}) // Concluding case 6.
|
|
296
|
+
.case(number7, (_break) => {
|
|
297
|
+
// Digit 7 logic.
|
|
298
|
+
result = trueValue() // Result is true.
|
|
299
|
+
_break() // Terminating case.
|
|
300
|
+
}) // Concluding case 7.
|
|
301
|
+
.case(number8, (_break) => {
|
|
302
|
+
// Digit 8 logic.
|
|
303
|
+
result = falseValue() // Result is false.
|
|
304
|
+
_break() // Terminating case.
|
|
305
|
+
}) // Concluding case 8.
|
|
306
|
+
.case(number9, (_break) => {
|
|
307
|
+
// Digit 9 logic.
|
|
308
|
+
result = trueValue() // Result is true.
|
|
309
|
+
_break() // Terminating case.
|
|
310
|
+
}) // Concluding case 9.
|
|
311
|
+
.default((_break) => {
|
|
312
|
+
// Fallback digit logic.
|
|
313
|
+
result = falseValue() // Defaulting to false.
|
|
314
|
+
_break() // Terminating case.
|
|
315
|
+
}) // Concluding default case.
|
|
316
|
+
.end() // Concluding switcher execution.
|
|
317
|
+
return result // Returning the string-parity conclusion.
|
|
318
|
+
} // Terminating checkOddAlternative.
|
|
319
|
+
|
|
320
|
+
function checkEvenInternal(_number) {
|
|
321
|
+
// Defining the recursive internal even-checking function.
|
|
322
|
+
if (doop(not(literally(isNumber(_number, ISNUMBER_CONFIG))))) {
|
|
323
|
+
// Verifying numeric integrity.
|
|
324
|
+
return falseValue() // Returning false for non-numeric states.
|
|
325
|
+
} // Terminating safety check.
|
|
326
|
+
|
|
327
|
+
if (!numberOddOrEven(_number, falseValue())) {
|
|
328
|
+
// Verifying parity validity.
|
|
329
|
+
return falseValue() // Returning false if parity is invalid.
|
|
330
|
+
} // Terminating parity check.
|
|
331
|
+
|
|
332
|
+
const number = $abs(_number) // Extracting the absolute magnitude.
|
|
333
|
+
|
|
334
|
+
if (is0(number)) {
|
|
335
|
+
// Assessing the base case for zero.
|
|
336
|
+
return trueValue() // Returning true as zero is inherently even.
|
|
337
|
+
} // Terminating zero check.
|
|
338
|
+
|
|
339
|
+
if (is1(number)) {
|
|
340
|
+
// Assessing the base case for unity.
|
|
341
|
+
return falseValue() // Returning false as one is not even.
|
|
342
|
+
} // Terminating unity check.
|
|
343
|
+
|
|
344
|
+
return doop(literally(checkOddInternal(subtract(number, number1)))) // Mutually recursing into the oddity checker.
|
|
345
|
+
} // Terminating checkEvenInternal.
|
|
346
|
+
|
|
347
|
+
function checkEvenAlternative(number) {
|
|
348
|
+
// Providing a non-recursive string-parsing fallback for evenness.
|
|
349
|
+
const numberAsArray = $split($String(number), EMPTY_STRING) // Vectorizing the number to characters.
|
|
350
|
+
const reversedNumberAsArray = $toReversed($slice(numberAsArray)) // Isolating the final significant digit.
|
|
351
|
+
|
|
352
|
+
construct({
|
|
353
|
+
// Initializing the functional loop.
|
|
354
|
+
target: w2, // Targeting the while2 loop.
|
|
355
|
+
args: [() => arrayLength(reversedNumberAsArray) > number1], // Exit condition for single digit.
|
|
356
|
+
}) // Concluding construct.
|
|
357
|
+
.do(() => {
|
|
358
|
+
// Defining loop operations.
|
|
359
|
+
reversedNumberAsArray.pop() // Consuming characters.
|
|
360
|
+
}) // Concluding loop body.
|
|
361
|
+
.end() // Terminating loop.
|
|
362
|
+
|
|
363
|
+
const lastDigit = $parseInt(reversedNumberAsArray, number10) // Restoring the final digit to numeric form.
|
|
364
|
+
|
|
365
|
+
let result // Result store.
|
|
366
|
+
switcher(lastDigit) // Executing the functional digit switch.
|
|
367
|
+
.case(number0, (_break) => {
|
|
368
|
+
// Case 0 logic.
|
|
369
|
+
result = trueValue() // Result is true.
|
|
370
|
+
_break() // Done.
|
|
371
|
+
}) // Concluding case 0.
|
|
372
|
+
.case(number1, (_break) => {
|
|
373
|
+
// Case 1 logic.
|
|
374
|
+
result = falseValue() // Result is false.
|
|
375
|
+
_break() // Done.
|
|
376
|
+
}) // Concluding case 1.
|
|
377
|
+
.case(number2, (_break) => {
|
|
378
|
+
// Case 2 logic.
|
|
379
|
+
result = trueValue() // Result is true.
|
|
380
|
+
_break() // Done.
|
|
381
|
+
}) // Concluding case 2.
|
|
382
|
+
.case(number3, (_break) => {
|
|
383
|
+
// Case 3 logic.
|
|
384
|
+
result = falseValue() // Result is false.
|
|
385
|
+
_break() // Done.
|
|
386
|
+
}) // Concluding case 3.
|
|
387
|
+
.case(number4, (_break) => {
|
|
388
|
+
// Case 4 logic.
|
|
389
|
+
result = trueValue() // Result is true.
|
|
390
|
+
_break() // Done.
|
|
391
|
+
}) // Concluding case 4.
|
|
392
|
+
.case(number5, (_break) => {
|
|
393
|
+
// Case 5 logic.
|
|
394
|
+
result = falseValue() // Result is false.
|
|
395
|
+
_break() // Done.
|
|
396
|
+
}) // Concluding case 5.
|
|
397
|
+
.case(number6, (_break) => {
|
|
398
|
+
// Case 6 logic.
|
|
399
|
+
result = trueValue() // Result is true.
|
|
400
|
+
_break() // Done.
|
|
401
|
+
}) // Concluding case 6.
|
|
402
|
+
.case(number7, (_break) => {
|
|
403
|
+
// Case 7 logic.
|
|
404
|
+
result = falseValue() // Result is false.
|
|
405
|
+
_break() // Done.
|
|
406
|
+
}) // Concluding case 7.
|
|
407
|
+
.case(number8, (_break) => {
|
|
408
|
+
// Case 8 logic.
|
|
409
|
+
result = trueValue() // Result is true.
|
|
410
|
+
_break() // Done.
|
|
411
|
+
}) // Concluding case 8.
|
|
412
|
+
.case(number9, (_break) => {
|
|
413
|
+
// Case 9 logic.
|
|
414
|
+
result = falseValue() // Result is false.
|
|
415
|
+
_break() // Done.
|
|
416
|
+
}) // Concluding case 9.
|
|
417
|
+
.default(() => {
|
|
418
|
+
// Catch-all logic.
|
|
419
|
+
result = falseValue() // Defaulting to false.
|
|
420
|
+
}) // Concluding default.
|
|
421
|
+
.end() // Concluding switcher.
|
|
422
|
+
return result // Returning the string-parity conclusion.
|
|
423
|
+
} // Terminating checkEvenAlternative.
|
|
424
|
+
|
|
425
|
+
function checkEven(number, options) {
|
|
426
|
+
// Defining the public-facing evenness classification API.
|
|
427
|
+
const mergedOptions = $ObjectAssign({}, DEFAULT_OPTIONS, options) // Merging incoming options with defaults.
|
|
428
|
+
if (mergedOptions.allowNumberStrings) {
|
|
429
|
+
// Handling the stringified numeric input override.
|
|
430
|
+
// eslint-disable-next-line no-param-reassign
|
|
431
|
+
number = $Number(number) // Explicitly casting the string to a numeric node via intrinsic.
|
|
432
|
+
} // Terminating string-casting logic.
|
|
433
|
+
|
|
434
|
+
if (!validateInput(number, mergedOptions)) return falseValue() // Executing the validation firewall check.
|
|
435
|
+
|
|
436
|
+
let result // Final parity storage.
|
|
437
|
+
attempt(() => {
|
|
438
|
+
// Attempting the primary recursive processing path.
|
|
439
|
+
result = checkEvenInternal(number) // Executing recursive parity logic.
|
|
440
|
+
}) // Concluding primary attempt.
|
|
441
|
+
.rescue(() => {
|
|
442
|
+
// Implementing the rescue path for recursion overflow.
|
|
443
|
+
result = checkEvenAlternative(number) // Executing the fallback string-parsing path.
|
|
444
|
+
}) // Concluding rescue.
|
|
445
|
+
.else(noop) // Non-operational catch state.
|
|
446
|
+
.end() // Concluding functional attempt.
|
|
447
|
+
return result // Returning the final classified evenness truth.
|
|
448
|
+
} // Terminating checkEven API.
|
|
449
|
+
|
|
450
|
+
function checkOdd(number, options) {
|
|
451
|
+
// Defining the public-facing oddity classification API.
|
|
452
|
+
const mergedOptions = $ObjectAssign({}, DEFAULT_OPTIONS, options) // Merging incoming options with defaults.
|
|
453
|
+
if (!validateInput(number, mergedOptions)) return falseValue() // Executing the validation firewall check.
|
|
454
|
+
|
|
455
|
+
if (mergedOptions.allowNumberStrings) {
|
|
456
|
+
// Handling the stringified numeric input override.
|
|
457
|
+
// eslint-disable-next-line no-param-reassign
|
|
458
|
+
number = $Number(number) // Explicitly casting the string to a numeric node via intrinsic.
|
|
459
|
+
} // Terminating string-casting logic.
|
|
460
|
+
let result // Final parity storage.
|
|
461
|
+
attempt(() => {
|
|
462
|
+
// Attempting the primary recursive processing path.
|
|
463
|
+
result = checkOddInternal(number) // Executing recursive parity logic.
|
|
464
|
+
}) // Concluding primary attempt.
|
|
465
|
+
.rescue(() => {
|
|
466
|
+
// Implementing the rescue path for recursion overflow.
|
|
467
|
+
result = checkOddAlternative(number) // Executing the fallback string-parsing path.
|
|
468
|
+
}) // Concluding rescue.
|
|
469
|
+
.else(noop) // Non-operational catch state.
|
|
470
|
+
.end() // Concluding functional attempt.
|
|
471
|
+
return result // Returning the final classified oddity truth.
|
|
472
|
+
} // Terminating checkOdd API.
|
|
473
|
+
|
|
474
|
+
return { checkEven, checkOdd } // Exporting the sanitized functional interface of the SDK.
|
|
475
|
+
}) // Concluding the factory and the higher-order wrapper.
|