@nymphjs/guid 1.0.0-beta.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.
@@ -0,0 +1 @@
1
+ export {};
package/jest.config.js ADDED
@@ -0,0 +1,6 @@
1
+ /** @type {import('ts-jest').JestConfigWithTsJest} */
2
+ module.exports = {
3
+ preset: 'ts-jest/presets/default-esm',
4
+ testEnvironment: 'node',
5
+ rootDir: 'src/',
6
+ };
package/package.json ADDED
@@ -0,0 +1,54 @@
1
+ {
2
+ "name": "@nymphjs/guid",
3
+ "version": "1.0.0-beta.0",
4
+ "description": "NymphJS - GUID and Unique Code Generators",
5
+ "type": "commonjs",
6
+ "main": "dist/index.js",
7
+ "types": "dist/index.d.ts",
8
+ "keywords": [
9
+ "nymph",
10
+ "ORM",
11
+ "object relational mapper",
12
+ "guid"
13
+ ],
14
+ "scripts": {
15
+ "clean": "test -d dist && rm -r dist || true",
16
+ "build": "rollup -c",
17
+ "watch": "rollup -c --watch",
18
+ "prepare": "npm run clean && npm run build",
19
+ "test": "NODE_OPTIONS=--experimental-vm-modules npx jest",
20
+ "test:watch": "NODE_OPTIONS=--experimental-vm-modules npx jest --watch"
21
+ },
22
+ "publishConfig": {
23
+ "access": "public"
24
+ },
25
+ "repository": {
26
+ "type": "git",
27
+ "url": "git+https://github.com/sciactive/nymphjs.git"
28
+ },
29
+ "author": "Hunter Perrin <hperrin@gmail.com>",
30
+ "bugs": {
31
+ "url": "https://github.com/sciactive/nymphjs/issues"
32
+ },
33
+ "license": "Apache-2.0",
34
+ "devDependencies": {
35
+ "@rollup/plugin-commonjs": "^23.0.2",
36
+ "@rollup/plugin-node-resolve": "^15.0.1",
37
+ "@rollup/plugin-typescript": "^9.0.2",
38
+ "@tsconfig/recommended": "^1.0.1",
39
+ "@types/jest": "^29.2.3",
40
+ "@types/luxon": "^3.1.0",
41
+ "@types/nanoid-dictionary": "^4.2.0",
42
+ "@types/sha1": "^1.1.3",
43
+ "jest": "^29.3.1",
44
+ "luxon": "^3.1.0",
45
+ "nanoid": "^4.0.0",
46
+ "nanoid-dictionary": "^4.3.0",
47
+ "rollup": "^3.3.0",
48
+ "sha1": "^1.1.1",
49
+ "ts-jest": "^29.0.3",
50
+ "tslib": "^2.4.1",
51
+ "typescript": "^4.9.3"
52
+ },
53
+ "gitHead": "80622ad09351ad12519208e7edb0b0db412fae50"
54
+ }
@@ -0,0 +1,12 @@
1
+ import typescript from '@rollup/plugin-typescript';
2
+ import { nodeResolve } from '@rollup/plugin-node-resolve';
3
+ import commonjs from '@rollup/plugin-commonjs';
4
+
5
+ export default {
6
+ input: 'src/index.ts',
7
+ output: {
8
+ file: 'dist/index.js',
9
+ format: 'cjs',
10
+ },
11
+ plugins: [nodeResolve(), commonjs(), typescript()],
12
+ };
@@ -0,0 +1,47 @@
1
+ import {
2
+ nanoid as realNanoid,
3
+ customAlphabet as realCustomAlphabet,
4
+ } from 'nanoid';
5
+
6
+ import {
7
+ guid,
8
+ makeTableSuffix,
9
+ humanSecret,
10
+ nanoid,
11
+ customAlphabet,
12
+ } from './index';
13
+
14
+ describe('GUID', () => {
15
+ it('exports nanoid and customAlphabet', () => {
16
+ expect(nanoid).toBe(realNanoid);
17
+ expect(customAlphabet).toBe(realCustomAlphabet);
18
+ });
19
+
20
+ it('generates GUIDs', () => {
21
+ let guid1 = guid();
22
+ let guid2 = guid();
23
+
24
+ expect(guid1.length).toBe(24);
25
+ expect(guid2.length).toBe(24);
26
+ expect(guid1).not.toEqual(guid2);
27
+ expect(guid1.substring(0, 4)).toEqual(guid2.substring(0, 4));
28
+ });
29
+
30
+ it('generates table suffixes', () => {
31
+ let tableSuffix1 = makeTableSuffix();
32
+ let tableSuffix2 = makeTableSuffix();
33
+
34
+ expect(tableSuffix1.length).toBe(20);
35
+ expect(tableSuffix2.length).toBe(20);
36
+ expect(tableSuffix1).not.toEqual(tableSuffix2);
37
+ });
38
+
39
+ it('generates human readable secrets', () => {
40
+ let secret1 = humanSecret();
41
+ let secret2 = humanSecret();
42
+
43
+ expect(secret1.length).toBe(10);
44
+ expect(secret2.length).toBe(10);
45
+ expect(secret1).not.toEqual(secret2);
46
+ });
47
+ });
package/src/index.ts ADDED
@@ -0,0 +1,22 @@
1
+ import { nanoid, customAlphabet } from 'nanoid';
2
+ import { DateTime } from 'luxon';
3
+ import sha1 from 'sha1';
4
+ import dictionary from 'nanoid-dictionary';
5
+
6
+ const { nolookalikesSafe } = dictionary;
7
+
8
+ const guidSuffix = customAlphabet('0123456789abcdef', 20);
9
+ export function guid() {
10
+ return `${sha1(
11
+ `${DateTime.now().weekYear}${DateTime.now().weekNumber}`
12
+ ).slice(0, 4)}${guidSuffix()}`;
13
+ }
14
+
15
+ export const makeTableSuffix = customAlphabet(
16
+ '0123456789abcdefghijklmnopqrstuvwxyz',
17
+ 20
18
+ );
19
+
20
+ export const humanSecret = customAlphabet(nolookalikesSafe, 10);
21
+
22
+ export { nanoid, customAlphabet };
package/tsconfig.json ADDED
@@ -0,0 +1,15 @@
1
+ {
2
+ "extends": "@tsconfig/recommended/tsconfig.json",
3
+
4
+ "compilerOptions": {
5
+ "noImplicitAny": true,
6
+ "removeComments": true,
7
+ "sourceMap": true,
8
+ "outDir": "dist",
9
+ "resolveJsonModule": true,
10
+ "rootDir": "src/",
11
+ "declaration": true
12
+ },
13
+ "include": ["src/**/*"],
14
+ "exclude": ["node_modules", "**/*.spec.ts"]
15
+ }