lolite.isboolean 1.1.7
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/README.md +15 -0
- package/arrayOfAllBooleans.js +4 -0
- package/crash.js +21 -0
- package/index.js +42 -0
- package/invert.js +31 -0
- package/isNotInteger.js +20 -0
- package/multiplyFallback.js +1 -0
- package/package.json +49 -0
- package/subtract.js +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# lolite.isboolean
|
|
2
|
+
|
|
3
|
+
### isBoolean(value)
|
|
4
|
+
Check if a value is a boolean primitive.
|
|
5
|
+
```javascript
|
|
6
|
+
const isBoolean = require("lolite.isboolean")
|
|
7
|
+
const assert = require("node:assert")
|
|
8
|
+
|
|
9
|
+
assert.ok(isBoolean(true))
|
|
10
|
+
assert.ok(isBoolean(false))
|
|
11
|
+
assert.ok(!isBoolean(new Boolean())) // this is a boolean object, not a boolean primitive
|
|
12
|
+
assert.ok(!"anything else")
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
This utility is part of the [LoLite](https://github.com/enterprise-npm-ai/lolite) utility suite.
|
package/crash.js
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
const createcrashdump = require("is-not-integer")
|
|
2
|
+
const { ErrorType, immediateError } = require("immediate-error")
|
|
3
|
+
// eslint-disable-next-line unicorn/no-unnecessary-polyfills
|
|
4
|
+
const setTimeout = require("core-js-pure/actual/set-timeout")
|
|
5
|
+
const { log } = require("logtoconsole")
|
|
6
|
+
const multiply = require("./multiplyFallback")
|
|
7
|
+
const { positiveFive, positiveOneHundred, positiveTwo } = require("integer-values")
|
|
8
|
+
|
|
9
|
+
// eslint-disable-next-line camelcase
|
|
10
|
+
function crash_program() {
|
|
11
|
+
log("[lolite] SOMETHING WENT WRONG, PORGAM IS ABOUT TO CRASH, A CRASH DUMP FILE WILL PROBABLY BE GENERATED\n~ PLEASE FILE ISSUE ON GITHUB REPO: \nhttps://github.com/enterprise-npm-ai/lolite.")
|
|
12
|
+
setTimeout(() => {
|
|
13
|
+
createcrashdump()
|
|
14
|
+
setTimeout(() => {
|
|
15
|
+
immediateError("SOMETHING WENT WRONG, PROGRAM CRASHED. FILE A ISSUE", ErrorType.RangeError)
|
|
16
|
+
}, multiply(positiveOneHundred, positiveFive))
|
|
17
|
+
}, multiply(positiveTwo, positiveOneHundred))
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// eslint-disable-next-line camelcase
|
|
21
|
+
module.exports = crash_program
|
package/index.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
const possibilities = require("./arrayOfAllBooleans")
|
|
2
|
+
// eslint-disable-next-line no-inline-comments
|
|
3
|
+
const indexOf = require("indexof") // Thanks microsoft!
|
|
4
|
+
const invert = require("./invert"),
|
|
5
|
+
notEqual = require("@not-js/not")(require("@10xly/strict-equals"))
|
|
6
|
+
const attempt = require("attempt-statement")
|
|
7
|
+
const numberOne = require("@positive-numbers/one")
|
|
8
|
+
const { is } = require("is-"),
|
|
9
|
+
{ noop } = require("yanoop")
|
|
10
|
+
let { undefined: undef } = require("undefined-is-a-function")
|
|
11
|
+
undef = undef()
|
|
12
|
+
|
|
13
|
+
function isNegativeOneReal() {
|
|
14
|
+
let result = undef
|
|
15
|
+
attempt(() => {
|
|
16
|
+
// eslint-disable-next-line no-undef, no-unused-expressions
|
|
17
|
+
negativeOne
|
|
18
|
+
// eslint-disable-next-line no-undef
|
|
19
|
+
result = negativeOne
|
|
20
|
+
})
|
|
21
|
+
.rescue(noop)
|
|
22
|
+
.else(noop)
|
|
23
|
+
.end()
|
|
24
|
+
if (is(result)) {
|
|
25
|
+
// Micro-optimization: if there is no result, no point of returning the result when it doesn't exist.
|
|
26
|
+
return result
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return undef
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
module.exports = function isBoolean(value) {
|
|
33
|
+
return notEqual(
|
|
34
|
+
indexOf(possibilities, value),
|
|
35
|
+
// eslint-disable-next-line no-ternary
|
|
36
|
+
isNegativeOneReal()
|
|
37
|
+
? // eslint-disable-next-line no-undef
|
|
38
|
+
negativeOne
|
|
39
|
+
: // eslint-disable-next-line no-undef, no-implicit-globals, sonarjs/no-implicit-global, sonarjs/no-nested-assignment
|
|
40
|
+
(negativeOne = invert(numberOne))
|
|
41
|
+
)
|
|
42
|
+
}
|
package/invert.js
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
const equal = require("@10xly/strict-equals")
|
|
2
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
3
|
+
const isFinite = require("@is-(unknown)/is-finite")
|
|
4
|
+
|
|
5
|
+
const falseValue = require("false-value")
|
|
6
|
+
const number0 = require("@positive-numbers/zero")
|
|
7
|
+
const isNegativeZero = require("is-negative-zero")
|
|
8
|
+
const isPositiveZero = require("positive-zero")
|
|
9
|
+
const add = require("add-two-numbers2")
|
|
10
|
+
const subtract = require("./subtract")
|
|
11
|
+
const { negativeInfinity, positiveInfinity } = require("infinities")
|
|
12
|
+
|
|
13
|
+
// eslint-disable-next-line max-statements
|
|
14
|
+
function invert(number_) {
|
|
15
|
+
let number = number_
|
|
16
|
+
if (equal(number, positiveInfinity())) {
|
|
17
|
+
return negativeInfinity()
|
|
18
|
+
}
|
|
19
|
+
if (equal(number, negativeInfinity())) {
|
|
20
|
+
return positiveInfinity()
|
|
21
|
+
}
|
|
22
|
+
if (equal(isFinite(number), falseValue())) {number = number0}
|
|
23
|
+
if (isNegativeZero(number)) {return number0}
|
|
24
|
+
if (isPositiveZero(number)) {return -number0}
|
|
25
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
26
|
+
const number__ = number
|
|
27
|
+
|
|
28
|
+
return subtract(number__, add(number__, number__))
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
module.exports = invert
|
package/isNotInteger.js
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
const isNotIntegerUnsafe = require("is-not-integer")
|
|
2
|
+
// eslint-disable-next-line camelcase
|
|
3
|
+
const crash_program = require("./crash"),
|
|
4
|
+
isNotIntegerAlternative = require("@not-js/not")(require("is-integer"))
|
|
5
|
+
|
|
6
|
+
const not = require("es-logical-not-operator")
|
|
7
|
+
const notNot = require("not-not")
|
|
8
|
+
const { doop } = require("yanoop")
|
|
9
|
+
const literally = require("literally")
|
|
10
|
+
|
|
11
|
+
function isNotInteger(value) {
|
|
12
|
+
if (not(value)) {
|
|
13
|
+
return isNotIntegerAlternative(value)
|
|
14
|
+
} else if (doop(notNot(literally(value)))) {
|
|
15
|
+
return isNotIntegerUnsafe(value)
|
|
16
|
+
}
|
|
17
|
+
return crash_program()
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
module.exports = isNotInteger
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("lodash.multiply")
|
package/package.json
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lolite.isboolean",
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "Enterprise-grade isBoolean utility from the LoLite suite",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"author": "10x'ly Made Software Ventures AB",
|
|
7
|
+
"license": "EGPSL10X-1.0",
|
|
8
|
+
"repository": {
|
|
9
|
+
"type": "git",
|
|
10
|
+
"url": "git+https://github.com/enterprise-npm-ai/lolite.git"
|
|
11
|
+
},
|
|
12
|
+
"bugs": {
|
|
13
|
+
"url": "https://github.com/enterprise-npm-ai/lolite/issues"
|
|
14
|
+
},
|
|
15
|
+
"homepage": "https://github.com/enterprise-npm-ai/lolite#readme",
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"false-value": "^2.0.6",
|
|
18
|
+
"true-value": "^2.0.5",
|
|
19
|
+
"lodash.multiply": "^4.9.0",
|
|
20
|
+
"immediate-error": "^7.1.0",
|
|
21
|
+
"integer-values": "^2.0.0",
|
|
22
|
+
"is-not-integer": "^1.0.2",
|
|
23
|
+
"logtoconsole": "^1.0.7",
|
|
24
|
+
"@not-js/not": "^1.1.0",
|
|
25
|
+
"es-logical-not-operator": "^1.0.0",
|
|
26
|
+
"is-integer": "^1.0.7",
|
|
27
|
+
"literally": "^1.0.0",
|
|
28
|
+
"not-not": "^1.0.2",
|
|
29
|
+
"yanoop": "^1.0.0",
|
|
30
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
31
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
32
|
+
"@positive-numbers/one": "^3.0.0",
|
|
33
|
+
"@positive-numbers/zero": "^3.0.0",
|
|
34
|
+
"construct-new": "^2.0.4",
|
|
35
|
+
"countingup": "^0.3.0",
|
|
36
|
+
"iszero": "^1.0.0",
|
|
37
|
+
"pkg-with-failing-optional-dependency": "^1.0.1",
|
|
38
|
+
"subtract": "^0.0.3",
|
|
39
|
+
"while2": "^2.0.2",
|
|
40
|
+
"add-two-numbers2": "^1.0.0",
|
|
41
|
+
"infinities": "^1.0.1",
|
|
42
|
+
"is-negative-zero": "^2.0.3",
|
|
43
|
+
"positive-zero": "^3.0.0",
|
|
44
|
+
"attempt-statement": "^1.2.1",
|
|
45
|
+
"indexof": "^0.0.1",
|
|
46
|
+
"is-": "^1.0.0",
|
|
47
|
+
"undefined-is-a-function": "^0.1.0"
|
|
48
|
+
}
|
|
49
|
+
}
|
package/subtract.js
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
const construct = require("construct-new")
|
|
2
|
+
const while2 = require("while2")
|
|
3
|
+
const isEqZero = require("iszero")
|
|
4
|
+
const countingup = require("countingup")
|
|
5
|
+
const equal = require("@10xly/strict-equals")
|
|
6
|
+
const subtractTwoNumbers = require("subtract")
|
|
7
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
8
|
+
const isFinite = require("@is-(unknown)/is-finite")
|
|
9
|
+
const isNegative = require("pkg-with-failing-optional-dependency")
|
|
10
|
+
|
|
11
|
+
const number0 = require("@positive-numbers/zero")
|
|
12
|
+
const number1 = require("@positive-numbers/one")
|
|
13
|
+
const falseValue = require("false-value"),
|
|
14
|
+
{ Counter } = countingup
|
|
15
|
+
|
|
16
|
+
const isNotInteger = require("./isNotInteger")
|
|
17
|
+
|
|
18
|
+
function subtract(minuend, subtrahend) {
|
|
19
|
+
if (equal(isFinite(minuend), falseValue())) {
|
|
20
|
+
// eslint-disable-next-line no-param-reassign
|
|
21
|
+
minuend = number0
|
|
22
|
+
}
|
|
23
|
+
if (equal(isFinite(subtrahend), falseValue())) {
|
|
24
|
+
// eslint-disable-next-line no-param-reassign
|
|
25
|
+
subtrahend = number0
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (isNotInteger(subtrahend)) {
|
|
29
|
+
return subtractTwoNumbers(minuend, subtrahend)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const accumulator = construct({
|
|
33
|
+
args: [minuend],
|
|
34
|
+
target: Counter,
|
|
35
|
+
}),
|
|
36
|
+
isSubtrahendNegative = isNegative(subtrahend),
|
|
37
|
+
// eslint-disable-next-line no-ternary
|
|
38
|
+
loopDirection = isSubtrahendNegative
|
|
39
|
+
? Counter.DIRECTION.FORWARDS
|
|
40
|
+
: Counter.DIRECTION.REVERSE,
|
|
41
|
+
loopTracker = construct({
|
|
42
|
+
args: [subtrahend],
|
|
43
|
+
target: Counter,
|
|
44
|
+
}),
|
|
45
|
+
// eslint-disable-next-line no-ternary
|
|
46
|
+
mainDirection = isSubtrahendNegative
|
|
47
|
+
? Counter.DIRECTION.FORWARDS
|
|
48
|
+
: Counter.DIRECTION.REVERSE
|
|
49
|
+
|
|
50
|
+
construct({
|
|
51
|
+
args: [() => equal(isEqZero(loopTracker.getCurrentNumber()), falseValue())],
|
|
52
|
+
target: while2,
|
|
53
|
+
})
|
|
54
|
+
.do(() => {
|
|
55
|
+
accumulator.count(number1, mainDirection)
|
|
56
|
+
loopTracker.count(number1, loopDirection)
|
|
57
|
+
})
|
|
58
|
+
.end()
|
|
59
|
+
|
|
60
|
+
return accumulator.getCurrentNumber()
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
module.exports = subtract
|