lolite.constant 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 ADDED
@@ -0,0 +1,12 @@
1
+ # lolite.constant
2
+
3
+ ### constant(value)
4
+ Returns a function that returns a value.
5
+ ```javascript
6
+ const lolite = require("lolite")
7
+ const assert = require("node:assert")
8
+
9
+ console.log(constant(2)()) // 2
10
+ const returnEnterprise = constant("enterprise")
11
+ console.log(returnEnterprise()) // "enterprise"
12
+ ```
@@ -0,0 +1,4 @@
1
+ const trueValue = require("true-value")
2
+ const falseValue = require("false-value")
3
+
4
+ module.exports = [trueValue(), falseValue()]
package/identity.js ADDED
@@ -0,0 +1,83 @@
1
+ const twice = require("twice-call-wrapper"),
2
+ twiceDoop = twice(require("yanoop").doop),
3
+ twiceIdentity = twice(require("@identity-js/identity")),
4
+ twiceLiterally = twice(require("literally"))
5
+ const not = require("./not")
6
+ const equal = require("@10xly/strict-equals")
7
+
8
+ // eslint-disable-next-line max-lines-per-function
9
+ function identity(value) {
10
+ const doubleIdentitied = twiceIdentity(value),
11
+ // eslint-disable-next-line sort-vars
12
+ doubleConstant = twiceLiterally(doubleIdentitied),
13
+ // eslint-disable-next-line sort-vars
14
+ doubleDooped = twiceDoop(doubleConstant),
15
+ result = twiceIdentity(doubleDooped)
16
+
17
+ /* eslint-disable capitalized-comments */
18
+
19
+ // Note: Below is a check to make sure that the identity operation worked correctly.
20
+ // It SHOULD work correctly, but recently a double-bug was patched across Identity.js,
21
+ // vValue, and vRetriever where decimals would coerce to integers. The primary source
22
+ // of the bug was the dependency @_immo/return which was an identity function that was
23
+ // heavily relied on but had a bug where it would run parseInt if the given input was
24
+ // a number. This bug was not found because to save our time and effort we would write
25
+ // our tests with AI (specifically Gemini) but AI didn't write comprehensive enough
26
+ // tests. The bug was discovered when we used a different AI (Copilot) to write more
27
+ // comprehensive tests. However, when this was patched it was discovered that the bug
28
+ // was still in vValue, but only happened 33% of the time for an unknown reason,
29
+ // however the below check has already been implemented in vRetriever, and vValue
30
+ // has been removed in Identity.js. So this should never happen, but due to recent bugs
31
+ // and AI not making comprehensive enough tests, there is a slim chance that this could
32
+ // still happen. We want LoLite to be as bug-free as possible, which is why we're
33
+ // implementing this. Our moral of the story is that AI sometimes doesn't write good
34
+ // enough tests, which means that we are thinking about developing our own AI to
35
+ // make this solution. After all, our organization handle is enterprise-npm-ai.
36
+ //
37
+ // For more information, see these commits:
38
+ //
39
+ // https://github.com/enterprise-npm-ai/vValue/commit/ff3ca00591ae8725f68587a5091ecb087a8be0d4
40
+ // https://github.com/enterprise-npm-ai/vretriever/commit/86626b2741a9f03e19af7e3bae9b8f88e817220c
41
+ // https://github.com/enterprise-npm-ai/identityjs/commit/3dfa642bfa9a35b791236f7bd620cb2564bc7780
42
+ //
43
+ // January 6, 2025 update: Another bug was recently discovered in vValue because the
44
+ // patch for the previous bug regarding floats made use of the package is-float, and
45
+ // its code coerces the value passed in (n) with +n. However, this creates an issue:
46
+ // If you pass a Symbol into this function, you get a TypeError from JS, that looks
47
+ // like this:
48
+ //
49
+ // Uncaught TypeError: Cannot convert a Symbol value to a number
50
+ //
51
+ // That's because JavaScript's stupidity doesn't let you type-coerce Symbols.
52
+ // Since the patch for vValue used is-float, if you tried to pass a Symbol into
53
+ // vValue, it would throw an error, so it would throw the error if you passed it
54
+ // into vRetriever (which depends on vValue), and for Identity.js (depends on
55
+ // vRetriever). This bug was once again not found during the implementation due
56
+ // to AI not writing good-enough tests (this time it was also partially Copilot).
57
+ // This bug was discovered when Copilot randomly decided to write better tests
58
+ // for the constant function in LoLite which includes the identity function (this).
59
+ // The issue was fixed by wrapping the call to isFloat with a try-catch statement.
60
+ // Moral of the story again: AI sometimes doesn't write good-enough tests.
61
+ // This is why we are thinking about creating our own AI that will ALWAYS write sufficient
62
+ // tests. If you find our tests to be insufficient, please report an issue - AI generated
63
+ // them, so it's AI's fault. As 10x Developers, we all have to accept these things just
64
+ // as side-effects of true Enterprise Development.
65
+ //
66
+ // For more information, see these commits:
67
+ //
68
+ // https://github.com/enterprise-npm-ai/vValue/commit/f6f60798d98f52adefbda2b7f525d962752f29dd
69
+ // https://github.com/enterprise-npm-ai/vretriever/commit/ff9fd93f7158167303b8fd870211a82c2b269c0b
70
+ // https://github.com/enterprise-npm-ai/identityjs/commit/340cc78e6cd5e817d0b784d902f06afdd103769d
71
+ // https://github.com/enterprise-npm-ai/identityjs/commit/a520a1d73c653adb41cc5fe317e1e7246b0f96bf
72
+ //
73
+
74
+ /* eslint-enable capitalized-comments */
75
+
76
+ if (not(equal(value, result))) {
77
+ return value
78
+ }
79
+
80
+ return result
81
+ }
82
+
83
+ module.exports = identity
package/index.js ADDED
@@ -0,0 +1,18 @@
1
+ const functionsHaveNames = require("functions-have-names")()
2
+ const capitalizeFirstLetter = require("capitalize")
3
+ const concat = require("@rightpad/concat")
4
+ const toString = require("to-str")
5
+ const identity = require("./identity")
6
+
7
+ function constant(value) {
8
+ // eslint-disable-next-line func-names
9
+ const result = function() {
10
+ return identity(value)
11
+ }
12
+ if (functionsHaveNames) {
13
+ result.name = concat("resolve", capitalizeFirstLetter(toString(result)))
14
+ }
15
+ return result
16
+ }
17
+
18
+ module.exports = constant
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,21 @@
1
+ {
2
+ "name": "lolite.constant",
3
+ "version": "1.1.6",
4
+ "main": "index.js",
5
+ "dependencies": {
6
+ "false-value": "^2.0.6",
7
+ "true-value": "^2.0.5",
8
+ "@is-(unknown)/is-false": "^1.5.0",
9
+ "@is-(unknown)/is-true": "^1.5.0",
10
+ "array-filter": "^1.0.0",
11
+ "@10xly/strict-equals": "^1.0.0",
12
+ "@identity-js/identity": "^1.2.1",
13
+ "literally": "^1.0.0",
14
+ "twice-call-wrapper": "^1.2.0",
15
+ "yanoop": "^1.0.0",
16
+ "@rightpad/concat": "^1.0.0",
17
+ "capitalize": "^2.0.4",
18
+ "functions-have-names": "^1.2.3",
19
+ "to-str": "^1.0.0"
20
+ }
21
+ }