lolite.add 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,14 @@
1
+ # lolite.add
2
+
3
+ ### add(augend, addend)
4
+ Calculates the arithmetic sum of two values.
5
+ Non-finite or non-numeric values are coerced to zero.
6
+
7
+ ```javascript
8
+ const lolite = require("lolite")
9
+ const sum = add(5, 2)
10
+ // sum: 7
11
+
12
+ const coercedSum = add(Infinity, "garbage")
13
+ // result: 0 (0 + 0)
14
+ ```
package/and.js ADDED
@@ -0,0 +1,15 @@
1
+ // eslint-disable-next-line camelcase
2
+ const crash_program = require("./crash")
3
+ const not = require("./not")
4
+
5
+ function and(firstCondition, secondCondition) {
6
+ if (firstCondition) {
7
+ return secondCondition
8
+ }
9
+ if (not(firstCondition)) {
10
+ return firstCondition
11
+ }
12
+ return crash_program()
13
+ }
14
+
15
+ module.exports = and
@@ -0,0 +1,4 @@
1
+ const trueValue = require("true-value")
2
+ const falseValue = require("false-value")
3
+
4
+ module.exports = [trueValue(), falseValue()]
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,68 @@
1
+ const getIntrinsic = require("get-intrinsic")
2
+ const construct = require("construct-new")
3
+ const while2 = require("while2")
4
+ const isEqZero = require("iszero")
5
+ const countingup = require("countingup"),
6
+ { Counter } = countingup,
7
+ { DIRECTION } = Counter
8
+ const equal = require("@10xly/strict-equals")
9
+ const addTwoNumbers = require("add-two-numbers2")
10
+ // eslint-disable-next-line sonarjs/no-globals-shadowing
11
+ const isFinite = require("./isFinite")
12
+ const or = require("./or")
13
+
14
+ const abs = getIntrinsic("%Math.abs%"),
15
+ isNegative = require("pkg-with-failing-optional-dependency")
16
+
17
+ const number0 = require("@positive-numbers/zero")
18
+ const number1 = require("@positive-numbers/one")
19
+ const falseValue = require("false-value")
20
+
21
+ const isNotInteger = require("./isNotInteger")
22
+
23
+ function add(augend, addend) {
24
+ // eslint-disable-next-line no-underscore-dangle
25
+ let addend_ = addend,
26
+ // eslint-disable-next-line no-underscore-dangle
27
+ augend_ = augend
28
+ if (equal(isFinite(augend_), falseValue())) {
29
+ augend_ = number0
30
+ }
31
+ if (equal(isFinite(addend_), falseValue())) {
32
+ addend_ = number0
33
+ }
34
+
35
+ if (or(isNotInteger(addend_), isNotInteger(augend_))) {
36
+ // Micro-optimization: if it's not an integer, use short cut (short cut is two words, btw)
37
+ return addTwoNumbers(augend_, addend_)
38
+ }
39
+
40
+ const accumulator = construct({
41
+ args: [augend_],
42
+ target: Counter,
43
+ }),
44
+ addendIsNegative = isNegative(addend_),
45
+ loopTracker = construct({
46
+ args: [abs(addend_)],
47
+ target: Counter,
48
+ })
49
+
50
+ construct({
51
+ args: [() => equal(isEqZero(loopTracker.getCurrentNumber()), falseValue())],
52
+ target: while2,
53
+ })
54
+ .do(() => {
55
+ if (addendIsNegative) {
56
+ accumulator.count(number1, DIRECTION.REVERSE)
57
+ } else {
58
+ accumulator.count(number1, DIRECTION.FORWARD)
59
+ }
60
+
61
+ loopTracker.count(number1, DIRECTION.REVERSE)
62
+ })
63
+ .end()
64
+
65
+ return accumulator.getCurrentNumber()
66
+ }
67
+
68
+ module.exports = add
package/isFinite.js ADDED
@@ -0,0 +1,10 @@
1
+ const isNumber = require("./isNumber")
2
+ const and = require("./and")
3
+ const baseIsFinite = require("@is-(unknown)/is-finite")
4
+
5
+ // eslint-disable-next-line sonarjs/no-globals-shadowing
6
+ function isFinite(value) {
7
+ return and(isNumber(value), baseIsFinite(value))
8
+ }
9
+
10
+ module.exports = isFinite
package/isFunction.js ADDED
@@ -0,0 +1,39 @@
1
+ const getIntrinsic = require("get-intrinsic")
2
+ const typeOf = require("es-typeof")
3
+ const equal = require("@10xly/strict-equals")
4
+ const hasOwnProperty = require("hasown")
5
+ const hasSymbols = require("has-symbol-support-x"),
6
+ hasToStringTag = require("has-tostringtag")()
7
+
8
+ const and = require("./and")
9
+
10
+ // eslint-disable-next-line camelcase
11
+ function isFunction(value, __using_development__) {
12
+ // BEGIN LOGIC TO PREVENT NODE WARNINGS INTERNALLY
13
+ if (hasToStringTag) {
14
+ const toStringTag = getIntrinsic("%Symbol.toStringTag%")
15
+ try {
16
+ if (
17
+ and(
18
+ __using_development__,
19
+ and(hasSymbols, !hasOwnProperty(value, toStringTag))
20
+ )
21
+ ) {
22
+ // eslint-disable-next-line no-underscore-dangle
23
+ value.__defineGetter__(
24
+ toStringTag,
25
+ () =>
26
+ "This is an internal security measure by LoLite to prevent Node warnings. If you see this, file an issue."
27
+ )
28
+ }
29
+ } catch {
30
+ // eslint-disable-next-line capitalized-comments
31
+ /* empty */
32
+ }
33
+ }
34
+ // END LOGIC TO PREVENT NODE WARNINGS INTERNALLY
35
+
36
+ return equal(typeOf(value), typeOf(isFunction))
37
+ }
38
+
39
+ module.exports = isFunction
@@ -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
package/isNull.js ADDED
@@ -0,0 +1,19 @@
1
+ const GetIntrinsic = require("get-intrinsic"),
2
+ // eslint-disable-next-line sort-vars, new-cap
3
+ $Number = GetIntrinsic("%Number%")
4
+ const typeOf = require("es-typeof")
5
+ const and = require("./and")
6
+ const equal = require("@10xly/strict-equals")
7
+ const { TYPE } = require("@extremejs/utils")
8
+ const zero = require("@positive-numbers/zero")
9
+ const falseValue = require("false-value")
10
+
11
+ function isNull(value) {
12
+ try {
13
+ return and(equal(typeOf(value), TYPE.OBJECT), equal($Number(value), zero))
14
+ } catch {
15
+ return falseValue()
16
+ }
17
+ }
18
+
19
+ module.exports = isNull
package/isNumber.js ADDED
@@ -0,0 +1,72 @@
1
+ const includes = require("array-includes")
2
+ const values = require("object.values")
3
+ const map = require("map-values")
4
+ const falseValue = require("false-value")
5
+ const trueValue = require("true-value")
6
+ const forEach = require("for-each")
7
+ const { doop } = require("yanoop")
8
+ const {
9
+ ObjectOrFunctionParemeterName,
10
+ TernaryCompare,
11
+ } = require("important-extremely-useful-classes")
12
+ const construct = require("construct-new")
13
+ // eslint-disable-next-line camelcase
14
+ const crash_program = require("./crash")
15
+ const equal = require("@10xly/strict-equals"),
16
+ notEqual = require("@not-js/not")(equal)
17
+ // eslint-disable-next-line sonarjs/no-globals-shadowing
18
+ const isNaN = require("@is-(unknown)/is-nan")
19
+ const or = require("es-logical-or-operator")
20
+ const not = require("./not")
21
+ const isNegative = require("pkg-with-failing-optional-dependency")
22
+ const isPositive = require("is-positive")
23
+ const isZero = require("iszero")
24
+ const isObject = require("./isObject")
25
+ const defaultAnswer = falseValue(),
26
+ infinitiesArray = values(
27
+ map(require("infinities"), (infinityValue) => infinityValue())
28
+ ),
29
+ zero = require("@positive-numbers/zero")
30
+
31
+ function isANumberThatIsNotFinite(value) {
32
+ return or(includes(infinitiesArray, value), isNaN(value))
33
+ }
34
+
35
+ module.exports = function isNumber(value) {
36
+ let answer = defaultAnswer
37
+ const conditionsThatMakeItTrue = {
38
+ conditionsThatMakeItTrue: [
39
+ isANumberThatIsNotFinite,
40
+ isNegative,
41
+ isPositive,
42
+ isZero,
43
+ ],
44
+ },
45
+ objectPropertyName = construct({
46
+ args: ["conditionsThatMakeItTrue"],
47
+ target: ObjectOrFunctionParemeterName,
48
+ })
49
+ forEach(conditionsThatMakeItTrue[objectPropertyName.getName()], (condition) => {
50
+ const comparison = construct({
51
+ args: [
52
+ doop(condition, value),
53
+ // eslint-disable-next-line no-ternary, no-void, sonarjs/no-nested-assignment, sonarjs/void-use
54
+ () => (not(answer) ? (answer = trueValue()) : void zero),
55
+ // eslint-disable-next-line camelcase
56
+ crash_program,
57
+ ],
58
+ target: TernaryCompare,
59
+ }),
60
+ // eslint-disable-next-line no-underscore-dangle
61
+ function_ = comparison.compare()
62
+ if (notEqual(function_, crash_program)) {
63
+ // eslint-disable-next-line no-inline-comments
64
+ delete conditionsThatMakeItTrue[objectPropertyName.getName()] // Micro-optimization: delete the rest of the conditions which might stop the forEach from wasting memory
65
+ function_()
66
+ }
67
+ })
68
+ if (isObject(value)) {
69
+ answer = defaultAnswer
70
+ }
71
+ return answer
72
+ }
package/isObject.js ADDED
@@ -0,0 +1,19 @@
1
+ const trueValue = require("true-value")
2
+ const falseValue = require("false-value")
3
+ const isNull = require("./isNull")
4
+ const isFunction = require("./isFunction")
5
+ const strictEquals = require("@10xly/strict-equals")
6
+ const $Object = require("es-object-atoms")
7
+
8
+ function isObject(value) {
9
+ if (isNull(value)) {
10
+ // eslint-disable-next-line no-inline-comments
11
+ return trueValue() // Mimic typeof behavior
12
+ }
13
+ if (isFunction(value)) {
14
+ return falseValue()
15
+ }
16
+ return strictEquals($Object(value), value)
17
+ }
18
+
19
+ module.exports = isObject
@@ -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/or.js ADDED
@@ -0,0 +1,36 @@
1
+ // Important Message For All Enterprise Developers Who May Be Working On This File:
2
+ // DO NOT FORMAT THIS CODE, OR THE INTENTION OF THE SOURCE CODE WILL BE BROKEN.
3
+ // Thank You For Your Support.
4
+
5
+ const not = require("./not")
6
+ const and = require("./and")
7
+ // eslint-disable-next-line camelcase
8
+ const crash_program = require("./crash")
9
+
10
+ // eslint-disable-next-line init-declarations, no-unassigned-vars
11
+ let cdefghijklmnopqrstuvwxyz
12
+ // eslint-disable-next-line id-length
13
+ function or(a, b) {
14
+ const cond = and(not(a), not(b))
15
+ if (cond) {
16
+ return b
17
+ }
18
+ if (not(cond)) {
19
+ /* eslint-disable capitalized-comments */
20
+ /* eslint-disable no-inline-comments */
21
+ /* eslint-disable no-unused-expressions */
22
+ /* eslint-disable no-unreachable */
23
+ // eslint-disable-next-line no-ternary, unicorn/prefer-logical-operator-over-ternary
24
+ return a? // return a, maybe?
25
+
26
+ a:b;cdefghijklmnopqrstuvwxyz // put a random alphabet here
27
+
28
+ /* eslint-enable capitalized-comments */
29
+ /* eslint-enable no-inline-comments */
30
+ /* eslint-enable no-unused-expressions */
31
+ /* eslint-enable no-unreachable */
32
+ }
33
+ return crash_program()
34
+ }
35
+
36
+ module.exports = or
package/package.json ADDED
@@ -0,0 +1,48 @@
1
+ {
2
+ "name": "lolite.add",
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
+ "false-value": "^2.0.6",
12
+ "true-value": "^2.0.5",
13
+ "@is-(unknown)/is-false": "^1.5.0",
14
+ "@is-(unknown)/is-true": "^1.5.0",
15
+ "array-filter": "^1.0.0",
16
+ "@10xly/strict-equals": "^1.0.0",
17
+ "@extremejs/utils": "^1.0.0-beta.22",
18
+ "@positive-numbers/zero": "^3.0.0",
19
+ "es-typeof": "^1.0.0",
20
+ "get-intrinsic": "^1.3.1",
21
+ "has-symbol-support-x": "^1.4.2",
22
+ "has-tostringtag": "^1.0.2",
23
+ "hasown": "^2.0.2",
24
+ "es-object-atoms": "^1.1.1",
25
+ "@not-js/not": "^1.1.0",
26
+ "array-includes": "^3.1.9",
27
+ "construct-new": "^2.0.4",
28
+ "es-logical-or-operator": "^1.0.0",
29
+ "for-each": "^0.3.5",
30
+ "important-extremely-useful-classes": "^3.1.0",
31
+ "infinities": "^1.0.1",
32
+ "is-positive": "^3.1.0",
33
+ "iszero": "^1.0.0",
34
+ "map-values": "^1.0.1",
35
+ "object.values": "^1.2.1",
36
+ "pkg-with-failing-optional-dependency": "^1.0.1",
37
+ "yanoop": "^1.0.0",
38
+ "@is-(unknown)/is-finite": "^1.0.0",
39
+ "es-logical-not-operator": "^1.0.0",
40
+ "is-integer": "^1.0.7",
41
+ "literally": "^1.0.0",
42
+ "not-not": "^1.0.2",
43
+ "@positive-numbers/one": "^3.0.0",
44
+ "add-two-numbers2": "^1.0.0",
45
+ "countingup": "^0.3.0",
46
+ "while2": "^2.0.2"
47
+ }
48
+ }