Skip to content

Commit

Permalink
v5.0.0 Released
Browse files Browse the repository at this point in the history
Breaking changes:

- Migrated to native ES Modules from global variable and CommonJS export
  - Added named `UUID` export and removed default export
  - Removed `UUID.overwrittenUUID` property (a.k.a. no conflict mode)
- Removed `node:crypto` module-based CSPRNG implementation
  - Now requires Web Crypto API to utilize cryptographically secure pseudorandom
    number generators
- Changed target ECMAScript version from ES3 to ES2016
- Removed uuid.core.js and bower.json from repository
- Fixed wrong return type declaration of `UUID.parse()`: `UUID` -> `UUID | null`
- Placed tighter type constraints on `UUID` class members
  - Marked constructor() as private
  - Marked `UUID.FIELD_NAMES`, `UUID.FIELD_SIZES`, `UUID#intFields`,
    `UUID#bitFields`, and `UUID#hexFields` as read-only arrays/objects

Dev environment changes:

- Migrated to TypeScript and transpilation from pure JavaScript
  - Replaced manually written type declaration with auto-generated .d.ts
- Adopted class declaration syntax
- Applied Prettier style to source code
- Migrated to TypeDoc from JSDoc for API document generation
- Updated dev dependencies
  • Loading branch information
LiosK committed Jan 28, 2023
2 parents 79a460c + e527a08 commit 22ba6e3
Show file tree
Hide file tree
Showing 69 changed files with 3,349 additions and 15,785 deletions.
2 changes: 0 additions & 2 deletions .npmignore

This file was deleted.

84 changes: 84 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
# Changelog

## v5.0.0 - 2023-01-28

### Breaking changes

- Migrated to native ES Modules from global variable and CommonJS export
- Added named `UUID` export and removed default export
- Removed `UUID.overwrittenUUID` property (a.k.a. no conflict mode)
- Removed `node:crypto` module-based CSPRNG implementation
- Now requires Web Crypto API to utilize cryptographically secure pseudorandom
number generators
- Changed target ECMAScript version from ES3 to ES2016
- Removed uuid.core.js and bower.json from repository
- Fixed wrong return type declaration of `UUID.parse()`: `UUID` -> `UUID | null`
- Placed tighter type constraints on `UUID` class members
- Marked constructor() as private
- Marked `UUID.FIELD_NAMES`, `UUID.FIELD_SIZES`, `UUID#intFields`,
`UUID#bitFields`, and `UUID#hexFields` as read-only arrays/objects

### Dev environment changes

- Migrated to TypeScript and transpilation from pure JavaScript
- Replaced manually written type declaration with auto-generated .d.ts
- Adopted class declaration syntax
- Applied Prettier style to source code
- Migrated to TypeDoc from JSDoc for API document generation
- Updated dev dependencies

### Migration notes

Import the `UUID` class using the ESM syntax:

```diff
<!-- HTML5 -->
-<script src="https://unpkg.com/uuidjs@^4"></script>
-<script>
+<script type="module">
+ import { UUID } from "https://unpkg.com/uuidjs@^5";
const uuid = UUID.generate();
</script>
```

```diff
// Node.js
-const UUID = require("uuidjs");
+import { UUID } from "uuidjs";
const uuid = UUID.generate();
```

Call static methods through the `UUID` class, rather than importing them
directly:

```diff
// Node.js
-const { generate } = require("uuidjs");
-const uuid = generate();
+import { UUID } from "uuidjs";
+const uuid = UUID.generate();
```

Run type checking relating to the following items, as these items have different
type declarations than those in v4:

- `UUID.parse()`
- `UUID.FIELD_NAMES`
- `UUID.FIELD_SIZES`
- `new UUID()`
- `UUID#intFields`
- `UUID#bitFields`
- `UUID#hexFields`

## v4.2.13 - 2023-01-09

Last version that:

- Retains ECMAScript 3 compatibility
- Supports Internet Explorer 6
- Registers `UUID` in global scope
- Exports CommonJS entry point
- Accompanies uuid.core.js variant
- Ships with bower.json
- Uses `node:crypto`-based cryptographically secure pseudorandom number
generator on Node.js
54 changes: 18 additions & 36 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@

```html
<!-- HTML5 -->
<script src="src/uuid.js"></script>
<script> var uuid = UUID.generate(); </script>
<script type="module">
import { UUID } from "https://unpkg.com/uuidjs@^5";
const uuid = UUID.generate();
</script>
```

```javascript
// Node.js
let UUID = require("uuidjs");
let uuid = UUID.generate();
import { UUID } from "uuidjs";
const uuid = UUID.generate();
```

```typescript
// TypeScript
import UUID from "uuidjs";
let str: string = UUID.generate();
let obj: UUID = UUID.genV4();
import { UUID } from "uuidjs";
const str: string = UUID.generate();
const obj: UUID = UUID.genV4();
```

```bash
Expand Down Expand Up @@ -49,27 +51,17 @@ variety of forms.
JavaScript than that required for version 1 UUIDs
- Comes with a lot of test cases including format checks and statistical tests
to maintain a high-quality code base
- Supports old browsers as well as modern browser and server environments, as
kept compatible with ECMAScript 3rd edition

## Install

Download `src/uuid.js` or call `npm install uuidjs`.

Then, load `src/uuid.js`.

```html
<script src="src/uuid.js"></script>
```
## Usage Examples

Or, import `uuidjs`.
Import `UUID` class:

```javascript
const UUID = require("uuidjs");
import { UUID } from "uuidjs";
// or on browsers:
// import { UUID } from "https://unpkg.com/uuidjs@^5";
```

## Usage Examples

`UUID.generate()` returns a version 4 UUID as a hexadecimal string.

```javascript
Expand All @@ -82,13 +74,13 @@ various fields and methods.

```javascript
// Create a version 4 (random number-based) UUID object
var objV4 = UUID.genV4();
const objV4 = UUID.genV4();

// Create a version 1 (time-based) UUID object
var objV1 = UUID.genV1();
const objV1 = UUID.genV1();

// Create a UUID object from a hexadecimal string
var uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");
const uuid = UUID.parse("a0e0f130-8c21-11df-92d9-95795a3bcd40");

// Get string representations of a UUID object
console.log(uuid.toString()); // "a0e0f130-8c21-11df-92d9-95795a3bcd40"
Expand Down Expand Up @@ -120,16 +112,6 @@ console.log(uuid.bitFields[4]); // "11011001"
console.log(uuid.hexFields[5]); // "95795a3bcd40"
```

UUID.js supports the so-called noConflict mode to work around namespace
conflicts.

```javascript
// Avoid namespace conflicts with other libraries
var arbitraryVarName = UUID;
UUID = UUID.overwrittenUUID; // Restore the original value
console.log(arbitraryVarName.generate()); // "cb9a0283-a44c-4e7a-a5b0-9cd2876e952b"
```

## License

Copyright (c) 2010-2023 LiosK
Expand All @@ -155,4 +137,4 @@ LiosK <contact@mail.liosk.net>
- [GitHub Repository](https://github.com/LiosK/UUID.js)
- [npm Package](https://www.npmjs.com/package/uuidjs)
- [API Documentation](https://liosk.github.io/UUID.js/docs/)
- [Run test cases on your browser](https://liosk.github.io/UUID.js/test/browser.html)
- [Run test cases on your browser](https://liosk.github.io/UUID.js/test/)
3 changes: 0 additions & 3 deletions bin/cli.js

This file was deleted.

29 changes: 0 additions & 29 deletions bower.json

This file was deleted.

2 changes: 2 additions & 0 deletions dist/cli.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#!/usr/bin/env node
export {};
3 changes: 3 additions & 0 deletions dist/cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env node
import { UUID } from "./uuid.js";
console.log(UUID.generate());
8 changes: 0 additions & 8 deletions dist/uuid.core.js

This file was deleted.

Loading

0 comments on commit 22ba6e3

Please sign in to comment.