@atlantjs.dev/uuid
TypeScript icon, indicating that this package has built-in type declarations

1.0.6 • Public • Published

Uuid

The main difference between this and this package on npm is that it defines a Uuid class and can be used to enforce typing.

Install

npm install @atlantjs.dev/uuid
yarn add @atlantjs.dev/uuid

Using

Usage example:

import { Uuid } from "@atlantjs.dev/uuid";

class User {
  constructor(public readonly id: Uuid) {}

  public isSame(anotherUser: User): boolean {
    return this.id.equals(anotherUser.id);
  }
}

const foo = new User(Uuid.new());
const bar = new User(Uuid.new());

console.log(foo.id.toString()); // 388b932f-0800-412c-a70d-68af2f8e54c8

foo.isSame(bar); // false

new User(Uuid.new()); // This is OK
new User(new Uuid("388b932f-0800-412c-a70d-68af2f8e54c8")); // This is OK
new User(new Uuid("foobar")); // Will throw a TypeError

new User(1); // Can't compile
new User("foobar"); // Can't compile
new User("388b932f-0800-412c-a70d-68af2f8e54c8"); // Can't compile

Readme

Keywords

none

Package Sidebar

Install

npm i @atlantjs.dev/uuid

Weekly Downloads

1

Version

1.0.6

License

MIT

Unpacked Size

3.1 kB

Total Files

5

Last publish

Collaborators

  • matheusantoni0