@jrc03c/make-key 0.0.2
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/bin.js +24 -0
- package/index.js +30 -0
- package/package.json +19 -0
- package/readme.md +48 -0
package/bin.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
const { exec } = require("child_process")
|
|
3
|
+
const makeKey = require("./index.js")
|
|
4
|
+
|
|
5
|
+
if (typeof require !== "undefined" && require.main === module) {
|
|
6
|
+
if (process.argv.length <= 2) {
|
|
7
|
+
console.log("You must specify a key length.")
|
|
8
|
+
process.exit(0)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
let keyLength = parseInt(process.argv[2])
|
|
12
|
+
let keySeed = null
|
|
13
|
+
|
|
14
|
+
try {
|
|
15
|
+
keySeed = parseInt(process.argv[3])
|
|
16
|
+
} catch (e) {}
|
|
17
|
+
|
|
18
|
+
const key = makeKey(keyLength, keySeed)
|
|
19
|
+
console.log(key)
|
|
20
|
+
|
|
21
|
+
try {
|
|
22
|
+
exec(`echo "${key}" | xsel -b`, () => {})
|
|
23
|
+
} catch (e) {}
|
|
24
|
+
}
|
package/index.js
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
const { assert, isNumber, int, seed, random } = require("@jrc03c/js-math-tools")
|
|
2
|
+
|
|
3
|
+
function makeKey(keyLength, keySeed) {
|
|
4
|
+
assert(
|
|
5
|
+
isNumber(keyLength) && int(keyLength) === keyLength,
|
|
6
|
+
"`keyLength` must be an integer!"
|
|
7
|
+
)
|
|
8
|
+
|
|
9
|
+
if (keySeed) {
|
|
10
|
+
assert(
|
|
11
|
+
isNumber(keySeed) && int(keySeed) === keySeed,
|
|
12
|
+
"`keySeed` must be an integer!"
|
|
13
|
+
)
|
|
14
|
+
|
|
15
|
+
seed(keySeed)
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
let out = ""
|
|
19
|
+
let alpha = "abcdefghijklmnopqrstuvwxyz1234567890"
|
|
20
|
+
|
|
21
|
+
for (let i = 0; i < keyLength; i++) {
|
|
22
|
+
out += alpha[int(random() * alpha.length)]
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return out
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
if (typeof module !== "undefined") {
|
|
29
|
+
module.exports = makeKey
|
|
30
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@jrc03c/make-key",
|
|
3
|
+
"version": "0.0.2",
|
|
4
|
+
"description": "",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"scripts": {
|
|
7
|
+
"test": "echo \"Error: no test specified\" && exit 1"
|
|
8
|
+
},
|
|
9
|
+
"keywords": [],
|
|
10
|
+
"author": "",
|
|
11
|
+
"license": "ISC",
|
|
12
|
+
"bin": {
|
|
13
|
+
"makeKey": "./bin.js",
|
|
14
|
+
"key": "./bin.js"
|
|
15
|
+
},
|
|
16
|
+
"dependencies": {
|
|
17
|
+
"@jrc03c/js-math-tools": "github:jrc03c/js-math-tools"
|
|
18
|
+
}
|
|
19
|
+
}
|
package/readme.md
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
# Intro
|
|
2
|
+
|
|
3
|
+
**make-key** generates alphanumeric strings of arbitrary length.
|
|
4
|
+
|
|
5
|
+
# Node / browser
|
|
6
|
+
|
|
7
|
+
## Installation
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install --save https://github.com/jrc03c/make-key
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Usage
|
|
14
|
+
|
|
15
|
+
```js
|
|
16
|
+
let makeKey = require("@jrc03c/make-key")
|
|
17
|
+
let keyLength = 32
|
|
18
|
+
let keySeed = 1234
|
|
19
|
+
|
|
20
|
+
console.log(makeKey(keyLength))
|
|
21
|
+
// "8v1101x1whevcm1cgdhuq90e12549xri"
|
|
22
|
+
|
|
23
|
+
console.log(makeKey(keyLength, keySeed))
|
|
24
|
+
// "dcb09fuuv3smirvqaetiyggvhap90e88"
|
|
25
|
+
```
|
|
26
|
+
|
|
27
|
+
# CLI
|
|
28
|
+
|
|
29
|
+
## Installation
|
|
30
|
+
|
|
31
|
+
```bash
|
|
32
|
+
git clone https://github.com/jrc03c/make-key
|
|
33
|
+
cd make-key
|
|
34
|
+
npm link
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
Optionally, you can install `xsel` to automatically have the key copied to the clipboard:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
sudo apt-get install -y xsel
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## Usage
|
|
44
|
+
|
|
45
|
+
```bash
|
|
46
|
+
# key <length> <seed-integer>
|
|
47
|
+
key 32 12345
|
|
48
|
+
```
|