@jrc03c/make-key 0.0.41 → 0.0.43
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/dist/iife.mjs +1 -0
- package/dist/index.d.mts +2 -0
- package/dist/index.mjs +10 -0
- package/package.json +23 -10
- package/readme.md +0 -6
- package/.prettierrc.json +0 -10
- package/build.mjs +0 -24
- package/dist/make-key.js +0 -37
- package/dist/make-key.min.js +0 -1
- package/eslint.config.js +0 -19
- package/moon.yml +0 -29
- package/pnpm-workspace.yaml +0 -2
- package/src/bin.mjs +0 -19
- package/src/iife.mjs +0 -5
- package/src/index.mjs +0 -38
- package/src/index.test.mjs +0 -21
package/dist/iife.mjs
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
function e(e,t,n){t instanceof Array&&(t=t.join(``)),n||=Math.random;let r=``;t||=`abcdef1234567890`;for(let i=0;i<e;i++)r+=t[Math.floor(n()*t.length)];return r}Object.defineProperty(globalThis,"makeKey",{configurable:!0,enumerable:!0,writable:!0,value:e});export{};
|
package/dist/index.d.mts
ADDED
package/dist/index.mjs
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
// src/index.ts
|
|
2
|
+
function makeKey(length, charset, randomFn) {
|
|
3
|
+
if (charset instanceof Array) charset = charset.join("");
|
|
4
|
+
randomFn = randomFn || Math.random;
|
|
5
|
+
let out = "";
|
|
6
|
+
charset = charset || "abcdef1234567890";
|
|
7
|
+
for (let i = 0; i < length; i++) out += charset[Math.floor(randomFn() * charset.length)];
|
|
8
|
+
return out;
|
|
9
|
+
}
|
|
10
|
+
export { makeKey };
|
package/package.json
CHANGED
|
@@ -1,22 +1,35 @@
|
|
|
1
1
|
{
|
|
2
2
|
"bin": {
|
|
3
|
-
"key": "./src/bin.
|
|
3
|
+
"key": "npx tsx ./src/bin.ts"
|
|
4
4
|
},
|
|
5
5
|
"devDependencies": {
|
|
6
|
-
"
|
|
7
|
-
"
|
|
8
|
-
"
|
|
9
|
-
"
|
|
6
|
+
"eslint": "^9.39.5",
|
|
7
|
+
"prettier": "^3.9.10",
|
|
8
|
+
"tsdown": "^0.23.4",
|
|
9
|
+
"tsx": "^4.23.15",
|
|
10
|
+
"typescript": "^6.0.3",
|
|
11
|
+
"typescript-eslint": "^8.72.1",
|
|
12
|
+
"vitest": "^4.1.12"
|
|
10
13
|
},
|
|
14
|
+
"exports": {
|
|
15
|
+
".": {
|
|
16
|
+
"import": "./dist/index.mjs",
|
|
17
|
+
"types": "./dist/index.d.mts"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
20
|
+
"files": [
|
|
21
|
+
"dist"
|
|
22
|
+
],
|
|
11
23
|
"license": "ISC",
|
|
12
|
-
"main": "
|
|
13
|
-
"module": "
|
|
24
|
+
"main": "dist/index.mjs",
|
|
25
|
+
"module": "dist/index.mjs",
|
|
14
26
|
"name": "@jrc03c/make-key",
|
|
15
27
|
"scripts": {
|
|
16
|
-
"build": "
|
|
28
|
+
"build": "tsdown",
|
|
17
29
|
"pub": "npm version patch --force && npm publish --access=public",
|
|
18
|
-
"test": "
|
|
30
|
+
"test": "vitest run",
|
|
31
|
+
"watch": "tsdown --watch"
|
|
19
32
|
},
|
|
20
33
|
"type": "module",
|
|
21
|
-
"version": "0.0.
|
|
34
|
+
"version": "0.0.43"
|
|
22
35
|
}
|
package/readme.md
CHANGED
package/.prettierrc.json
DELETED
package/build.mjs
DELETED
|
@@ -1,24 +0,0 @@
|
|
|
1
|
-
import { execSync } from "node:child_process"
|
|
2
|
-
|
|
3
|
-
function rebuild() {
|
|
4
|
-
console.log("-----")
|
|
5
|
-
console.log(`\nRebuilding... (${new Date().toLocaleString()})`)
|
|
6
|
-
|
|
7
|
-
try {
|
|
8
|
-
execSync(
|
|
9
|
-
`npx esbuild src/iife.mjs --bundle --outfile=dist/make-key.js`,
|
|
10
|
-
{ encoding: "utf8" },
|
|
11
|
-
)
|
|
12
|
-
|
|
13
|
-
execSync(
|
|
14
|
-
`npx esbuild src/iife.mjs --bundle --minify --outfile=dist/make-key.min.js`,
|
|
15
|
-
{ encoding: "utf8" },
|
|
16
|
-
)
|
|
17
|
-
|
|
18
|
-
console.log("\nDone! 🎉\n")
|
|
19
|
-
} catch (e) {
|
|
20
|
-
console.error(e)
|
|
21
|
-
}
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
rebuild()
|
package/dist/make-key.js
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
(() => {
|
|
2
|
-
// src/index.mjs
|
|
3
|
-
function makeKey(keyLength, charset, randomFn) {
|
|
4
|
-
if (typeof keyLength !== "number" || isNaN(keyLength)) {
|
|
5
|
-
throw new Error(
|
|
6
|
-
"The first value passed into the `makeKey` function must be a number!"
|
|
7
|
-
);
|
|
8
|
-
}
|
|
9
|
-
if (charset) {
|
|
10
|
-
if (charset instanceof Array) {
|
|
11
|
-
charset = charset.join("");
|
|
12
|
-
}
|
|
13
|
-
if (typeof charset !== "string") {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"The second argument passed into the `makeKey` function must be a string or array of strings!"
|
|
16
|
-
);
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
randomFn = randomFn || Math.random;
|
|
20
|
-
if (typeof randomFn !== "function") {
|
|
21
|
-
throw new Error(
|
|
22
|
-
"The third argument passed into the `makeKey` function must be a function!"
|
|
23
|
-
);
|
|
24
|
-
}
|
|
25
|
-
let out = "";
|
|
26
|
-
charset = charset || "abcdef1234567890";
|
|
27
|
-
for (let i = 0; i < keyLength; i++) {
|
|
28
|
-
out += charset[Math.floor(randomFn() * charset.length)];
|
|
29
|
-
}
|
|
30
|
-
return out;
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// src/iife.mjs
|
|
34
|
-
if (typeof globalThis !== "undefined") {
|
|
35
|
-
globalThis.makeKey = makeKey;
|
|
36
|
-
}
|
|
37
|
-
})();
|
package/dist/make-key.min.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
(()=>{function f(t,e,o){if(typeof t!="number"||isNaN(t))throw new Error("The first value passed into the `makeKey` function must be a number!");if(e&&(e instanceof Array&&(e=e.join("")),typeof e!="string"))throw new Error("The second argument passed into the `makeKey` function must be a string or array of strings!");if(o=o||Math.random,typeof o!="function")throw new Error("The third argument passed into the `makeKey` function must be a function!");let i="";e=e||"abcdef1234567890";for(let n=0;n<t;n++)i+=e[Math.floor(o()*e.length)];return i}typeof globalThis<"u"&&(globalThis.makeKey=f);})();
|
package/eslint.config.js
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import globals from "globals"
|
|
2
|
-
import pluginJs from "@eslint/js"
|
|
3
|
-
|
|
4
|
-
export default [
|
|
5
|
-
{
|
|
6
|
-
languageOptions: {
|
|
7
|
-
globals: {
|
|
8
|
-
...globals.browser,
|
|
9
|
-
...globals.node,
|
|
10
|
-
},
|
|
11
|
-
},
|
|
12
|
-
|
|
13
|
-
rules: {
|
|
14
|
-
"no-empty": ["error", { allowEmptyCatch: true }],
|
|
15
|
-
"no-unused-vars": ["error", { caughtErrors: "none" }],
|
|
16
|
-
},
|
|
17
|
-
},
|
|
18
|
-
pluginJs.configs.recommended,
|
|
19
|
-
]
|
package/moon.yml
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
language: javascript
|
|
2
|
-
tasks:
|
|
3
|
-
build:
|
|
4
|
-
command:
|
|
5
|
-
- node
|
|
6
|
-
- build.mjs
|
|
7
|
-
platform: node
|
|
8
|
-
pub:
|
|
9
|
-
command:
|
|
10
|
-
- npm
|
|
11
|
-
- publish
|
|
12
|
-
- --access=public
|
|
13
|
-
deps:
|
|
14
|
-
- ~:pub-dep1
|
|
15
|
-
local: true
|
|
16
|
-
platform: node
|
|
17
|
-
pub-dep1:
|
|
18
|
-
command:
|
|
19
|
-
- npm
|
|
20
|
-
- version
|
|
21
|
-
- patch
|
|
22
|
-
- --force
|
|
23
|
-
local: true
|
|
24
|
-
platform: node
|
|
25
|
-
test:
|
|
26
|
-
command:
|
|
27
|
-
- npx
|
|
28
|
-
- fake-jest
|
|
29
|
-
platform: node
|
package/pnpm-workspace.yaml
DELETED
package/src/bin.mjs
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
#!/usr/bin/env node
|
|
2
|
-
import { exec } from "node:child_process"
|
|
3
|
-
import { makeKey } from "./index.mjs"
|
|
4
|
-
|
|
5
|
-
const args = process.argv.slice(2)
|
|
6
|
-
|
|
7
|
-
if (args.length === 0) {
|
|
8
|
-
console.log("SYNTAX: key <length> <charset>")
|
|
9
|
-
process.exit(0)
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
const keyLength = parseInt(args[0])
|
|
13
|
-
const charset = args[1]
|
|
14
|
-
const key = makeKey(keyLength, charset)
|
|
15
|
-
console.log(key)
|
|
16
|
-
|
|
17
|
-
try {
|
|
18
|
-
exec(`echo -n "${key}" | xsel -b`, () => {})
|
|
19
|
-
} catch (e) {}
|
package/src/iife.mjs
DELETED
package/src/index.mjs
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
function makeKey(keyLength, charset, randomFn) {
|
|
2
|
-
if (typeof keyLength !== "number" || isNaN(keyLength)) {
|
|
3
|
-
throw new Error(
|
|
4
|
-
"The first value passed into the `makeKey` function must be a number!",
|
|
5
|
-
)
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
if (charset) {
|
|
9
|
-
if (charset instanceof Array) {
|
|
10
|
-
charset = charset.join("")
|
|
11
|
-
}
|
|
12
|
-
|
|
13
|
-
if (typeof charset !== "string") {
|
|
14
|
-
throw new Error(
|
|
15
|
-
"The second argument passed into the `makeKey` function must be a string or array of strings!",
|
|
16
|
-
)
|
|
17
|
-
}
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
randomFn = randomFn || Math.random
|
|
21
|
-
|
|
22
|
-
if (typeof randomFn !== "function") {
|
|
23
|
-
throw new Error(
|
|
24
|
-
"The third argument passed into the `makeKey` function must be a function!",
|
|
25
|
-
)
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
let out = ""
|
|
29
|
-
charset = charset || "abcdef1234567890"
|
|
30
|
-
|
|
31
|
-
for (let i = 0; i < keyLength; i++) {
|
|
32
|
-
out += charset[Math.floor(randomFn() * charset.length)]
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
return out
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export { makeKey }
|
package/src/index.test.mjs
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { expect, test } from "@jrc03c/fake-jest"
|
|
2
|
-
import { makeKey } from "./index.mjs"
|
|
3
|
-
|
|
4
|
-
test("tests that random strings can be generated correctly", () => {
|
|
5
|
-
const a = makeKey(123)
|
|
6
|
-
expect(a.length).toBe(123)
|
|
7
|
-
|
|
8
|
-
const b = makeKey(123)
|
|
9
|
-
const c = makeKey(123)
|
|
10
|
-
expect(b).not.toBe(c)
|
|
11
|
-
|
|
12
|
-
const charset = "Hello, world!"
|
|
13
|
-
const d = makeKey(123, charset)
|
|
14
|
-
|
|
15
|
-
d.split("").forEach(char => {
|
|
16
|
-
expect(charset.includes(char)).toBe(true)
|
|
17
|
-
})
|
|
18
|
-
|
|
19
|
-
const e = makeKey(123, charset)
|
|
20
|
-
expect(e).not.toBe(d)
|
|
21
|
-
})
|