@jrc03c/make-key 0.0.43 → 0.0.44

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.
@@ -0,0 +1,10 @@
1
+ {
2
+ "arrowParens": "avoid",
3
+ "bracketSameLine": true,
4
+ "htmlWhitespaceSensitivity": "ignore",
5
+ "semi": false,
6
+ "singleQuote": false,
7
+ "tabWidth": 2,
8
+ "useTabs": false,
9
+ "vueIndentScriptAndStyle": true
10
+ }
package/build.mjs ADDED
@@ -0,0 +1,24 @@
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()
@@ -0,0 +1,37 @@
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
+ })();
@@ -0,0 +1 @@
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);})();
@@ -0,0 +1,19 @@
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 ADDED
@@ -0,0 +1,29 @@
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/package.json CHANGED
@@ -1,35 +1,22 @@
1
1
  {
2
2
  "bin": {
3
- "key": "npx tsx ./src/bin.ts"
3
+ "key": "./src/bin.mjs"
4
4
  },
5
5
  "devDependencies": {
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"
6
+ "esbuild": "^0.25.4",
7
+ "eslint": "^9.38.0",
8
+ "prettier": "^3.6.2",
9
+ "vitest": "^4.1.10"
13
10
  },
14
- "exports": {
15
- ".": {
16
- "import": "./dist/index.mjs",
17
- "types": "./dist/index.d.mts"
18
- }
19
- },
20
- "files": [
21
- "dist"
22
- ],
23
11
  "license": "ISC",
24
- "main": "dist/index.mjs",
25
- "module": "dist/index.mjs",
12
+ "main": "./src/index.mjs",
13
+ "module": "./src/index.mjs",
26
14
  "name": "@jrc03c/make-key",
27
15
  "scripts": {
28
- "build": "tsdown",
16
+ "build": "node build.mjs",
29
17
  "pub": "npm version patch --force && npm publish --access=public",
30
- "test": "vitest run",
31
- "watch": "tsdown --watch"
18
+ "test": "npx vitest run"
32
19
  },
33
20
  "type": "module",
34
- "version": "0.0.43"
21
+ "version": "0.0.44"
35
22
  }
@@ -0,0 +1,4 @@
1
+ allowBuilds:
2
+ esbuild: true
3
+ onlyBuiltDependencies:
4
+ - esbuild
package/readme.md CHANGED
@@ -50,6 +50,12 @@ cd make-key
50
50
  npm link
51
51
  ```
52
52
 
53
+ Optionally, you can install `xsel` to have the key be copied automatically to the clipboard:
54
+
55
+ ```bash
56
+ sudo apt-get install -y xsel
57
+ ```
58
+
53
59
  ## Usage
54
60
 
55
61
  ```bash
package/src/bin.mjs ADDED
@@ -0,0 +1,19 @@
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 ADDED
@@ -0,0 +1,5 @@
1
+ import { makeKey } from "./index.mjs"
2
+
3
+ if (typeof globalThis !== "undefined") {
4
+ globalThis.makeKey = makeKey
5
+ }
package/src/index.mjs ADDED
@@ -0,0 +1,38 @@
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 }
@@ -0,0 +1,21 @@
1
+ import { expect, test } from "vitest"
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
+ })
package/dist/iife.mjs DELETED
@@ -1 +0,0 @@
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 DELETED
@@ -1,2 +0,0 @@
1
- declare function makeKey(length: number, charset?: string | string[], randomFn?: () => number): string;
2
- export { makeKey };
package/dist/index.mjs DELETED
@@ -1,10 +0,0 @@
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 };