lolite.invert 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 +23 -0
- package/crash.js +21 -0
- package/index.js +31 -0
- package/isNotInteger.js +20 -0
- package/multiplyFallback.js +1 -0
- package/package.json +44 -0
- package/subtract.js +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
# lolite.invert
|
|
2
|
+
|
|
3
|
+
### invert(value)
|
|
4
|
+
Inverts the sign of a value. Zero becomes negative zero.
|
|
5
|
+
Non-numeric values are coerced to zero.
|
|
6
|
+
Infinity is negated to -Infinity, and vice versa.
|
|
7
|
+
|
|
8
|
+
```javascript
|
|
9
|
+
const invert = require("lolite.invert")
|
|
10
|
+
const inverted = invert(10)
|
|
11
|
+
// inverted: -10
|
|
12
|
+
|
|
13
|
+
const doubleNegative = invert(-5)
|
|
14
|
+
// result: 5
|
|
15
|
+
|
|
16
|
+
const negativeInfinity = invert(Infinity)
|
|
17
|
+
// result: -Infinity
|
|
18
|
+
|
|
19
|
+
const coercedNegative = invert("garbage")
|
|
20
|
+
// result: -0 (0 inverted)
|
|
21
|
+
```
|
|
22
|
+
|
|
23
|
+
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,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,44 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lolite.invert",
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "Enterprise-grade invert 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
|
+
"lodash.multiply": "^4.9.0",
|
|
18
|
+
"immediate-error": "^7.1.0",
|
|
19
|
+
"integer-values": "^2.0.0",
|
|
20
|
+
"is-not-integer": "^1.0.2",
|
|
21
|
+
"logtoconsole": "^1.0.7",
|
|
22
|
+
"@not-js/not": "^1.1.0",
|
|
23
|
+
"es-logical-not-operator": "^1.0.0",
|
|
24
|
+
"is-integer": "^1.0.7",
|
|
25
|
+
"literally": "^1.0.0",
|
|
26
|
+
"not-not": "^1.0.2",
|
|
27
|
+
"yanoop": "^1.0.0",
|
|
28
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
29
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
30
|
+
"@positive-numbers/one": "^3.0.0",
|
|
31
|
+
"@positive-numbers/zero": "^3.0.0",
|
|
32
|
+
"construct-new": "^2.0.4",
|
|
33
|
+
"countingup": "^0.3.0",
|
|
34
|
+
"false-value": "^2.0.6",
|
|
35
|
+
"iszero": "^1.0.0",
|
|
36
|
+
"pkg-with-failing-optional-dependency": "^1.0.1",
|
|
37
|
+
"subtract": "^0.0.3",
|
|
38
|
+
"while2": "^2.0.2",
|
|
39
|
+
"add-two-numbers2": "^1.0.0",
|
|
40
|
+
"infinities": "^1.0.1",
|
|
41
|
+
"is-negative-zero": "^2.0.3",
|
|
42
|
+
"positive-zero": "^3.0.0"
|
|
43
|
+
}
|
|
44
|
+
}
|
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
|