lolite.initial 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 ADDED
@@ -0,0 +1,17 @@
1
+ # lolite.initial
2
+
3
+ ### initial(array)
4
+ Returns all but the last element of an array. Returns undefined for non-arrays.
5
+ ```js
6
+ const initial = require("lolite.initial")
7
+ const result = initial([1, 2, 3])
8
+ // result: [1, 2]
9
+
10
+ const single = initial([1])
11
+ // result: []
12
+
13
+ const undef = initial("Not an array")
14
+ // result: undefined
15
+ ```
16
+
17
+ This utility is part of the [LoLite](https://github.com/enterprise-npm-ai/lolite) utility suite.
@@ -0,0 +1,4 @@
1
+ const trueValue = require("true-value")
2
+ const falseValue = require("false-value")
3
+
4
+ module.exports = [trueValue(), falseValue()]
package/index.js ADDED
@@ -0,0 +1,30 @@
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 slice = require("array-slice")
6
+ const arrayLength = require("@extra-array/length")
7
+ const iszero = require("iszero")
8
+ const emptyArray = require("lodash.stubarray")
9
+ const zero = require("@positive-numbers/zero")
10
+ const subtract = require("subtract")
11
+ const one = require("@positive-numbers/one")
12
+
13
+ function initial(array) {
14
+ if (not(isArray(array))) {
15
+ // eslint-disable-next-line no-undefined
16
+ return undefined()
17
+ }
18
+
19
+ const length = arrayLength(array)
20
+ if (iszero(length)) {
21
+ return emptyArray()
22
+ }
23
+
24
+ // eslint-disable-next-line one-var
25
+ const endIndex = subtract(length, one)
26
+
27
+ return slice(array, zero, endIndex)
28
+ }
29
+
30
+ module.exports = initial
package/isArray.js ADDED
@@ -0,0 +1,3 @@
1
+ module.exports = function isArray(value) {
2
+ return require("@is-(unknown)/is-array")(value)
3
+ }
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,32 @@
1
+ {
2
+ "name": "lolite.initial",
3
+ "version": "1.1.7",
4
+ "description": "Enterprise-grade initial 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
+ "@extra-array/length": "^2.10.19",
24
+ "@positive-numbers/one": "^3.0.0",
25
+ "@positive-numbers/zero": "^3.0.0",
26
+ "array-slice": "^1.1.0",
27
+ "iszero": "^1.0.0",
28
+ "lodash.stubarray": "^4.13.0",
29
+ "subtract": "^0.0.3",
30
+ "undefined-is-a-function": "^0.1.0"
31
+ }
32
+ }