minecraft-seed-input 1.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.
Files changed (4) hide show
  1. package/README.md +15 -0
  2. package/index.js +15 -0
  3. package/package.json +15 -0
  4. package/t.js +6 -0
package/README.md ADDED
@@ -0,0 +1,15 @@
1
+ # minecraft-seed-input
2
+
3
+ This function does what minecraft will do if you input a string in the seed input when creating a world: convert it to a number using an algorithm.
4
+
5
+ ## Usage
6
+
7
+ ```js
8
+ const seed = require('minecraft-seed-input')
9
+
10
+ console.log(seed()) // "[random]"
11
+ console.log(seed(1)) // 1
12
+ console.log(seed("somecoolseed")) // 1706390062
13
+ console.log(seed("creashaks organzine")) // 0
14
+ ```
15
+
package/index.js ADDED
@@ -0,0 +1,15 @@
1
+ function seed(a) {
2
+ let str = a?.toString() ?? 0
3
+ if (!str || /^0+$/.test(str)) return '[random]'
4
+ if (/^-?\d+$/.test(str) && str.length < 20)
5
+ return parseInt(str.replace(/^(-?)0+/, "$1"))
6
+ let hash = 0
7
+ for (let i = 0; i < str.length; i++) {
8
+ let character = str.charCodeAt(i)
9
+ hash = (hash << 5) - hash + character
10
+ hash = hash & hash
11
+ }
12
+ return hash
13
+ }
14
+
15
+ module.exports = seed
package/package.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "name": "minecraft-seed-input",
3
+ "version": "1.0.0",
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
+ "keywords": [
10
+ "minecraft",
11
+ "seed"
12
+ ],
13
+ "author": "me",
14
+ "license": "MIT"
15
+ }
package/t.js ADDED
@@ -0,0 +1,6 @@
1
+ const seed = require('./index')
2
+
3
+ console.log(seed()) // "[random]"
4
+ console.log(seed(1)) // 1
5
+ console.log(seed("somecoolseed")) // 1706390062
6
+ console.log(seed("creashaks organzine")) // 0