uuid-hash 1.1.4 → 2.0.3

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/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 Dan Lynch <pyramation@gmail.com>
3
+ Copyright (c) 2024 Dan Lynch <pyramation@gmail.com>
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
package/README.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # UUID Hash
2
2
 
3
+ <p align="center" width="100%">
4
+ <img height="250" src="https://github.com/user-attachments/assets/d0456af5-b6e9-422e-a45d-2574d5be490f" />
5
+ </p>
6
+
7
+ <p align="center" width="100%">
8
+ <a href="https://github.com/launchql/launchql-2.0/actions/workflows/run-tests.yaml">
9
+ <img height="20" src="https://github.com/launchql/launchql-2.0/actions/workflows/run-tests.yaml/badge.svg" />
10
+ </a>
11
+ <a href="https://github.com/launchql/launchql-2.0/blob/main/LICENSE-MIT"><img height="20" src="https://img.shields.io/badge/license-MIT-blue.svg"/></a>
12
+ <a href="https://www.npmjs.com/package/uuid-hash"><img height="20" src="https://img.shields.io/github/package-json/v/launchql/launchql-2.0?filename=packages%2Fuuid-hash%2Fpackage.json"/></a>
13
+ </p>
14
+
3
15
  Es6 class that generates RFC-compliant UUID v5.
4
16
 
5
17
  ## Installation
@@ -15,4 +27,4 @@ const uuid = require('uuid-hash');
15
27
  const identifier = uuid.createHash().update(contents).digest();
16
28
  ```
17
29
 
18
- Just like [node-uuid](https://github.com/kelektiv/node-uuid) for uuid v5, but removed the need to have all contents in-memory to be compatible with streams. API similar to the crypto module.
30
+ Just like [node-uuid](https://github.com/kelektiv/node-uuid) for uuid v5, but removed the need to have all contents in-memory to be compatible with streams. API similar to the crypto module.
package/esm/index.js ADDED
@@ -0,0 +1,81 @@
1
+ import { createHash as createCryptoHash } from 'crypto';
2
+ export const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
3
+ export const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
4
+ const convertToBuffer = (bytes) => {
5
+ if (Array.isArray(bytes)) {
6
+ return Buffer.from(bytes);
7
+ }
8
+ else if (typeof bytes === 'string') {
9
+ return Buffer.from(bytes, 'utf8');
10
+ }
11
+ return bytes;
12
+ };
13
+ const uuidToBytes = (uuid) => {
14
+ const bytes = [];
15
+ uuid.replace(/[a-fA-F0-9]{2}/g, (hex) => {
16
+ bytes.push(parseInt(hex, 16));
17
+ return '';
18
+ });
19
+ return bytes;
20
+ };
21
+ const hex = [];
22
+ for (let i = 0; i < 256; i++) {
23
+ hex[i] = (i < 16 ? '0' : '') + i.toString(16);
24
+ }
25
+ const hexToBytes = (hexStr) => {
26
+ const bytes = [];
27
+ for (let c = 0; c < hexStr.length; c += 2) {
28
+ bytes.push(parseInt(hexStr.substr(c, 2), 16));
29
+ }
30
+ return bytes;
31
+ };
32
+ export class UuidHash {
33
+ version;
34
+ namespace;
35
+ shasum;
36
+ constructor(namespace = URL, version = 0x50) {
37
+ this.version = version;
38
+ this.namespace = namespace;
39
+ this.shasum = createCryptoHash('sha1');
40
+ this.shasum.update(convertToBuffer(this.namespace));
41
+ if (typeof this.namespace === 'string') {
42
+ this.namespace = uuidToBytes(this.namespace);
43
+ }
44
+ if (!Array.isArray(this.namespace) || this.namespace.length !== 16) {
45
+ throw new Error('namespace must be uuid string or an Array of 16 byte values');
46
+ }
47
+ }
48
+ update(chunk) {
49
+ this.shasum.update(convertToBuffer(chunk));
50
+ return this;
51
+ }
52
+ digest() {
53
+ const r = hexToBytes(this.shasum.digest('hex'));
54
+ r[6] = (r[6] & 0x0f) | this.version;
55
+ r[8] = (r[8] & 0x3f) | 0x80;
56
+ return (hex[r[0]] +
57
+ hex[r[1]] +
58
+ hex[r[2]] +
59
+ hex[r[3]] +
60
+ '-' +
61
+ hex[r[4]] +
62
+ hex[r[5]] +
63
+ '-' +
64
+ hex[r[6]] +
65
+ hex[r[7]] +
66
+ '-' +
67
+ hex[r[8]] +
68
+ hex[r[9]] +
69
+ '-' +
70
+ hex[r[10]] +
71
+ hex[r[11]] +
72
+ hex[r[12]] +
73
+ hex[r[13]] +
74
+ hex[r[14]] +
75
+ hex[r[15]]);
76
+ }
77
+ }
78
+ export const createHash = (...args) => {
79
+ return new UuidHash(...args);
80
+ };
81
+ export default UuidHash;
package/index.d.ts ADDED
@@ -0,0 +1,12 @@
1
+ export declare const DNS = "6ba7b810-9dad-11d1-80b4-00c04fd430c8";
2
+ export declare const URL = "6ba7b811-9dad-11d1-80b4-00c04fd430c8";
3
+ export declare class UuidHash {
4
+ private version;
5
+ private namespace;
6
+ private shasum;
7
+ constructor(namespace?: string | number[], version?: number);
8
+ update(chunk: string | number[] | Buffer): this;
9
+ digest(): string;
10
+ }
11
+ export declare const createHash: (namespace?: string | number[], version?: number) => UuidHash;
12
+ export default UuidHash;
package/index.js ADDED
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.createHash = exports.UuidHash = exports.URL = exports.DNS = void 0;
4
+ const crypto_1 = require("crypto");
5
+ exports.DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
6
+ exports.URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
7
+ const convertToBuffer = (bytes) => {
8
+ if (Array.isArray(bytes)) {
9
+ return Buffer.from(bytes);
10
+ }
11
+ else if (typeof bytes === 'string') {
12
+ return Buffer.from(bytes, 'utf8');
13
+ }
14
+ return bytes;
15
+ };
16
+ const uuidToBytes = (uuid) => {
17
+ const bytes = [];
18
+ uuid.replace(/[a-fA-F0-9]{2}/g, (hex) => {
19
+ bytes.push(parseInt(hex, 16));
20
+ return '';
21
+ });
22
+ return bytes;
23
+ };
24
+ const hex = [];
25
+ for (let i = 0; i < 256; i++) {
26
+ hex[i] = (i < 16 ? '0' : '') + i.toString(16);
27
+ }
28
+ const hexToBytes = (hexStr) => {
29
+ const bytes = [];
30
+ for (let c = 0; c < hexStr.length; c += 2) {
31
+ bytes.push(parseInt(hexStr.substr(c, 2), 16));
32
+ }
33
+ return bytes;
34
+ };
35
+ class UuidHash {
36
+ version;
37
+ namespace;
38
+ shasum;
39
+ constructor(namespace = exports.URL, version = 0x50) {
40
+ this.version = version;
41
+ this.namespace = namespace;
42
+ this.shasum = (0, crypto_1.createHash)('sha1');
43
+ this.shasum.update(convertToBuffer(this.namespace));
44
+ if (typeof this.namespace === 'string') {
45
+ this.namespace = uuidToBytes(this.namespace);
46
+ }
47
+ if (!Array.isArray(this.namespace) || this.namespace.length !== 16) {
48
+ throw new Error('namespace must be uuid string or an Array of 16 byte values');
49
+ }
50
+ }
51
+ update(chunk) {
52
+ this.shasum.update(convertToBuffer(chunk));
53
+ return this;
54
+ }
55
+ digest() {
56
+ const r = hexToBytes(this.shasum.digest('hex'));
57
+ r[6] = (r[6] & 0x0f) | this.version;
58
+ r[8] = (r[8] & 0x3f) | 0x80;
59
+ return (hex[r[0]] +
60
+ hex[r[1]] +
61
+ hex[r[2]] +
62
+ hex[r[3]] +
63
+ '-' +
64
+ hex[r[4]] +
65
+ hex[r[5]] +
66
+ '-' +
67
+ hex[r[6]] +
68
+ hex[r[7]] +
69
+ '-' +
70
+ hex[r[8]] +
71
+ hex[r[9]] +
72
+ '-' +
73
+ hex[r[10]] +
74
+ hex[r[11]] +
75
+ hex[r[12]] +
76
+ hex[r[13]] +
77
+ hex[r[14]] +
78
+ hex[r[15]]);
79
+ }
80
+ }
81
+ exports.UuidHash = UuidHash;
82
+ const createHash = (...args) => {
83
+ return new UuidHash(...args);
84
+ };
85
+ exports.createHash = createHash;
86
+ exports.default = UuidHash;
package/package.json CHANGED
@@ -1,38 +1,33 @@
1
1
  {
2
2
  "name": "uuid-hash",
3
- "version": "1.1.4",
4
- "description": "Es6 class that generates RFC-compliant UUID v5.",
3
+ "version": "2.0.3",
5
4
  "author": "Dan Lynch <pyramation@gmail.com>",
6
- "homepage": "https://github.com/pyramation/uuid-hash#readme",
5
+ "description": "Es6 class that generates RFC-compliant UUID v5.",
6
+ "main": "index.js",
7
+ "module": "esm/index.js",
8
+ "types": "index.d.ts",
9
+ "homepage": "https://github.com/launchql/launchql",
7
10
  "license": "SEE LICENSE IN LICENSE",
8
- "main": "main/index.js",
9
- "module": "module/index.js",
10
- "directories": {
11
- "lib": "src",
12
- "test": "__tests__"
13
- },
14
- "files": [
15
- "main",
16
- "module"
17
- ],
18
- "scripts": {
19
- "build:main": "cross-env BABEL_ENV=production babel src --out-dir main --delete-dir-on-start",
20
- "build:module": "cross-env MODULE=true babel src --out-dir module --delete-dir-on-start",
21
- "build": "npm run build:module && npm run build:main",
22
- "prepublish": "npm run build",
23
- "dev": "cross-env NODE_ENV=development babel-node src/index",
24
- "watch": "cross-env NODE_ENV=development babel-watch src/index",
25
- "lint": "eslint src --fix",
26
- "test": "jest",
27
- "test:watch": "jest --watch",
28
- "test:debug": "node --inspect node_modules/.bin/jest --runInBand"
29
- },
30
11
  "publishConfig": {
31
- "access": "public"
12
+ "access": "public",
13
+ "directory": "dist"
32
14
  },
33
15
  "repository": {
34
16
  "type": "git",
35
- "url": "https://github.com/pyramation/uuid-hash"
17
+ "url": "https://github.com/launchql/launchql"
18
+ },
19
+ "bugs": {
20
+ "url": "https://github.com/launchql/launchql/issues"
21
+ },
22
+ "scripts": {
23
+ "copy": "copyfiles -f ../../LICENSE README.md package.json dist",
24
+ "clean": "rimraf dist/**",
25
+ "prepare": "npm run build",
26
+ "build": "npm run clean; tsc; tsc -p tsconfig.esm.json; npm run copy",
27
+ "build:dev": "npm run clean; tsc --declarationMap; tsc -p tsconfig.esm.json; npm run copy",
28
+ "lint": "eslint . --fix",
29
+ "test": "jest",
30
+ "test:watch": "jest --watch"
36
31
  },
37
32
  "keywords": [
38
33
  "hash",
@@ -40,32 +35,5 @@
40
35
  "uuidv5",
41
36
  "uuid"
42
37
  ],
43
- "bugs": {
44
- "url": "https://github.com/pyramation/uuid-hash/issues"
45
- },
46
- "devDependencies": {
47
- "@babel/cli": "7.11.6",
48
- "@babel/core": "7.11.6",
49
- "@babel/node": "^7.10.5",
50
- "@babel/plugin-proposal-class-properties": "7.10.4",
51
- "@babel/plugin-proposal-export-default-from": "7.10.4",
52
- "@babel/plugin-proposal-object-rest-spread": "7.11.0",
53
- "@babel/plugin-transform-runtime": "7.11.5",
54
- "@babel/preset-env": "7.11.5",
55
- "babel-core": "7.0.0-bridge.0",
56
- "babel-eslint": "10.1.0",
57
- "babel-jest": "25.1.0",
58
- "babel-watch": "^7.0.0",
59
- "cross-env": "^7.0.2",
60
- "eslint": "6.8.0",
61
- "eslint-config-prettier": "^6.10.0",
62
- "eslint-plugin-prettier": "^3.1.2",
63
- "jest": "^24.5.0",
64
- "jest-in-case": "^1.0.2",
65
- "prettier": "^2.1.2",
66
- "regenerator-runtime": "^0.13.7"
67
- },
68
- "dependencies": {
69
- "@babel/runtime": "^7.11.2"
70
- }
38
+ "gitHead": "546607b8de61b57f332562bfd8418cd5fac63a6a"
71
39
  }
package/main/index.js DELETED
@@ -1,89 +0,0 @@
1
- "use strict";
2
-
3
- var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
-
5
- var _construct2 = _interopRequireDefault(require("@babel/runtime/helpers/construct"));
6
-
7
- var _classCallCheck2 = _interopRequireDefault(require("@babel/runtime/helpers/classCallCheck"));
8
-
9
- var _createClass2 = _interopRequireDefault(require("@babel/runtime/helpers/createClass"));
10
-
11
- var createHash = require('crypto').createHash;
12
-
13
- var DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
14
- var URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
15
- module.exports.DNS = DNS;
16
- module.exports.URL = URL;
17
-
18
- var convertToBuffer = function convertToBuffer(bytes) {
19
- if (Array.isArray(bytes)) {
20
- bytes = Buffer.from(bytes);
21
- } else if (typeof bytes === 'string') {
22
- bytes = Buffer.from(bytes, 'utf8');
23
- }
24
-
25
- return bytes;
26
- };
27
-
28
- function uuidToBytes(uuid) {
29
- var bytes = [];
30
- uuid.replace(/[a-fA-F0-9]{2}/g, function (hex) {
31
- bytes.push(parseInt(hex, 16));
32
- });
33
- return bytes;
34
- }
35
-
36
- var hex = [];
37
-
38
- for (var i = 0; i < 256; i++) {
39
- hex[i] = (i < 16 ? '0' : '') + i.toString(16);
40
- }
41
-
42
- function hexToBytes(hex) {
43
- for (var bytes = [], c = 0; c < hex.length; c += 2) {
44
- bytes.push(parseInt(hex.substr(c, 2), 16));
45
- }
46
-
47
- return bytes;
48
- }
49
-
50
- var UuidHash = /*#__PURE__*/function () {
51
- function UuidHash() {
52
- var namespace = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : URL;
53
- var version = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 0x50;
54
- (0, _classCallCheck2["default"])(this, UuidHash);
55
- this.version = version;
56
- this.namespace = namespace;
57
- this.shasum = createHash('sha1');
58
- this.shasum.update(convertToBuffer(this.namespace));
59
- if (typeof this.namespace == 'string') this.namespace = uuidToBytes(this.namespace);
60
- if (!Array.isArray(this.namespace) || this.namespace.length !== 16) throw new Error('namespace must be uuid string or an Array of 16 byte values');
61
- }
62
-
63
- (0, _createClass2["default"])(UuidHash, [{
64
- key: "update",
65
- value: function update(chunk) {
66
- this.shasum.update(convertToBuffer(chunk));
67
- return this;
68
- }
69
- }, {
70
- key: "digest",
71
- value: function digest() {
72
- var r = hexToBytes(this.shasum.digest('hex'));
73
- r[6] = r[6] & 0x0f | this.version;
74
- r[8] = r[8] & 0x3f | 0x80;
75
- return hex[r[0]] + hex[r[1]] + hex[r[2]] + hex[r[3]] + '-' + hex[r[4]] + hex[r[5]] + '-' + hex[r[6]] + hex[r[7]] + '-' + hex[r[8]] + hex[r[9]] + '-' + hex[r[10]] + hex[r[11]] + hex[r[12]] + hex[r[13]] + hex[r[14]] + hex[r[15]];
76
- }
77
- }]);
78
- return UuidHash;
79
- }();
80
-
81
- module.exports = UuidHash;
82
-
83
- module.exports.createHash = function () {
84
- for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
85
- args[_key] = arguments[_key];
86
- }
87
-
88
- return (0, _construct2["default"])(UuidHash, args);
89
- };
package/module/index.js DELETED
@@ -1,66 +0,0 @@
1
- const createHash = require('crypto').createHash;
2
-
3
- const DNS = '6ba7b810-9dad-11d1-80b4-00c04fd430c8';
4
- const URL = '6ba7b811-9dad-11d1-80b4-00c04fd430c8';
5
- module.exports.DNS = DNS;
6
- module.exports.URL = URL;
7
-
8
- const convertToBuffer = bytes => {
9
- if (Array.isArray(bytes)) {
10
- bytes = Buffer.from(bytes);
11
- } else if (typeof bytes === 'string') {
12
- bytes = Buffer.from(bytes, 'utf8');
13
- }
14
-
15
- return bytes;
16
- };
17
-
18
- function uuidToBytes(uuid) {
19
- var bytes = [];
20
- uuid.replace(/[a-fA-F0-9]{2}/g, function (hex) {
21
- bytes.push(parseInt(hex, 16));
22
- });
23
- return bytes;
24
- }
25
-
26
- var hex = [];
27
-
28
- for (var i = 0; i < 256; i++) {
29
- hex[i] = (i < 16 ? '0' : '') + i.toString(16);
30
- }
31
-
32
- function hexToBytes(hex) {
33
- for (var bytes = [], c = 0; c < hex.length; c += 2) bytes.push(parseInt(hex.substr(c, 2), 16));
34
-
35
- return bytes;
36
- }
37
-
38
- class UuidHash {
39
- constructor(namespace = URL, version = 0x50) {
40
- this.version = version;
41
- this.namespace = namespace;
42
- this.shasum = createHash('sha1');
43
- this.shasum.update(convertToBuffer(this.namespace));
44
- if (typeof this.namespace == 'string') this.namespace = uuidToBytes(this.namespace);
45
- if (!Array.isArray(this.namespace) || this.namespace.length !== 16) throw new Error('namespace must be uuid string or an Array of 16 byte values');
46
- }
47
-
48
- update(chunk) {
49
- this.shasum.update(convertToBuffer(chunk));
50
- return this;
51
- }
52
-
53
- digest() {
54
- var r = hexToBytes(this.shasum.digest('hex'));
55
- r[6] = r[6] & 0x0f | this.version;
56
- r[8] = r[8] & 0x3f | 0x80;
57
- return hex[r[0]] + hex[r[1]] + hex[r[2]] + hex[r[3]] + '-' + hex[r[4]] + hex[r[5]] + '-' + hex[r[6]] + hex[r[7]] + '-' + hex[r[8]] + hex[r[9]] + '-' + hex[r[10]] + hex[r[11]] + hex[r[12]] + hex[r[13]] + hex[r[14]] + hex[r[15]];
58
- }
59
-
60
- }
61
-
62
- module.exports = UuidHash;
63
-
64
- module.exports.createHash = (...args) => {
65
- return new UuidHash(...args);
66
- };