Socket
Socket
Sign inDemoInstall

uuid-tool

Package Overview
Dependencies
0
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    uuid-tool

Lightweight UUID for JavaScript. Parse and generate UUIDs. Convert between string and byte array.


Version published
Maintainers
1
Install size
12.6 kB
Created

Changelog

Source

1.5.0

  • Updated the project setup and the dev-dependencies.
  • Replaced tslint (deprecated) with eslint (typescript support).
  • Switched from Apache 2 to MIT license.

Readme

Source

UUID Tool

Version MIT License

Lightweight UUID library for JavaScript. No bullshit, simple to use, easy to learn. Well tested and no dependencies.

Parse and generate UUIDs. Convert between UUID string (36 byte) to 16 byte array. Inclusive TypeScript definition file (types).

For NodeJS and Browser.

UUID RFC 4122 Version 4

Install

npm i uuid-tool

NPM Package

Example

let uuid = UUIDTool.newUUID();
let bytes = UUIDTool.toBytes(uuid);
let strAgain = UUIDTool.toString(bytes);
let isValid = UUIDTool.isUUID(strAgain);
let isEqual = UUIDTool.compare(uuid1, uuid2);

You can also use the UUID class.

let uuid = new UUID(byteOrString);
let str = uuid.toString();
let bytes = uuid.toBytes();
// Generate a new UUID
let uuid = new UUID();
// Compare (case insensitive)
let uuid1 = new UUID('3C09B262-49C7-466F-8B4F-626BCA1EC9BC');
let uuid2 = new UUID('3c09b262-49c7-466f-8b4f-626bca1ec9bc');

if (uuid1.equals(uuid2)) {
  console.log('The IDs match.');
} else {
  console.log('The IDs do not match.');
}

// Result: The IDs match.

In NodeJS e.g.

const UUID = require('uuid-tool').UUID;
console.log(new UUID().toString());

API

UUIDTool


toBytes (uuid)

Converts an UUID string to an UUID byte array.

ParamTypeDescription
uuidstringUUID string e.g. '1FBD384C-B2A1-41C6-84AF-43CABDF44124'

Returns number[] UUID byte array (length: 16)


toString (bytes)

Converts an UUID byte array to an UUID string.

ParamTypeDescription
bytesnumber[]UUID Byte array (length 16 bytes of bytes)

Returns string UUID string. (length 36)


newUUID ()

Generates a new (pseudo) UUID RFC 4122 Version 4.

Returns string UUID e.g. '1FBD384C-B2A1-41C6-84AF-43CABDF44124'


isUUID (uuid)

Converts an UUID byte array to an UUID string.

ParamTypeDescription
uuidstringUUID string e.g. '1FBD384C-B2A1-41C6-84AF-43CABDF44124'

Returns boolean True if valid, otherwise false.


compare (uuid1, uuid2)

Compares two UUIDs.

ParamTypeDescription
uuid1stringUUID string
uuid2stringUUID string

Returns boolean True if equal, otherwise false.


UUID

generate ()

Re-generates a new UUID for this instance.

Returns this The same UUID instance.


fromBytes (bytes)

Converts an UUID byte array to an UUID string. (length: 36)

ParamTypeDescription
bytesnumber[]UUID Byte array (length 16 bytes of bytes)

Returns this The same UUID instance.


toBytes ()

Converts this UUID to an UUID byte array. (length: 16)

Returns number[] The UUID as byte array.


fromString (uuid)

Converts an UUID byte array to an UUID string. (length: 36)

ParamTypeDescription
uuidstringstring e.g. '1FBD384C-B2A1-41C6-84AF-43CABDF44124'

Returns this The same UUID instance.


toString ()

To UUID string. HINT Set case mode by UUID.stringExportFormat = 'uppercase' | 'lowercase';

Returns string UUID string e.g. '1FBD384C-B2A1-41C6-84AF-43CABDF44124'


isValid ()

Validate this UUID.

Returns boolean True if valid, otherwise false.


equals (uuid)

Compares this UUID with another UUID.

ParamTypeDescription
uuidUUID | stringAnother UUID instance or uuid-string.

Returns boolean True if equal, otherwise false.


License

MIT © Copyright 2020 Dominik-Andreas Geng (@domske)

Keywords

FAQs

Last updated on 04 Jun 2020

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc