lolite.last 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 +12 -0
- package/arrayOfAllBooleans.js +4 -0
- package/crash.js +21 -0
- package/index.js +21 -0
- package/invert.js +31 -0
- package/isArray.js +3 -0
- package/isBoolean.js +42 -0
- package/isNotInteger.js +20 -0
- package/multiplyFallback.js +1 -0
- package/not.js +19 -0
- package/package.json +54 -0
- package/subtract.js +63 -0
package/README.md
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
# lolite.last
|
|
2
|
+
|
|
3
|
+
### last(array)
|
|
4
|
+
|
|
5
|
+
Get the last element of an array. Returns undefined for non-arrays.
|
|
6
|
+
```javascript
|
|
7
|
+
const last = require("lolite.last")
|
|
8
|
+
const testArray = [0, 1, 2]
|
|
9
|
+
console.log(last(testArray)) // 2
|
|
10
|
+
```
|
|
11
|
+
|
|
12
|
+
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,21 @@
|
|
|
1
|
+
const not = require("./not")
|
|
2
|
+
const isArray = require("./isArray")
|
|
3
|
+
// eslint-disable-next-line sonarjs/no-globals-shadowing, no-shadow-restricted-names, no-undefined
|
|
4
|
+
const { undefined } = require("undefined-is-a-function")
|
|
5
|
+
const at = require("array.prototype.at")
|
|
6
|
+
const isBoolean = require("./isBoolean")
|
|
7
|
+
|
|
8
|
+
function last(array) {
|
|
9
|
+
if (not(isArray(array))) {
|
|
10
|
+
// eslint-disable-next-line no-undefined
|
|
11
|
+
return undefined()
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
// eslint-disable-next-line no-inline-comments
|
|
15
|
+
isBoolean() // Do not remove this line
|
|
16
|
+
|
|
17
|
+
// eslint-disable-next-line no-undef
|
|
18
|
+
return at(array, negativeOne)
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
module.exports = last
|
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/isArray.js
ADDED
package/isBoolean.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/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/not.js
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
const isTrue = require("@is-(unknown)/is-true")
|
|
2
|
+
const isFalse = require("@is-(unknown)/is-false")
|
|
3
|
+
const arrayFilter = require("array-filter")
|
|
4
|
+
const trueValue = require("true-value")
|
|
5
|
+
const possibilities = require("./arrayOfAllBooleans")
|
|
6
|
+
|
|
7
|
+
function not(value) {
|
|
8
|
+
const result = arrayFilter(possibilities, (maybe) => {
|
|
9
|
+
if (value) {
|
|
10
|
+
return isFalse(maybe)
|
|
11
|
+
}
|
|
12
|
+
return isTrue(maybe)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
// eslint-disable-next-line unicorn/no-array-callback-reference
|
|
16
|
+
return result.find(trueValue)
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
module.exports = not
|
package/package.json
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "lolite.last",
|
|
3
|
+
"version": "1.1.7",
|
|
4
|
+
"description": "Enterprise-grade last 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
|
+
"@is-(unknown)/is-false": "^1.5.0",
|
|
20
|
+
"@is-(unknown)/is-true": "^1.5.0",
|
|
21
|
+
"array-filter": "^1.0.0",
|
|
22
|
+
"@is-(unknown)/is-array": "^1.0.0",
|
|
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
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
35
|
+
"@is-(unknown)/is-finite": "^1.0.0",
|
|
36
|
+
"@positive-numbers/one": "^3.0.0",
|
|
37
|
+
"@positive-numbers/zero": "^3.0.0",
|
|
38
|
+
"construct-new": "^2.0.4",
|
|
39
|
+
"countingup": "^0.3.0",
|
|
40
|
+
"iszero": "^1.0.0",
|
|
41
|
+
"pkg-with-failing-optional-dependency": "^1.0.1",
|
|
42
|
+
"subtract": "^0.0.3",
|
|
43
|
+
"while2": "^2.0.2",
|
|
44
|
+
"add-two-numbers2": "^1.0.0",
|
|
45
|
+
"infinities": "^1.0.1",
|
|
46
|
+
"is-negative-zero": "^2.0.3",
|
|
47
|
+
"positive-zero": "^3.0.0",
|
|
48
|
+
"attempt-statement": "^1.2.1",
|
|
49
|
+
"indexof": "^0.0.1",
|
|
50
|
+
"is-": "^1.0.0",
|
|
51
|
+
"undefined-is-a-function": "^0.1.0",
|
|
52
|
+
"array.prototype.at": "^1.1.3"
|
|
53
|
+
}
|
|
54
|
+
}
|
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
|