Security News
Bun 1.2 Released with 90% Node.js Compatibility and Built-in S3 Object Support
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
ramsey-uuid
Advanced tools
A JavaScript library that provides a 'ramsey/uuid'-like interface for the uuid package
A TypeScript library that provides a 'ramsey/uuid'-like interface for the uuid package.
ramsey-uuid is a TypeScript library for generating and working with universally unique identifiers (UUIDs). It provides a ramsey/uuid-like interface to the uuid package that
This project adheres to a code of conduct. By participating in this project and its community, you are expected to uphold this code.
npm i --save ramsey-uuid
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.uuid4();
... or using CommonJS syntax:
const { Uuid } = require('ramsey-uuid');
const uuid = Uuid.uuid4();
Returns the array of bytes of the UUID
returns | Uint8Array[16] |
throws | TypeError if str is not a valid UUID |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.uuid4();
const byteArray = uuid.getUuid();
Convert a UUID string to array of bytes
str | A valid UUID String |
returns | Uint8Array[16] |
throws | TypeError if str is not a valid UUID |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.fromString('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');
Convert array of bytes to UUID string
returns | String |
throws | TypeError if a valid UUID string cannot be generated |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.uuid4();
uuid.toString(); // ⇨ '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'
Convert array of bytes to UUID hexadecimal string
returns | String |
throws | TypeError if a valid UUID string cannot be generated |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.uuid4();
uuid.toHex(); // ⇨ '6EC0BD7F11C043DA975E2A8AD9EBAE0B'
Convert a UUID byte string to array of bytes
str | A valid UUID byte string String |
returns | Uint8Array[16] |
throws | TypeError if str is not a valid UUID |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.fromString('acCäügF¥ÜsÃ?4');
Convert an array of bytes to a binary string representation of the UUID
returns | String |
throws | TypeError if a valid UUID string cannot be generated |
Example:
import { Uuid } from 'ramsey-uuid';
const uuid = Uuid.uuid4();
uuid.getBytes(); // ⇨ 'acCäügF¥ÜsÃ?4'
The recommended use for saving UUID values in the database would be to create a BINARY(16)
column in the database.
When persisting the UUIDs you can UNHEX
the hexadecimal representation of the UUID.
await this.model
.createQueryBuilder()
.insert()
.into(Table)
.values({
uuid: () => `UNHEX('${Uuid.uuid4().toHex()}')`,
})
.execute();
INSERT INTO `ActivityDefinition` (`uuid`)
VALUES('UNHEX("616343E4FC6746A598DC73C39C873F34")');
Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.
The ramsey-uuid library is copyright © Connor Smyth and licensed for use under the MIT License (MIT). Please see LICENSE for more information.
FAQs
A JavaScript library that provides a 'ramsey/uuid'-like interface for the uuid package
The npm package ramsey-uuid receives a total of 0 weekly downloads. As such, ramsey-uuid popularity was classified as not popular.
We found that ramsey-uuid demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Bun 1.2 enhances its JavaScript runtime with 90% Node.js compatibility, built-in S3 and Postgres support, HTML Imports, and faster, cloud-first performance.
Security News
Biden's executive order pushes for AI-driven cybersecurity, software supply chain transparency, and stronger protections for federal and open source systems.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.