Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@actually_connor/uuid

Package Overview
Dependencies
Maintainers
1
Versions
15
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@actually_connor/uuid

A JavaScript library that provides a 'ramsey/uuid'-like interface for the uuid package

  • 0.3.2
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
16
increased by300%
Maintainers
1
Weekly downloads
 
Created
Source

@actually_connor/uuid

A JavaScript library that provides a 'ramsey/uuid'-like interface for the uuid package.

@actually_connor/uuid is a JavaScript 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.

Quickstart

  1. Install
npm i --save @actually_connor/uuid
  1. Generate a UUID (ES6 module syntax)
import { Uuid } from '@actually_connor/uuid';
const uuid = Uuid.uuid4();

... or using CommonJS syntax:

const { Uuid } = require('@actually_connor/uuid');
const uuid = Uuid.uuid4();

API Summary

getUuid()

Returns the array of bytes of the UUID

returnsUint8Array[16]
throwsTypeError if str is not a valid UUID

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.uuid4();
const byteArray = uuid.getUuid();

fromString(str)

Convert a UUID string to array of bytes

strA valid UUID String
returnsUint8Array[16]
throwsTypeError if str is not a valid UUID

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.fromString('6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b');

toString()

Convert array of bytes to UUID string

returnsString
throwsTypeError if a valid UUID string cannot be generated

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.uuid4();
uuid.toString(); // ⇨ '6ec0bd7f-11c0-43da-975e-2a8ad9ebae0b'

getHex

Convert array of bytes to UUID hexadecimal string

returnsString
throwsTypeError if a valid UUID string cannot be generated

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.uuid4();
uuid.getHex(); // ⇨ '6EC0BD7F11C043DA975E2A8AD9EBAE0B'

fromBytes(str)

Convert a UUID byte string to array of bytes

strA valid UUID byte string String
returnsUint8Array[16]
throwsTypeError if str is not a valid UUID

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.fromString('acCäügF¥˜Üs܇?4');

getBytes()

Convert an array of bytes to a binary string representation of the UUID

returnsString
throwsTypeError if a valid UUID string cannot be generated

Example:

import { Uuid } from '@actually_connor/uuid';

const uuid = Uuid.uuid4();
uuid.getBytes(); // ⇨ 'acCäügF¥˜Üs܇?4'

Use in Database - MySQL

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.

TypeORM

await this.model
.createQueryBuilder()
.insert()
.into(Table)
.values({
  uuid: () => `UNHEX('${Uuid.uuid4().toHex()}')`,
})
.execute();

MySQL

INSERT INTO `ActivityDefinition` (`uuid`)
VALUES('UNHEX("616343E4FC6746A598DC73C39C873F34")');

Contributing

Contributions are welcome! To contribute, please familiarize yourself with CONTRIBUTING.md.

The @actually_connor/uuid library is copyright © Connor Smyth and licensed for use under the MIT License (MIT). Please see LICENSE for more information.

Keywords

FAQs

Package last updated on 02 Mar 2022

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc