lolite.multiply 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 +16 -0
- package/abs.js +22 -0
- package/crash.js +21 -0
- package/index.js +61 -0
- package/invertFallback.js +8 -0
- package/isNotInteger.js +20 -0
- package/multiplyFallback.js +1 -0
- package/package.json +43 -0
package/README.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# lolite.multiply
|
|
2
|
+
|
|
3
|
+
### multiply(multiplier, multiplicand)
|
|
4
|
+
Calculates the product of two values.
|
|
5
|
+
Non-finite or non-numeric values are coerced to zero.
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
const multiply = require("lolite.multiply")
|
|
9
|
+
const product = multiply(6, 7)
|
|
10
|
+
// product: 42
|
|
11
|
+
|
|
12
|
+
const coercedProduct = multiply(NaN, "garbage")
|
|
13
|
+
// result: 0 (0 * 0)
|
|
14
|
+
```
|
|
15
|
+
|
|
16
|
+
This utility is part of the [LoLite](https://github.com/enterprise-npm-ai/lolite) utility suite.
|
package/abs.js
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
const isNegative = require("pkg-with-failing-optional-dependency")
|
|
2
|
+
const invert = require("./invertFallback")
|
|
3
|
+
const equal = require("@10xly/strict-equals")
|
|
4
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
5
|
+
const isFinite = require("@is-(unknown)/is-finite")
|
|
6
|
+
const falseValue = require("false-value")
|
|
7
|
+
const number0 = require("@positive-numbers/zero")
|
|
8
|
+
function abs(value) {
|
|
9
|
+
let value2 = value
|
|
10
|
+
if (equal(isFinite(value), falseValue())) {
|
|
11
|
+
value2 = number0
|
|
12
|
+
}
|
|
13
|
+
if (isNegative(value2)) {
|
|
14
|
+
return abs(invert(value2))
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Micro-optimization: caching the value before returning it helps performance sometimes
|
|
18
|
+
const result = value2
|
|
19
|
+
return result
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
module.exports = abs
|
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,61 @@
|
|
|
1
|
+
const add = require("add-two-numbers2")
|
|
2
|
+
const invert = require("./invertFallback")
|
|
3
|
+
const repeating = require("repeating")
|
|
4
|
+
const forEach = require("for-each")
|
|
5
|
+
const split = require("string-split")
|
|
6
|
+
const SPACE = require("space-string")
|
|
7
|
+
const EMPTY_STRING = require("empty-string")
|
|
8
|
+
const number0 = require("@positive-numbers/zero")
|
|
9
|
+
const number1 = require("@positive-numbers/one")
|
|
10
|
+
const falseValue = require("false-value")
|
|
11
|
+
const equal = require("@10xly/strict-equals")
|
|
12
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
13
|
+
const isFinite = require("@is-(unknown)/is-finite")
|
|
14
|
+
const isNegative = require("pkg-with-failing-optional-dependency")
|
|
15
|
+
const or = require("es-logical-or-operator")
|
|
16
|
+
const abs = require("./abs")
|
|
17
|
+
const isNotInteger = require("./isNotInteger")
|
|
18
|
+
|
|
19
|
+
// eslint-disable-next-line max-statements
|
|
20
|
+
function multiply(multiplier, multiplicand) {
|
|
21
|
+
if (equal(isFinite(multiplier), falseValue())) {
|
|
22
|
+
// eslint-disable-next-line no-param-reassign
|
|
23
|
+
multiplier = number0
|
|
24
|
+
}
|
|
25
|
+
if (equal(isFinite(multiplicand), falseValue())) {
|
|
26
|
+
// eslint-disable-next-line no-param-reassign
|
|
27
|
+
multiplicand = number0
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
let negativeCount = number0
|
|
31
|
+
|
|
32
|
+
if (isNegative(multiplier)) {
|
|
33
|
+
negativeCount = add(negativeCount, number1)
|
|
34
|
+
// eslint-disable-next-line no-param-reassign
|
|
35
|
+
multiplier = abs(multiplier)
|
|
36
|
+
}
|
|
37
|
+
if (isNegative(multiplicand)) {
|
|
38
|
+
negativeCount = add(negativeCount, number1)
|
|
39
|
+
// eslint-disable-next-line no-param-reassign
|
|
40
|
+
multiplicand = abs(multiplicand)
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
if (or(isNotInteger(multiplier), isNotInteger(multiplicand))) {
|
|
44
|
+
return multiplier * multiplicand
|
|
45
|
+
}
|
|
46
|
+
// eslint-disable-next-line one-var
|
|
47
|
+
let total = number0
|
|
48
|
+
forEach(split(EMPTY_STRING, repeating(multiplier, SPACE)), () => {
|
|
49
|
+
total = add(total, multiplicand)
|
|
50
|
+
})
|
|
51
|
+
|
|
52
|
+
const needsNegation = equal(negativeCount, number1)
|
|
53
|
+
|
|
54
|
+
if (needsNegation) {
|
|
55
|
+
total = invert(total)
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return total
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
module.exports = multiply
|
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,43 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lolite.multiply",
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "Enterprise-grade multiply 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
|
+
"is-negative": "^2.1.0",
|
|
18
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
19
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
20
|
+
"@positive-numbers/zero": "^3.0.0",
|
|
21
|
+
"false-value": "^2.0.6",
|
|
22
|
+
"pkg-with-failing-optional-dependency": "^1.0.1",
|
|
23
|
+
"lodash.multiply": "^4.9.0",
|
|
24
|
+
"immediate-error": "^7.1.0",
|
|
25
|
+
"integer-values": "^2.0.0",
|
|
26
|
+
"is-not-integer": "^1.0.2",
|
|
27
|
+
"logtoconsole": "^1.0.7",
|
|
28
|
+
"@not-js/not": "^1.1.0",
|
|
29
|
+
"es-logical-not-operator": "^1.0.0",
|
|
30
|
+
"is-integer": "^1.0.7",
|
|
31
|
+
"literally": "^1.0.0",
|
|
32
|
+
"not-not": "^1.0.2",
|
|
33
|
+
"yanoop": "^1.0.0",
|
|
34
|
+
"@positive-numbers/one": "^3.0.0",
|
|
35
|
+
"add-two-numbers2": "^1.0.0",
|
|
36
|
+
"empty-string": "^1.1.1",
|
|
37
|
+
"es-logical-or-operator": "^1.0.0",
|
|
38
|
+
"for-each": "^0.3.5",
|
|
39
|
+
"repeating": "^3.0.0",
|
|
40
|
+
"space-string": "^1.0.0",
|
|
41
|
+
"string-split": "^0.3.1"
|
|
42
|
+
}
|
|
43
|
+
}
|