zerosurge 13.1.0 → 16.0.0
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 -15
- package/dist/index.d.ts +37 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +100 -0
- package/dist/index.js.map +1 -0
- package/index.test.js +41 -20
- package/package.json +24 -31
- package/src/index.ts +126 -0
- package/src/types/@10xly/strict-equals.d.ts +10 -0
- package/src/types/@rightpad/concat.d.ts +10 -0
- package/src/types/betterloggingwithecho.d.ts +22 -0
- package/src/types/literally.d.ts +9 -0
- package/src/types/minecraft-seed-input.d.ts +10 -0
- package/src/types/my-simple-add-test.d.ts +21 -0
- package/src/types/not-not.d.ts +9 -0
- package/src/types/string-creashaks-organzine.d.ts +8 -0
- package/src/types/to-str.d.ts +9 -0
- package/src/types/yanoop.d.ts +25 -0
- package/tsconfig.json +45 -0
- package/LICENSE +0 -75
- package/index.d.ts +0 -12
- package/index.js +0 -187
package/README.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
|
|
4
4
|
<sup><sub><i>(i apologize for the terrible logo.)</i></sub></sup>
|
|
5
5
|
|
|
6
|
-
> The
|
|
6
|
+
> The best zero utility library on the internet.
|
|
7
7
|
|
|
8
8
|
Tired of painstakingly trying to find the character 0 on your keyboard and then pushing the button, or don't remember how to use the number zero in JavaScript? Well, this library is the new way to zero. ZeroSurge.js is the future!
|
|
9
9
|
|
|
@@ -34,6 +34,7 @@ $ pnpm add zerosurge
|
|
|
34
34
|
This enum defines the calculation methods available for the `returnZero` function in the library:
|
|
35
35
|
- **CreashaksOrganzine**: Method 1 for zero calculation. This uses the string "creashaks organzine" and uses the Minecraft seed input algorithm to make the number zero from it.
|
|
36
36
|
- **NumberPrototypeValue**: Method 2 for zero calculation. This uses the `Number` class prototype to return zero.
|
|
37
|
+
- **RandomNumberSelfSubtraction**: Method 3 for zero calculation. This subtracts a random number by itself.
|
|
37
38
|
|
|
38
39
|
### Functions
|
|
39
40
|
|
|
@@ -43,15 +44,15 @@ This function returns the number zero. You can specify the calculation method an
|
|
|
43
44
|
|
|
44
45
|
#### Example
|
|
45
46
|
```js
|
|
46
|
-
import trueValue from 'true-value'
|
|
47
|
-
import { returnZero, ZeroCalculationMethod } from 'zerosurge'
|
|
47
|
+
import trueValue from 'true-value' // you should always use tj-commits's true-value or mde's true library. never directly use the keyword true.
|
|
48
|
+
import { returnZero, ZeroCalculationMethod } from 'zerosurge'
|
|
48
49
|
|
|
49
50
|
const zeroValue = returnZero({
|
|
50
51
|
method: ZeroCalculationMethod.CreashaksOrganzine,
|
|
51
|
-
loggingEnabled: trueValue
|
|
52
|
-
})
|
|
52
|
+
loggingEnabled: trueValue()
|
|
53
|
+
}) // outputs some logs
|
|
53
54
|
|
|
54
|
-
console.log(zeroValue)
|
|
55
|
+
console.log(zeroValue) // Outputs: 0
|
|
55
56
|
```
|
|
56
57
|
|
|
57
58
|
<hr>
|
|
@@ -61,14 +62,14 @@ console.log(zeroValue); // Outputs: 0
|
|
|
61
62
|
This function checks if a given value is zero. If logging is enabled, it will log the evaluation process to the console.
|
|
62
63
|
|
|
63
64
|
```js
|
|
64
|
-
import trueValue from 'true-value'
|
|
65
|
-
import { isZero, returnZero } from 'zerosurge'
|
|
65
|
+
import trueValue from 'true-value'
|
|
66
|
+
import { isZero, returnZero } from 'zerosurge'
|
|
66
67
|
|
|
67
68
|
const result = isZero(returnZero({
|
|
68
69
|
method: ZeroCalculationMethod.CreashaksOrganzine,
|
|
69
70
|
loggingEnabled: trueValue
|
|
70
|
-
}), trueValue)
|
|
71
|
-
console.log(result)
|
|
71
|
+
}), trueValue) // outputs some logs from both isZero and returnZero
|
|
72
|
+
console.log(result) // Outputs: true
|
|
72
73
|
```
|
|
73
74
|
|
|
74
75
|
## Logging
|
|
@@ -78,8 +79,4 @@ When `loggingEnabled` is set to `true`, the library will log relevant messages t
|
|
|
78
79
|
## Contributing
|
|
79
80
|
Contributions welcome. You can contribute by opening a pull request or issue at our github repository.
|
|
80
81
|
|
|
81
|
-
##
|
|
82
|
-
Zerosurge is licensed under the 10xGPWTHPL License. See the [LICENSE](LICENSE) file for more details.
|
|
83
|
-
|
|
84
|
-
## made with HEAVY BLACK HEART U+2764 ❤❤❤❤
|
|
85
|
-
## 10xGPWTHPL Licensed
|
|
82
|
+
## made with HEAVY BLACK HEART U+2764 ❤❤❤❤
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Represents the literal type for the numerical value zero.
|
|
3
|
+
*/
|
|
4
|
+
export type Zero = 0;
|
|
5
|
+
/**
|
|
6
|
+
* Defines the available strategies for deriving the value zero.
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ZeroCalculationMethod {
|
|
9
|
+
/** Uses the CreashaksOrganzine string and Minecraft seed input to derive zero. */
|
|
10
|
+
CreashaksOrganzine = 0,
|
|
11
|
+
/** Accesses the default value of the Number prototype. */
|
|
12
|
+
NumberPrototypeValue = 1,
|
|
13
|
+
/** Generates a random number and subtracts it from itself. */
|
|
14
|
+
RandomNumberSelfSubtraction = 2
|
|
15
|
+
}
|
|
16
|
+
/**
|
|
17
|
+
* Configuration options for the zero calculation process.
|
|
18
|
+
*/
|
|
19
|
+
export type ReturnZeroOptions = {
|
|
20
|
+
/** The specific mathematical or string-based method to use. */
|
|
21
|
+
method: ZeroCalculationMethod;
|
|
22
|
+
/** Whether to output progress and status updates to the console. */
|
|
23
|
+
loggingEnabled: boolean;
|
|
24
|
+
};
|
|
25
|
+
/**
|
|
26
|
+
* Executes a calculation to retrieve the value zero using the specified method.
|
|
27
|
+
* * @param options - Configuration for the calculation and logging behavior.
|
|
28
|
+
* @returns The calculated value of zero, or exits on an invalid method.
|
|
29
|
+
*/
|
|
30
|
+
export declare function returnZero(options: ReturnZeroOptions): Zero | undefined;
|
|
31
|
+
/**
|
|
32
|
+
* Validates if a given value is strictly equal to zero.
|
|
33
|
+
* * @param value - Any value to be tested for zero-equality.
|
|
34
|
+
* @returns True if the value matches the calculated zero, otherwise false.
|
|
35
|
+
*/
|
|
36
|
+
export declare function isZero(value: any): boolean;
|
|
37
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAcA;;GAEG;AACH,MAAM,MAAM,IAAI,GAAG,CAAC,CAAA;AAEpB;;GAEG;AACH,oBAAY,qBAAqB;IAC/B,kFAAkF;IAClF,kBAAkB,IAAA;IAClB,0DAA0D;IAC1D,oBAAoB,IAAA;IACpB,8DAA8D;IAC9D,2BAA2B,IAAA;CAC5B;AA0BD;;GAEG;AACH,MAAM,MAAM,iBAAiB,GAAG;IAC9B,+DAA+D;IAC/D,MAAM,EAAE,qBAAqB,CAAA;IAC7B,oEAAoE;IACpE,cAAc,EAAE,OAAO,CAAA;CACxB,CAAA;AAED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,OAAO,EAAE,iBAAiB,GAAG,IAAI,GAAG,SAAS,CAwCvE;AAED;;;;GAIG;AACH,wBAAgB,MAAM,CAAC,KAAK,EAAE,GAAG,GAAG,OAAO,CAQ1C"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.ZeroCalculationMethod = void 0;
|
|
7
|
+
exports.returnZero = returnZero;
|
|
8
|
+
exports.isZero = isZero;
|
|
9
|
+
const betterloggingwithecho_1 = __importDefault(require("betterloggingwithecho"));
|
|
10
|
+
const chalk_1 = __importDefault(require("chalk"));
|
|
11
|
+
const minecraft_seed_input_1 = __importDefault(require("minecraft-seed-input"));
|
|
12
|
+
const string_creashaks_organzine_1 = __importDefault(require("string-creashaks-organzine"));
|
|
13
|
+
const immediate_error_1 = require("immediate-error");
|
|
14
|
+
const random_number_1 = __importDefault(require("random-number"));
|
|
15
|
+
const concat_1 = __importDefault(require("@rightpad/concat"));
|
|
16
|
+
const to_str_1 = __importDefault(require("to-str"));
|
|
17
|
+
const my_simple_add_test_1 = require("my-simple-add-test");
|
|
18
|
+
const strict_equals_1 = __importDefault(require("@10xly/strict-equals"));
|
|
19
|
+
const yanoop_1 = require("yanoop");
|
|
20
|
+
const not_not_1 = __importDefault(require("not-not"));
|
|
21
|
+
const literally_1 = __importDefault(require("literally"));
|
|
22
|
+
/**
|
|
23
|
+
* Defines the available strategies for deriving the value zero.
|
|
24
|
+
*/
|
|
25
|
+
var ZeroCalculationMethod;
|
|
26
|
+
(function (ZeroCalculationMethod) {
|
|
27
|
+
/** Uses the CreashaksOrganzine string and Minecraft seed input to derive zero. */
|
|
28
|
+
ZeroCalculationMethod[ZeroCalculationMethod["CreashaksOrganzine"] = 0] = "CreashaksOrganzine";
|
|
29
|
+
/** Accesses the default value of the Number prototype. */
|
|
30
|
+
ZeroCalculationMethod[ZeroCalculationMethod["NumberPrototypeValue"] = 1] = "NumberPrototypeValue";
|
|
31
|
+
/** Generates a random number and subtracts it from itself. */
|
|
32
|
+
ZeroCalculationMethod[ZeroCalculationMethod["RandomNumberSelfSubtraction"] = 2] = "RandomNumberSelfSubtraction";
|
|
33
|
+
})(ZeroCalculationMethod || (exports.ZeroCalculationMethod = ZeroCalculationMethod = {}));
|
|
34
|
+
/**
|
|
35
|
+
* Internal utility for handling output based on the provided configuration.
|
|
36
|
+
*/
|
|
37
|
+
class Logger {
|
|
38
|
+
/**
|
|
39
|
+
* @param loggingEnabled - Determines if log messages should be emitted.
|
|
40
|
+
*/
|
|
41
|
+
constructor(loggingEnabled) {
|
|
42
|
+
this.loggingEnabled = loggingEnabled;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* Outputs a message if logging is currently active.
|
|
46
|
+
* @param message - The content to log.
|
|
47
|
+
*/
|
|
48
|
+
log(message) {
|
|
49
|
+
if (this.loggingEnabled) {
|
|
50
|
+
(0, betterloggingwithecho_1.default)(message);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/**
|
|
55
|
+
* Executes a calculation to retrieve the value zero using the specified method.
|
|
56
|
+
* * @param options - Configuration for the calculation and logging behavior.
|
|
57
|
+
* @returns The calculated value of zero, or exits on an invalid method.
|
|
58
|
+
*/
|
|
59
|
+
function returnZero(options) {
|
|
60
|
+
const logger = new Logger(options.loggingEnabled);
|
|
61
|
+
const method = options.method;
|
|
62
|
+
logger.log(chalk_1.default.cyan("[zerosurge] Beginning to calculate zero"));
|
|
63
|
+
switch (method) {
|
|
64
|
+
case ZeroCalculationMethod.CreashaksOrganzine: {
|
|
65
|
+
logger.log(chalk_1.default.cyan("[zerosurge] Using CreashaksOrganzine method"));
|
|
66
|
+
const result = (0, minecraft_seed_input_1.default)(string_creashaks_organzine_1.default);
|
|
67
|
+
logger.log(chalk_1.default.green("[zerosurge] Zero calculated succesfully"));
|
|
68
|
+
return result;
|
|
69
|
+
}
|
|
70
|
+
case ZeroCalculationMethod.NumberPrototypeValue: {
|
|
71
|
+
logger.log(chalk_1.default.cyan("[zerosurge] Using NumberPrototypeValue method"));
|
|
72
|
+
const result = Number.prototype.valueOf();
|
|
73
|
+
logger.log(chalk_1.default.green("[zerosurge] Zero calculated succesfully"));
|
|
74
|
+
return result;
|
|
75
|
+
}
|
|
76
|
+
case ZeroCalculationMethod.RandomNumberSelfSubtraction: {
|
|
77
|
+
logger.log(chalk_1.default.cyan("[zerosurge] Using RandomNumberSelfSubtraction"));
|
|
78
|
+
const random = (0, random_number_1.default)();
|
|
79
|
+
logger.log(chalk_1.default.cyan((0, concat_1.default)("[zerosurge] Generated random number ", (0, to_str_1.default)(random))));
|
|
80
|
+
const result = (0, my_simple_add_test_1.subtract)(random, random);
|
|
81
|
+
logger.log(chalk_1.default.green("[zerosurge] Zero calculated succesfully"));
|
|
82
|
+
return result;
|
|
83
|
+
}
|
|
84
|
+
default: {
|
|
85
|
+
(0, immediate_error_1.immediateError)(chalk_1.default.red("[zerosurge] Unknown or undefined method for calculating zero, exiting"), immediate_error_1.ErrorType.TypeError);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
}
|
|
89
|
+
/**
|
|
90
|
+
* Validates if a given value is strictly equal to zero.
|
|
91
|
+
* * @param value - Any value to be tested for zero-equality.
|
|
92
|
+
* @returns True if the value matches the calculated zero, otherwise false.
|
|
93
|
+
*/
|
|
94
|
+
function isZero(value) {
|
|
95
|
+
return (0, strict_equals_1.default)(value, returnZero({
|
|
96
|
+
method: ZeroCalculationMethod.CreashaksOrganzine,
|
|
97
|
+
loggingEnabled: (0, yanoop_1.doop)((0, not_not_1.default)((0, literally_1.default)(void /false/))),
|
|
98
|
+
}));
|
|
99
|
+
}
|
|
100
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"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"}
|
package/index.test.js
CHANGED
|
@@ -1,28 +1,49 @@
|
|
|
1
|
-
const { ZeroCalculationMethod, isZero, returnZero } = require("
|
|
1
|
+
const { ZeroCalculationMethod, isZero, returnZero } = require("./dist/index")
|
|
2
2
|
const kleur = require("kleur")
|
|
3
3
|
const attempt = require("attempt-statement")
|
|
4
4
|
const assert = require("assert-fn")
|
|
5
|
-
const noop = require("
|
|
6
|
-
const ltc = require(
|
|
7
|
-
const { immediateError, ErrorType } = require('immediate-error')
|
|
5
|
+
const noop = require("n0p3-es2015-cjs")
|
|
6
|
+
const ltc = require("logtoconsole").log
|
|
8
7
|
|
|
9
8
|
const loggingEnabled = false
|
|
10
9
|
|
|
11
10
|
attempt(() => {
|
|
12
|
-
assert(returnZero() === 0, "returnZero should return zero")
|
|
13
|
-
assert(
|
|
14
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine, loggingEnabled }) === 0,
|
|
15
|
-
"returnZero should return zero with creashaks organzine method"
|
|
16
|
-
)
|
|
17
11
|
assert(
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
})
|
|
12
|
+
returnZero({
|
|
13
|
+
method: ZeroCalculationMethod.CreashaksOrganzine,
|
|
14
|
+
loggingEnabled,
|
|
15
|
+
}) === 0,
|
|
16
|
+
"returnZero should return zero with creashaks organzine method"
|
|
17
|
+
)
|
|
18
|
+
assert(
|
|
19
|
+
returnZero({
|
|
20
|
+
method: ZeroCalculationMethod.NumberPrototypeValue,
|
|
21
|
+
loggingEnabled,
|
|
22
|
+
}) === 0,
|
|
23
|
+
"returnZero should return zero with number prototype value method"
|
|
24
|
+
)
|
|
25
|
+
assert(
|
|
26
|
+
returnZero({
|
|
27
|
+
method: ZeroCalculationMethod.RandomNumberSelfSubtraction,
|
|
28
|
+
loggingEnabled,
|
|
29
|
+
}) === 0,
|
|
30
|
+
"returnZero should return zero with number prototype value method"
|
|
31
|
+
)
|
|
32
|
+
assert(
|
|
33
|
+
isZero(0, loggingEnabled) === true,
|
|
34
|
+
"isZero should return true if the input is zero"
|
|
35
|
+
)
|
|
36
|
+
assert(
|
|
37
|
+
isZero((Math.random() + 0.1) * 134, loggingEnabled) === false,
|
|
38
|
+
"isZero should return false if the input is not zero"
|
|
39
|
+
)
|
|
40
|
+
})
|
|
41
|
+
.rescue((e) => {
|
|
42
|
+
ltc(kleur.red("× Tests failed!!! " + e.message))
|
|
43
|
+
throw e
|
|
44
|
+
})
|
|
45
|
+
.else(() => {
|
|
46
|
+
ltc(kleur.green("✔ TESTS PASSED!!!!"))
|
|
47
|
+
})
|
|
48
|
+
.ensure(noop)
|
|
49
|
+
.end()
|
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "zerosurge",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "16.0.0",
|
|
4
4
|
"description": "The future is here.",
|
|
5
|
-
"main": "index.js",
|
|
5
|
+
"main": "src/index.js",
|
|
6
6
|
"scripts": {
|
|
7
|
-
"test": "node index.test"
|
|
7
|
+
"test": "node index.test",
|
|
8
|
+
"build": "tsc"
|
|
8
9
|
},
|
|
9
10
|
"repository": {
|
|
10
11
|
"type": "git",
|
|
@@ -108,42 +109,34 @@
|
|
|
108
109
|
"95-keywords-is-alot"
|
|
109
110
|
],
|
|
110
111
|
"author": "tj-commits <thefoxjones@gmail.com>",
|
|
111
|
-
"license": "
|
|
112
|
+
"license": "MIT",
|
|
112
113
|
"bugs": {
|
|
113
114
|
"url": "https://github.com/10xEngineersQualityProgramming/ZeroSurge.js/issues"
|
|
114
115
|
},
|
|
115
116
|
"homepage": "https://github.com/10xEngineersQualityProgramming/ZeroSurge.js#readme",
|
|
116
117
|
"dependencies": {
|
|
117
|
-
"@
|
|
118
|
-
"@
|
|
119
|
-
"
|
|
118
|
+
"@10xly/strict-equals": "^1.0.0",
|
|
119
|
+
"@rightpad/concat": "^1.0.0",
|
|
120
|
+
"betterloggingwithecho": "^1.0.0",
|
|
121
|
+
"chalk": "^4.1.2",
|
|
122
|
+
"immediate-error": "^7.1.0",
|
|
123
|
+
"literally": "^1.0.0",
|
|
124
|
+
"minecraft-seed-input": "^1.0.0",
|
|
125
|
+
"my-simple-add-test": "^1.1.0",
|
|
126
|
+
"not-not": "^1.0.2",
|
|
127
|
+
"random-number": "^0.0.9",
|
|
128
|
+
"string-creashaks-organzine": "^1.0.0",
|
|
129
|
+
"to-str": "^1.0.0",
|
|
130
|
+
"yanoop": "^1.0.0"
|
|
131
|
+
},
|
|
132
|
+
"devDependencies": {
|
|
133
|
+
"@types/node": "^24.10.0",
|
|
134
|
+
"@types/random-number": "^0.0.4",
|
|
120
135
|
"assert-fn": "^1.0.1",
|
|
121
136
|
"attempt-statement": "^1.1.0",
|
|
122
|
-
"deep-equal": "^2.2.3",
|
|
123
|
-
"exit": "^0.1.2",
|
|
124
|
-
"falsejs": "^1234.56.789",
|
|
125
|
-
"get-ecmascript-type-of": "^1.0.0",
|
|
126
|
-
"get-intrinsic": "^1.2.4",
|
|
127
|
-
"if": "^2.0.0",
|
|
128
|
-
"immediate-error": "^6.1.0",
|
|
129
|
-
"integer-value-positive-one": "^1.0.2",
|
|
130
|
-
"integer-value-positive-two": "^1.0.0",
|
|
131
|
-
"is-eq-ten-thousand": "^4324803849.34298304823.328712760",
|
|
132
|
-
"is-equal": "^1.7.0",
|
|
133
|
-
"is-equal-to": "^1.1.2",
|
|
134
|
-
"is-hundred": "^0.10.0",
|
|
135
|
-
"is-hundred-thousand": "^10000000000000.10000000000000.10000000000000",
|
|
136
|
-
"is-nil": "^1.0.1",
|
|
137
|
-
"is-one": "^1.0.0",
|
|
138
|
-
"is-ten": "^0.1.0",
|
|
139
|
-
"is-thousand": "^0.0.2",
|
|
140
|
-
"is-uneven": "^1.0.0",
|
|
141
137
|
"kleur": "^4.1.5",
|
|
142
|
-
"lodash.sample": "^4.2.1",
|
|
143
138
|
"logtoconsole": "^1.0.7",
|
|
144
|
-
"
|
|
145
|
-
"
|
|
146
|
-
"noop10": "^1.0.3",
|
|
147
|
-
"string-creashaks-organzine": "^1.0.0"
|
|
139
|
+
"n0p3-es2015-cjs": "^1.0.1",
|
|
140
|
+
"typescript": "^5.9.3"
|
|
148
141
|
}
|
|
149
142
|
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import echo from "betterloggingwithecho"
|
|
2
|
+
import chalk from "chalk"
|
|
3
|
+
import seed from "minecraft-seed-input"
|
|
4
|
+
import creashaksOrganzine from "string-creashaks-organzine"
|
|
5
|
+
import { immediateError, ErrorType } from "immediate-error"
|
|
6
|
+
import rn from "random-number"
|
|
7
|
+
import concat from "@rightpad/concat"
|
|
8
|
+
import toStr from "to-str"
|
|
9
|
+
import { subtract } from "my-simple-add-test"
|
|
10
|
+
import isEqual from "@10xly/strict-equals"
|
|
11
|
+
import { doop } from "yanoop"
|
|
12
|
+
import notNot from "not-not"
|
|
13
|
+
import literally from "literally"
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* Represents the literal type for the numerical value zero.
|
|
17
|
+
*/
|
|
18
|
+
export type Zero = 0
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* Defines the available strategies for deriving the value zero.
|
|
22
|
+
*/
|
|
23
|
+
export enum ZeroCalculationMethod {
|
|
24
|
+
/** Uses the CreashaksOrganzine string and Minecraft seed input to derive zero. */
|
|
25
|
+
CreashaksOrganzine,
|
|
26
|
+
/** Accesses the default value of the Number prototype. */
|
|
27
|
+
NumberPrototypeValue,
|
|
28
|
+
/** Generates a random number and subtracts it from itself. */
|
|
29
|
+
RandomNumberSelfSubtraction,
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Internal utility for handling output based on the provided configuration.
|
|
34
|
+
*/
|
|
35
|
+
class Logger {
|
|
36
|
+
public loggingEnabled: boolean
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param loggingEnabled - Determines if log messages should be emitted.
|
|
40
|
+
*/
|
|
41
|
+
constructor(loggingEnabled: boolean) {
|
|
42
|
+
this.loggingEnabled = loggingEnabled
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* Outputs a message if logging is currently active.
|
|
47
|
+
* @param message - The content to log.
|
|
48
|
+
*/
|
|
49
|
+
log(message: string) {
|
|
50
|
+
if (this.loggingEnabled) {
|
|
51
|
+
echo(message)
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Configuration options for the zero calculation process.
|
|
58
|
+
*/
|
|
59
|
+
export type ReturnZeroOptions = {
|
|
60
|
+
/** The specific mathematical or string-based method to use. */
|
|
61
|
+
method: ZeroCalculationMethod
|
|
62
|
+
/** Whether to output progress and status updates to the console. */
|
|
63
|
+
loggingEnabled: boolean
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* Executes a calculation to retrieve the value zero using the specified method.
|
|
68
|
+
* * @param options - Configuration for the calculation and logging behavior.
|
|
69
|
+
* @returns The calculated value of zero, or exits on an invalid method.
|
|
70
|
+
*/
|
|
71
|
+
export function returnZero(options: ReturnZeroOptions): Zero | undefined {
|
|
72
|
+
const logger: Logger = new Logger(options.loggingEnabled)
|
|
73
|
+
const method: ZeroCalculationMethod = options.method
|
|
74
|
+
|
|
75
|
+
logger.log(chalk.cyan("[zerosurge] Beginning to calculate zero"))
|
|
76
|
+
|
|
77
|
+
switch (method) {
|
|
78
|
+
case ZeroCalculationMethod.CreashaksOrganzine: {
|
|
79
|
+
logger.log(chalk.cyan("[zerosurge] Using CreashaksOrganzine method"))
|
|
80
|
+
const result: number = seed(creashaksOrganzine)
|
|
81
|
+
logger.log(chalk.green("[zerosurge] Zero calculated succesfully"))
|
|
82
|
+
return result as Zero
|
|
83
|
+
}
|
|
84
|
+
case ZeroCalculationMethod.NumberPrototypeValue: {
|
|
85
|
+
logger.log(chalk.cyan("[zerosurge] Using NumberPrototypeValue method"))
|
|
86
|
+
const result: number = Number.prototype.valueOf()
|
|
87
|
+
logger.log(chalk.green("[zerosurge] Zero calculated succesfully"))
|
|
88
|
+
return result as Zero
|
|
89
|
+
}
|
|
90
|
+
case ZeroCalculationMethod.RandomNumberSelfSubtraction: {
|
|
91
|
+
logger.log(chalk.cyan("[zerosurge] Using RandomNumberSelfSubtraction"))
|
|
92
|
+
const random: number = rn()
|
|
93
|
+
logger.log(
|
|
94
|
+
chalk.cyan(
|
|
95
|
+
concat("[zerosurge] Generated random number ", toStr(random))
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
const result: number = subtract(random, random)
|
|
99
|
+
logger.log(chalk.green("[zerosurge] Zero calculated succesfully"))
|
|
100
|
+
return result as Zero
|
|
101
|
+
}
|
|
102
|
+
default: {
|
|
103
|
+
immediateError(
|
|
104
|
+
chalk.red(
|
|
105
|
+
"[zerosurge] Unknown or undefined method for calculating zero, exiting"
|
|
106
|
+
),
|
|
107
|
+
ErrorType.TypeError
|
|
108
|
+
)
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
/**
|
|
114
|
+
* Validates if a given value is strictly equal to zero.
|
|
115
|
+
* * @param value - Any value to be tested for zero-equality.
|
|
116
|
+
* @returns True if the value matches the calculated zero, otherwise false.
|
|
117
|
+
*/
|
|
118
|
+
export function isZero(value: any): boolean {
|
|
119
|
+
return isEqual(
|
|
120
|
+
value,
|
|
121
|
+
returnZero({
|
|
122
|
+
method: ZeroCalculationMethod.CreashaksOrganzine,
|
|
123
|
+
loggingEnabled: doop(notNot(literally(void /false/))),
|
|
124
|
+
})
|
|
125
|
+
)
|
|
126
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare module "@10xly/strict-equals" {
|
|
2
|
+
/**
|
|
3
|
+
* Performs a strict equality comparison between two values.
|
|
4
|
+
* @param a - The first value to compare.
|
|
5
|
+
* @param b - The second value to compare.
|
|
6
|
+
*/
|
|
7
|
+
function isEqual<T>(a: T, b: T): boolean
|
|
8
|
+
|
|
9
|
+
export = isEqual
|
|
10
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
// This declares the module 'betterloggingwithecho'
|
|
2
|
+
declare module "betterloggingwithecho" {
|
|
3
|
+
interface EchoProperty {
|
|
4
|
+
/**
|
|
5
|
+
* Sets a custom function to handle the logging output.
|
|
6
|
+
* @param logFunction A function that takes any number of arguments and returns nothing.
|
|
7
|
+
*/
|
|
8
|
+
setLogFunction(logFunction: (...args: any[]) => void): void
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
interface EchoFunction extends EchoProperty {
|
|
12
|
+
/**
|
|
13
|
+
* Logs a string message to the console (or the custom log function, if set).
|
|
14
|
+
* @param message The string message to be logged.
|
|
15
|
+
*/
|
|
16
|
+
(message: string): void
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
// Export the combined type as the default export of the module
|
|
20
|
+
const echo: EchoFunction
|
|
21
|
+
export default echo
|
|
22
|
+
}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
declare module "minecraft-seed-input" {
|
|
2
|
+
/**
|
|
3
|
+
* Generates a numerical Minecraft seed from a given input value.
|
|
4
|
+
* * @param input The value to be converted into a seed (can be a string, number, etc.).
|
|
5
|
+
* @returns The generated numerical seed (e.g., a 64-bit integer represented as a JavaScript number).
|
|
6
|
+
*/
|
|
7
|
+
function seed(input: any): number
|
|
8
|
+
|
|
9
|
+
export = seed
|
|
10
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
declare module "my-simple-add-test" {
|
|
2
|
+
/**
|
|
3
|
+
* Calculates the sum of two numbers.
|
|
4
|
+
* @param a - The first number.
|
|
5
|
+
* @param b - The second number.
|
|
6
|
+
*/
|
|
7
|
+
function add(a: number, b: number): number
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* Calculates the difference between two numbers.
|
|
11
|
+
* @param a - The number to be subtracted from.
|
|
12
|
+
* @param b - The number to subtract.
|
|
13
|
+
*/
|
|
14
|
+
function subtract(a: number, b: number): number
|
|
15
|
+
|
|
16
|
+
namespace add {
|
|
17
|
+
export { add, subtract }
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
export = add
|
|
21
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
declare module "not-not" {
|
|
2
|
+
/**
|
|
3
|
+
* Returns a function that returns the truthiness of the original function's result.
|
|
4
|
+
* @param f - The function to evaluate.
|
|
5
|
+
*/
|
|
6
|
+
function notNot<T extends (...args: any[]) => any>(f: T): (...args: Parameters<T>) => boolean
|
|
7
|
+
|
|
8
|
+
export = notNot
|
|
9
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
declare module "yanoop" {
|
|
2
|
+
/**
|
|
3
|
+
* Does nothing.
|
|
4
|
+
*/
|
|
5
|
+
function noop(): void
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* Throws error if present.
|
|
9
|
+
* @param err - The error to throw.
|
|
10
|
+
*/
|
|
11
|
+
function throwop(err?: unknown): void
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Performs the given function if present, with the given arguments.
|
|
15
|
+
* @param fn - The function to execute.
|
|
16
|
+
* @param args - Arguments to pass to the function.
|
|
17
|
+
* @returns The result of the function, or undefined if fn is not a function.
|
|
18
|
+
*/
|
|
19
|
+
function doop<T extends (...args: any[]) => any>(
|
|
20
|
+
fn: T | unknown,
|
|
21
|
+
...args: Parameters<T>
|
|
22
|
+
): ReturnType<T> | undefined
|
|
23
|
+
|
|
24
|
+
export { noop, throwop, doop }
|
|
25
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
{
|
|
2
|
+
// Visit https://aka.ms/tsconfig to read more about this file
|
|
3
|
+
"compilerOptions": {
|
|
4
|
+
// File Layout
|
|
5
|
+
"rootDir": "./src",
|
|
6
|
+
"outDir": "./dist",
|
|
7
|
+
|
|
8
|
+
// Environment Settings
|
|
9
|
+
// See also https://aka.ms/tsconfig/module
|
|
10
|
+
"module": "commonjs",
|
|
11
|
+
"target": "es2018",
|
|
12
|
+
"lib": ["esnext"],
|
|
13
|
+
"types": ["node"],
|
|
14
|
+
// For nodejs:
|
|
15
|
+
// "lib": ["esnext"],
|
|
16
|
+
// "types": ["node"],
|
|
17
|
+
// and npm install -D @types/node
|
|
18
|
+
"esModuleInterop": true,
|
|
19
|
+
|
|
20
|
+
// Other Outputs
|
|
21
|
+
"sourceMap": true,
|
|
22
|
+
"declaration": true,
|
|
23
|
+
"declarationMap": true,
|
|
24
|
+
|
|
25
|
+
// Stricter Typechecking Options
|
|
26
|
+
"noUncheckedIndexedAccess": true,
|
|
27
|
+
"exactOptionalPropertyTypes": true,
|
|
28
|
+
|
|
29
|
+
// Style Options
|
|
30
|
+
// "noImplicitReturns": true,
|
|
31
|
+
// "noImplicitOverride": true,
|
|
32
|
+
// "noUnusedLocals": true,
|
|
33
|
+
// "noUnusedParameters": true,
|
|
34
|
+
// "noFallthroughCasesInSwitch": true,
|
|
35
|
+
// "noPropertyAccessFromIndexSignature": true,
|
|
36
|
+
|
|
37
|
+
// Recommended Options
|
|
38
|
+
"strict": true,
|
|
39
|
+
"jsx": "react-jsx","verbatimModuleSyntax": false, // <--- CHANGE THIS
|
|
40
|
+
"isolatedModules": true,
|
|
41
|
+
"noUncheckedSideEffectImports": true,
|
|
42
|
+
"moduleDetection": "force",
|
|
43
|
+
"skipLibCheck": true,
|
|
44
|
+
}
|
|
45
|
+
}
|
package/LICENSE
DELETED
|
@@ -1,75 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
10X GIANT PENIS DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
|
|
3
|
-
Version 20, October 2024
|
|
4
|
-
|
|
5
|
-
10X Giant Penis Do What The Heck You Want To Public License (10xGPWTHPL)
|
|
6
|
-
|
|
7
|
-
Copyright (C) 2024 tj-commits
|
|
8
|
-
|
|
9
|
-
https://10xgpwthfpl.is-best.net
|
|
10
|
-
|
|
11
|
-
▄▄██▄██▄▄
|
|
12
|
-
▄█ █ █▄
|
|
13
|
-
▄█ █▄
|
|
14
|
-
█ █
|
|
15
|
-
█ █
|
|
16
|
-
█ █
|
|
17
|
-
█ █
|
|
18
|
-
█ █
|
|
19
|
-
█▄ █ ▄█
|
|
20
|
-
█ ▄▄▄ █
|
|
21
|
-
█ █
|
|
22
|
-
█ █
|
|
23
|
-
█ █
|
|
24
|
-
█ █
|
|
25
|
-
█ █
|
|
26
|
-
█ █
|
|
27
|
-
█ █
|
|
28
|
-
█ █
|
|
29
|
-
█ █
|
|
30
|
-
█ █
|
|
31
|
-
█ █
|
|
32
|
-
█ █
|
|
33
|
-
▄████▄█ █▄████▄
|
|
34
|
-
▄█ █▄
|
|
35
|
-
█ █
|
|
36
|
-
█ █
|
|
37
|
-
█ █
|
|
38
|
-
█ █
|
|
39
|
-
█ ▄▄█▄▄ █
|
|
40
|
-
█ █ █ █
|
|
41
|
-
█▄ ▄█ █▄ ▄█
|
|
42
|
-
█▄▄▄▄▄█ █▄▄▄▄▄█
|
|
43
|
-
|
|
44
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
45
|
-
of this software and associated documentation files (the "Software"), to do anything they want:
|
|
46
|
-
The above copyright notice and this permission notice shall be included in
|
|
47
|
-
all copies or substantial portions of the Software.
|
|
48
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
49
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
50
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
51
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
52
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
53
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
54
|
-
THE SOFTWARE. THIS PROJECT IS PROBABLY 10X AND PROBABLY USES MANY GOOD PRACTICES WRITTEN BY
|
|
55
|
-
10X ENGINEERS AS THEY USE THIS LICENSE. ALSO THIS PROJECT IS MADE WITH HEAVY BLACK HEART U+2764 ❤❤❤❤
|
|
56
|
-
|
|
57
|
-
This is a permissive license.
|
|
58
|
-
|
|
59
|
-
Everyone is permitted to copy and distribute verbatim or modified
|
|
60
|
-
copies of this license document, and changing it is allowed as long
|
|
61
|
-
as the name is changed. Yes. It is it. You can do it. DISTRIBUTE IT
|
|
62
|
-
(the Software) HOWEVER YOU WANT AS LONG AS THE NAME IS CHANGED FROM
|
|
63
|
-
THE NAME OF THE ORIGINAL PROJECT (the Software) THAT THIS LICENSE
|
|
64
|
-
(the License) IS LICENSING. DASS ALL. THAT'S THE RULE (the Terms).
|
|
65
|
-
DO WHAT YOU WANT. UH HUH. DASS RIGHT. YOU HEARD ME.
|
|
66
|
-
|
|
67
|
-
10X GIANT PENIS DO WHAT THE HECK YOU WANT TO PUBLIC LICENSE
|
|
68
|
-
|
|
69
|
-
Ok, the purpose of this license is simple
|
|
70
|
-
and you just
|
|
71
|
-
|
|
72
|
-
DO WANT THE HECK YOU WANT TO.
|
|
73
|
-
|
|
74
|
-
10. You just, DO WHAT THE HECK YOU WANT TO 10XLY.
|
|
75
|
-
The 10xGPWTHPL.
|
package/index.d.ts
DELETED
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
export enum ZeroCalculationMethod {
|
|
2
|
-
CreashaksOrganzine = 1,
|
|
3
|
-
NumberPrototypeValue = 2
|
|
4
|
-
}
|
|
5
|
-
|
|
6
|
-
export type ReturnZeroOptions = {
|
|
7
|
-
method?: ZeroCalculationMethod
|
|
8
|
-
loggingEnabled?: boolean
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function returnZero(options?: ReturnZeroOptions): number
|
|
12
|
-
export function isZero(value: any, loggingEnabled?: boolean): boolean
|
package/index.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
require("none")()
|
|
2
|
-
|
|
3
|
-
const GetIntrinsic = require("get-intrinsic")
|
|
4
|
-
const seed = require("minecraft-seed-input")
|
|
5
|
-
const creashaksOrganzineString = require("string-creashaks-organzine")
|
|
6
|
-
const one = require("integer-value-positive-one")
|
|
7
|
-
const two = require("integer-value-positive-two")
|
|
8
|
-
const isNil = require("is-nil")
|
|
9
|
-
const If = require("if")
|
|
10
|
-
const sample = require("lodash.sample")
|
|
11
|
-
const { immediateError, ErrorType } = require("immediate-error")
|
|
12
|
-
const exit = require("exit")
|
|
13
|
-
const isOne = require("is-one")
|
|
14
|
-
const isTen = require("is-ten")
|
|
15
|
-
const isHundred = require("is-hundred")
|
|
16
|
-
const isThousand = require("is-thousand").default
|
|
17
|
-
const isTenThousand = require("is-eq-ten-thousand")
|
|
18
|
-
const isHundredThousand = require("is-hundred-thousand")
|
|
19
|
-
const f = require("falsejs")
|
|
20
|
-
const isUneven = require("is-uneven")
|
|
21
|
-
const typeOf = require("get-ecmascript-type-of")
|
|
22
|
-
const { TYPE } = require("@extremejs/utils")
|
|
23
|
-
const eq = require("are-strictly-equal")
|
|
24
|
-
const isEqual = require("is-equal")
|
|
25
|
-
const isEqualTo = require("is-equal-to")
|
|
26
|
-
const deepEqual = require("deep-equal")
|
|
27
|
-
const not = require("@not-js/not")
|
|
28
|
-
const kleur = require("kleur")
|
|
29
|
-
const ltc = require("logtoconsole").log
|
|
30
|
-
|
|
31
|
-
const NumberPrototype = GetIntrinsic("%Number.prototype%")
|
|
32
|
-
const Keys = GetIntrinsic("%Object.keys%")
|
|
33
|
-
|
|
34
|
-
const ZeroCalculationMethod = {
|
|
35
|
-
CreashaksOrganzine: one(),
|
|
36
|
-
NumberPrototypeValue: two()
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
class Logger {
|
|
40
|
-
constructor(loggingEnabled) {
|
|
41
|
-
this.loggingEnabled = loggingEnabled
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
log(message) {
|
|
45
|
-
if (this.loggingEnabled) {
|
|
46
|
-
ltc(message)
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function returnZero({ method, loggingEnabled } = {}) {
|
|
52
|
-
const logger = new Logger(loggingEnabled)
|
|
53
|
-
logger.log(kleur.cyan("[zerosurge/returnZero] Beginning to calculate zero"))
|
|
54
|
-
let result
|
|
55
|
-
If(method === ZeroCalculationMethod.getMember("CreashaksOrganzine"))
|
|
56
|
-
.Then(function () {
|
|
57
|
-
logger.log(
|
|
58
|
-
kleur.cyan("[zerosurge/returnZero] Method is CreashaksOrganzine")
|
|
59
|
-
)
|
|
60
|
-
result = seed(creashaksOrganzineString)
|
|
61
|
-
logger.log(
|
|
62
|
-
kleur.green("[zerosurge/returnZero] Result calculated successfully")
|
|
63
|
-
)
|
|
64
|
-
})
|
|
65
|
-
.Else()
|
|
66
|
-
.If(method === ZeroCalculationMethod.getMember("NumberPrototypeValue"))
|
|
67
|
-
.Then(function () {
|
|
68
|
-
logger.log(
|
|
69
|
-
kleur.cyan("[zerosurge/returnZero] Method is NumberPrototypeValue")
|
|
70
|
-
)
|
|
71
|
-
result = NumberPrototype.valueOf()
|
|
72
|
-
logger.log(
|
|
73
|
-
kleur.green("[zerosurge/returnZero] Result calculated successfully")
|
|
74
|
-
)
|
|
75
|
-
})
|
|
76
|
-
.Else()
|
|
77
|
-
.If(isNil(method))
|
|
78
|
-
.Then(function () {
|
|
79
|
-
logger.log(
|
|
80
|
-
kleur.yellow(
|
|
81
|
-
"[zerosurge/returnZero] No method specified, returning the returnZero function passed in with a random method."
|
|
82
|
-
)
|
|
83
|
-
)
|
|
84
|
-
result = returnZero({
|
|
85
|
-
method: ZeroCalculationMethod.getMember(
|
|
86
|
-
sample(Keys(ZeroCalculationMethod))
|
|
87
|
-
)
|
|
88
|
-
})
|
|
89
|
-
})
|
|
90
|
-
.Else(function () {
|
|
91
|
-
immediateError(
|
|
92
|
-
kleur.red("[zerosurge/returnZero] Unknown method"),
|
|
93
|
-
ErrorType.TypeError
|
|
94
|
-
)
|
|
95
|
-
exit(one())
|
|
96
|
-
})
|
|
97
|
-
logger.log(kleur.green("[zerosurge/returnZero] Returning result"))
|
|
98
|
-
return result
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
function isZero(value, loggingEnabled) {
|
|
102
|
-
try {
|
|
103
|
-
const logger = new Logger(loggingEnabled)
|
|
104
|
-
logger.log(
|
|
105
|
-
kleur.cyan("[zerosurge/isZero] Beginning to check if value is zero")
|
|
106
|
-
)
|
|
107
|
-
logger.log(
|
|
108
|
-
kleur.cyan("[zerosurge/isZero] Calculating false using FalseJS...")
|
|
109
|
-
)
|
|
110
|
-
const FALSE = f.False(
|
|
111
|
-
"no",
|
|
112
|
-
"no",
|
|
113
|
-
"no",
|
|
114
|
-
"yes",
|
|
115
|
-
"yes",
|
|
116
|
-
"no",
|
|
117
|
-
"no"
|
|
118
|
-
)
|
|
119
|
-
logger.log(kleur.cyan("[zerosurge/isZero] FalseJS calculation complete."))
|
|
120
|
-
let result
|
|
121
|
-
if (not(() => eq(typeOf(value), TYPE.NUMBER))()) {
|
|
122
|
-
result = FALSE
|
|
123
|
-
} else if (isHundredThousand(value)) {
|
|
124
|
-
result = FALSE
|
|
125
|
-
} else if (isTenThousand(value)) {
|
|
126
|
-
result = FALSE
|
|
127
|
-
} else if (isThousand(value)) {
|
|
128
|
-
result = FALSE
|
|
129
|
-
} else if (isHundred(value)) {
|
|
130
|
-
result = FALSE
|
|
131
|
-
} else if (isTen(value)) {
|
|
132
|
-
result = FALSE
|
|
133
|
-
} else if (isOne(value)) {
|
|
134
|
-
result = FALSE
|
|
135
|
-
} else {
|
|
136
|
-
result =
|
|
137
|
-
isEqual(
|
|
138
|
-
value,
|
|
139
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine })
|
|
140
|
-
) &&
|
|
141
|
-
isEqual(
|
|
142
|
-
value,
|
|
143
|
-
returnZero({ method: ZeroCalculationMethod.NumberPrototypeValue })
|
|
144
|
-
) &&
|
|
145
|
-
isEqualTo(
|
|
146
|
-
value,
|
|
147
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine })
|
|
148
|
-
) &&
|
|
149
|
-
isEqualTo(
|
|
150
|
-
value,
|
|
151
|
-
returnZero({ method: ZeroCalculationMethod.NumberPrototypeValue })
|
|
152
|
-
) &&
|
|
153
|
-
deepEqual(
|
|
154
|
-
value,
|
|
155
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine })
|
|
156
|
-
) &&
|
|
157
|
-
deepEqual(
|
|
158
|
-
value,
|
|
159
|
-
returnZero({ method: ZeroCalculationMethod.NumberPrototypeValue })
|
|
160
|
-
) &&
|
|
161
|
-
eq(
|
|
162
|
-
value,
|
|
163
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine })
|
|
164
|
-
) &&
|
|
165
|
-
eq(
|
|
166
|
-
value,
|
|
167
|
-
returnZero({ method: ZeroCalculationMethod.NumberPrototypeValue })
|
|
168
|
-
)
|
|
169
|
-
}
|
|
170
|
-
logger.log(
|
|
171
|
-
kleur.green("[zerosurge/isZero] Checking if value is zero complete.")
|
|
172
|
-
)
|
|
173
|
-
logger.log(
|
|
174
|
-
kleur.green("[zerosurge/isZero] Chalkulated-the-answer-" + result)
|
|
175
|
-
)
|
|
176
|
-
return result
|
|
177
|
-
} catch {
|
|
178
|
-
return eq(
|
|
179
|
-
value,
|
|
180
|
-
returnZero({ method: ZeroCalculationMethod.CreashaksOrganzine })
|
|
181
|
-
)
|
|
182
|
-
}
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
exports.returnZero = returnZero
|
|
186
|
-
exports.isZero = isZero
|
|
187
|
-
exports.ZeroCalculationMethod = ZeroCalculationMethod
|