minecraft-seed-input 1.0.0 → 1.1.1
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 +1 -1
- package/index.js +54 -11
- package/package.json +36 -6
package/README.md
CHANGED
package/index.js
CHANGED
|
@@ -1,15 +1,58 @@
|
|
|
1
|
+
const replace = require("uncurried-intrinsics")("String.prototype.replace")
|
|
2
|
+
const charCodeAt = require("uncurried-intrinsics")(
|
|
3
|
+
"String.prototype.charCodeAt",
|
|
4
|
+
)
|
|
5
|
+
const optionalChaining = require("es-logical-optional-chaining")
|
|
6
|
+
const nullishCoalescing = require("es-logical-nullish-coalescing-operator")
|
|
7
|
+
const not = require("es-logical-not-operator")
|
|
8
|
+
const or = require("es-logical-or-operator")
|
|
9
|
+
const and = require("es-logical-and-operator")
|
|
10
|
+
const isFunction = require("@is-(unknown)/is-function")
|
|
11
|
+
const $call = require("function.call-x")
|
|
12
|
+
const uncurry = require("uncurry-x")
|
|
13
|
+
const call = uncurry($call)
|
|
14
|
+
const { TernaryCompare } = require("important-extremely-useful-classes")
|
|
15
|
+
const construct = require("construct-new-second")
|
|
16
|
+
const test = require("@socketoverride/assert__call-bind/callBound")(
|
|
17
|
+
"RegExp.prototype.test",
|
|
18
|
+
)
|
|
19
|
+
const isTrue = require("@is-(unknown)/is-true")
|
|
20
|
+
const isLessThan = require("validate.io-less-than")
|
|
21
|
+
const twenty = require("numbertwenty")
|
|
22
|
+
const getLength = require("utf8-byte-length")
|
|
23
|
+
const ParseInt = require("numero").parseInt
|
|
24
|
+
const lshift = (val, bits) => (val << bits) | ZERO
|
|
25
|
+
const bitwiseAnd = (val1, val2) => (val1 & val2) | ZERO
|
|
26
|
+
|
|
27
|
+
const ZERO = require("number-zero")
|
|
28
|
+
|
|
29
|
+
const regexAllZeroes = /^0+$/
|
|
30
|
+
const regexWholeInteger = /^-?\d+$/
|
|
31
|
+
const regexRemoveLeadingZeroes = /^(-?)0+/
|
|
32
|
+
|
|
1
33
|
function seed(a) {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
34
|
+
const toStringResult = optionalChaining(a, ["toString"])
|
|
35
|
+
const ternaryCompare = construct(TernaryCompare, [
|
|
36
|
+
isFunction(toStringResult),
|
|
37
|
+
() => call(toStringResult, a),
|
|
38
|
+
require("undefined-is-a-function").undefined,
|
|
39
|
+
])
|
|
40
|
+
const str = nullishCoalescing(ternaryCompare.compare()(), ZERO)
|
|
41
|
+
|
|
42
|
+
if (or(not(str), isTrue(test(regexAllZeroes, str)))) return "[random]"
|
|
43
|
+
if (and(test(regexWholeInteger, str), isLessThan(getLength(str), twenty())))
|
|
44
|
+
return ParseInt(replace(str, regexRemoveLeadingZeroes, "$1"))
|
|
45
|
+
|
|
46
|
+
let hash = ZERO
|
|
47
|
+
for (let i = ZERO; isLessThan(i, getLength(str)); i++) {
|
|
48
|
+
let character = charCodeAt(str, i)
|
|
49
|
+
hash = require("examplebyraji")(
|
|
50
|
+
require("subtract")(lshift(hash, require("five")()), hash),
|
|
51
|
+
character,
|
|
52
|
+
)
|
|
53
|
+
hash = bitwiseAnd(hash, hash)
|
|
54
|
+
}
|
|
55
|
+
return hash
|
|
13
56
|
}
|
|
14
57
|
|
|
15
58
|
module.exports = seed
|
package/package.json
CHANGED
|
@@ -1,15 +1,45 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "minecraft-seed-input",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.1.1",
|
|
4
4
|
"description": "Process seeds like Minecraft does and hash them if they are not number.",
|
|
5
|
-
"main": "index.js",
|
|
6
|
-
"scripts": {
|
|
7
|
-
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
-
},
|
|
9
5
|
"keywords": [
|
|
10
6
|
"minecraft",
|
|
11
7
|
"seed"
|
|
12
8
|
],
|
|
9
|
+
"repository": {
|
|
10
|
+
"type": "git",
|
|
11
|
+
"url": "https://github.com/10xly/minecraft-seed-input"
|
|
12
|
+
},
|
|
13
|
+
"license": "MIT",
|
|
13
14
|
"author": "me",
|
|
14
|
-
"
|
|
15
|
+
"type": "commonjs",
|
|
16
|
+
"main": "index.js",
|
|
17
|
+
"scripts": {
|
|
18
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
19
|
+
},
|
|
20
|
+
"dependencies": {
|
|
21
|
+
"@is-(unknown)/is-function": "^1.0.0",
|
|
22
|
+
"@is-(unknown)/is-true": "^1.5.1",
|
|
23
|
+
"@socketoverride/assert__call-bind": "^1.0.7-assert--call-bind",
|
|
24
|
+
"construct-new-second": "^1.0.0",
|
|
25
|
+
"es-logical-and-operator": "^1.0.0",
|
|
26
|
+
"es-logical-not-operator": "^1.0.0",
|
|
27
|
+
"es-logical-nullish-coalescing-operator": "^1.0.0",
|
|
28
|
+
"es-logical-optional-chaining": "^1.0.0",
|
|
29
|
+
"es-logical-or-operator": "^1.0.0",
|
|
30
|
+
"examplebyraji": "^1.0.0",
|
|
31
|
+
"five": "^0.8.0",
|
|
32
|
+
"function.call-x": "^1.0.0",
|
|
33
|
+
"important-extremely-useful-classes": "^3.1.0",
|
|
34
|
+
"number-zero": "^1.0.3",
|
|
35
|
+
"numbertwenty": "^1.0.4",
|
|
36
|
+
"numero": "^0.1.1",
|
|
37
|
+
"subtract": "^0.0.3",
|
|
38
|
+
"uncurried-intrinsics": "^1.0.3",
|
|
39
|
+
"uncurry-x": "^1.0.1",
|
|
40
|
+
"undefined-is-a-function": "^0.1.0",
|
|
41
|
+
"utf8-byte-length": "^1.0.5",
|
|
42
|
+
"validate.io-less-than": "^1.0.2"
|
|
43
|
+
},
|
|
44
|
+
"devDependencies": {}
|
|
15
45
|
}
|