1.1.0 • Published 8 months ago

@agoralabs-sh/uuid v1.1.0

Weekly downloads
-
License
CC0-1.0
Repository
github
Last release
8 months ago

License: CC0-1.0 NPM Version

GitHub Release GitHub Release


Table of Contents

🪄 1. Getting Started

1.1. Installation

You can install the types using:

npm add @agoralabs-sh/uuid

Back to top ^

1.2. API Reference

1.2.1. generate([options])

Generates a random UUID v4 string.

Parameters
NameTypeRequiredDefaultDescription
optionsIExtraOptionsno-Options that allows the UUID to to be returned to uppercase.
Returns
TypeDescription
stringA random UUID v4 string.
Example
import { generate } from '@agoralabs-sh/uuid';

const uuid = generate();

console.log(uuid);
// 18b0e62a-21c6-4e27-a813-825716f0fedb

Back to top ^

1.2.2. decode(value)

Decodes the UUID into a byte array. This removes any hyphens and case is preserved.

Parameters
NameTypeRequiredDefaultDescription
valuestringyes-The UUID to decode
Returns
TypeDescription
Uint8ArrayThe UUID as bytes.
Example
import { decode } from '@agoralabs-sh/uuid';

const decoded = decode('18b0e62a-21c6-4e27-a813-825716f0fedb');

console.log(decoded);
// [24, 176, 230, 42, 33, 198, 78, 39, 168, 19, 130, 87, 22, 240, 254, 219]

Back to top ^

1.2.3. encode(value, [options])

Encodes the UUID into the human-readable format with hyphens added.

Parameters
NameTypeRequiredDefaultDescription
valueUint8Arrayyes-A UUID byte array.
optionsIExtraOptionsno-Options that allows the UUID to to be returned to uppercase.
Returns
TypeDescription
stringThe encoded UUID string as a human-readable string.
Example
import { encode } from '@agoralabs-sh/uuid';

const uuid = encode(new Uint8Array([24, 176, 230, 42, 33, 198, 78, 39, 168, 19, 130, 87, 22, 240, 254, 219]));

console.log(uuid);
// 18b0e62a-21c6-4e27-a813-825716f0fedb

Back to top ^

1.2.4. IExtraOptions

NameTypeRequiredDefaultDescription
uppercasebooleannofalseWhether the UUID is transformed to uppercase.

Back to top ^

📑 2. Appendix

2.1. Useful Commands

CommandDescription
pnpm run buildGenerates build and TypeScript declaration files to the dist/ directory.
pnpm run cleanDeletes the dist/ directory and the tsconfig.*.tsbuildinfo files.
pnpm run generate:indexGenerates/overwrites the main index.ts file used for exporting all files.
pnpm run lintRuns the linter based on the rules in eslint.config.mjs.
pnpm run prettierRuns the prettier based on the rules in prettier.config.mjs.

Back to top ^

👏 3. How To Contribute

Please read the Contributing Guide to learn about the development process.

Back to top ^

📄 4. License

Please refer to the LICENSE file.

Back to top ^

🫶 5. Credits

  • The generation of the UUID is thanks to the amazing @dhest and their amazing @stablelib library.

Back to top ^