lolite.floor 1.1.6
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 +17 -0
- package/crash.js +21 -0
- package/index.js +35 -0
- package/isNotInteger.js +20 -0
- package/multiplyFallback.js +1 -0
- package/package.json +33 -0
- package/subtract.js +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
# lolite.floor
|
|
2
|
+
|
|
3
|
+
### floor(value)
|
|
4
|
+
Round a number down to the nearest whole integer.
|
|
5
|
+
Non-finite or non-numeric values are coerced to zero.
|
|
6
|
+
|
|
7
|
+
```javascript
|
|
8
|
+
const lolite = require("lolite")
|
|
9
|
+
const positiveResult = floor(2.1)
|
|
10
|
+
// result: 2
|
|
11
|
+
|
|
12
|
+
const negativeResult = floor(-2.1)
|
|
13
|
+
// result: 3
|
|
14
|
+
|
|
15
|
+
const coercedResult = floor("garbage")
|
|
16
|
+
// result: 0 (0 floored)
|
|
17
|
+
```
|
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,35 @@
|
|
|
1
|
+
const subtract = require("./subtract")
|
|
2
|
+
const isInteger = require("is-integer")
|
|
3
|
+
const isNotNegative = require("is-not-negative")
|
|
4
|
+
const split = require("string-split")
|
|
5
|
+
const toStr = require("to-str")
|
|
6
|
+
const number1 = require("@positive-numbers/one")
|
|
7
|
+
const $Number = require("es-intrinsic-cache")("Number"),
|
|
8
|
+
number0 = require("@positive-numbers/zero")
|
|
9
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing
|
|
10
|
+
const isFinite = require("@is-(unknown)/is-finite")
|
|
11
|
+
const falseValue = require("false-value")
|
|
12
|
+
const equal = require("@10xly/strict-equals")
|
|
13
|
+
|
|
14
|
+
function floor(value) {
|
|
15
|
+
// eslint-disable-next-line no-underscore-dangle
|
|
16
|
+
let value_ = value
|
|
17
|
+
if (equal(isFinite(value_), falseValue())) {
|
|
18
|
+
value_ = number0
|
|
19
|
+
}
|
|
20
|
+
if (isInteger(value_)) {
|
|
21
|
+
return value_
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const parts = split(".", toStr(value_)),
|
|
25
|
+
// eslint-disable-next-line sort-vars
|
|
26
|
+
integerPart = $Number(parts[number0])
|
|
27
|
+
|
|
28
|
+
if (isNotNegative(value_)) {
|
|
29
|
+
return integerPart
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
return subtract(integerPart, number1)
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
module.exports = floor
|
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,33 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lolite.floor",
|
|
3
|
+
"version": "1.1.6",
|
|
4
|
+
"main": "index.js",
|
|
5
|
+
"dependencies": {
|
|
6
|
+
"lodash.multiply": "^4.9.0",
|
|
7
|
+
"immediate-error": "^7.1.0",
|
|
8
|
+
"integer-values": "^2.0.0",
|
|
9
|
+
"is-not-integer": "^1.0.2",
|
|
10
|
+
"logtoconsole": "^1.0.7",
|
|
11
|
+
"@not-js/not": "^1.1.0",
|
|
12
|
+
"es-logical-not-operator": "^1.0.0",
|
|
13
|
+
"is-integer": "^1.0.7",
|
|
14
|
+
"literally": "^1.0.0",
|
|
15
|
+
"not-not": "^1.0.2",
|
|
16
|
+
"yanoop": "^1.0.0",
|
|
17
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
18
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
19
|
+
"@positive-numbers/one": "^3.0.0",
|
|
20
|
+
"@positive-numbers/zero": "^3.0.0",
|
|
21
|
+
"construct-new": "^2.0.4",
|
|
22
|
+
"countingup": "^0.3.0",
|
|
23
|
+
"false-value": "^2.0.6",
|
|
24
|
+
"iszero": "^1.0.0",
|
|
25
|
+
"pkg-with-failing-optional-dependency": "^1.0.1",
|
|
26
|
+
"subtract": "^0.0.3",
|
|
27
|
+
"while2": "^2.0.2",
|
|
28
|
+
"es-intrinsic-cache": "^1.0.1",
|
|
29
|
+
"is-not-negative": "^1.0.3",
|
|
30
|
+
"string-split": "^0.3.1",
|
|
31
|
+
"to-str": "^1.0.0"
|
|
32
|
+
}
|
|
33
|
+
}
|
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
|