UUID String to Buffer Parser
uuid-parse is a JavaScript utility for converting RFC4122 UUID strings to Node.js Buffer objects (or Array/Buffer targets) and vice-versa. It provides `parse` and `unparse` functions for this specific transformation. The current stable version is 1.1.0, and the package is explicitly marked as no longer maintained. Its primary differentiator was providing parsing/unparsing functionality that was removed from a prior version of the `node-uuid` library, which is now maintained as `uuid`. Developers should be aware that this module will not receive updates for bugs, security vulnerabilities, or new features, and alternatives like the `uuid` package's `parse` and `stringify` functions are generally recommended for active projects. It does not have a release cadence due to its abandoned status.
Common errors
-
TypeError: uuidParse is not a function
cause Attempting to call `uuidParse()` directly after `require('uuid-parse')` when it's an object with `parse` and `unparse` methods.fixAccess the methods as `uuidParse.parse(...)` or `uuidParse.unparse(...)`. -
uuidParse.parse is not a function (in an ES Module context)
cause Trying to use CommonJS `require`'d module in an ES Module environment without proper interop, or attempting `import uuidParse from 'uuid-parse'` which yields an empty object or `undefined`.fixSwitch to `require` syntax or, preferably, migrate to a modern, actively maintained UUID library that supports ES Modules, such as `uuid`. -
ReferenceError: Buffer is not defined (in a browser environment)
cause This package relies on Node.js's global `Buffer` object, which is not available in standard browser environments.fixUse a bundler (like Webpack or Rollup) that automatically provides a Buffer polyfill for browser compatibility, or manually include a Buffer polyfill. Alternatively, switch to a UUID library designed for universal (Node.js and browser) usage.
Warnings
- breaking This module is no longer maintained. It will not receive updates for security vulnerabilities, bug fixes, or new features. Projects should migrate to actively maintained alternatives like the `uuid` package for robustness and security.
- gotcha The package is CommonJS-only (`require`). It does not natively support ES Modules (`import`). Attempting to use `import` syntax will result in errors in pure ESM environments.
- gotcha Due to its age and abandonment, `uuid-parse` might exhibit unexpected behavior or compatibility issues with newer Node.js Buffer APIs or browser environments if not properly polyfilled or bundled. The `Buffer` object is a Node.js primitive.
Install
-
npm install uuid-parse -
yarn add uuid-parse -
pnpm add uuid-parse
Imports
- uuidParse
import uuidParse from 'uuid-parse';
const uuidParse = require('uuid-parse'); - parse
import { parse } from 'uuid-parse';const { parse } = require('uuid-parse'); - unparse
import { unparse } from 'uuid-parse';const { unparse } = require('uuid-parse');
Quickstart
const uuidParse = require('uuid-parse');
const uuidString = '797ff043-11eb-11e1-80d6-510998755d10';
// Parse a UUID string into a Buffer
const bytes = uuidParse.parse(uuidString);
console.log('Parsed bytes:', bytes.toString('hex'));
// Example with a target buffer and offset
const targetBuffer = Buffer.alloc(32);
const offset = 8;
uuidParse.parse(uuidString, targetBuffer, offset);
console.log('Parsed into target buffer:', targetBuffer.toString('hex'));
// Unparse a Buffer into a UUID string
const string = uuidParse.unparse(bytes);
console.log('Unparsed string:', string);
// Unparsing from a specific offset in a buffer
const unparsedFromOffset = uuidParse.unparse(targetBuffer, offset);
console.log('Unparsed from offset:', unparsedFromOffset);