Registry / security / rfc2253

rfc2253

JSON →
library0.2.0jsnpmunverified

An RFC 2253 parser and formatter for X.500/X.501 distinguished names, used in LDAPv3 and SSL certificates. Version 0.2.0 is the latest stable release; the package has infrequent updates. It provides parse, format, and escape functions, plus DistinguishedName and RelativeDistinguishedName classes with methods like match, get, getAll, and has. Unlike alternatives (e.g., ldapjs DN), rfc2253 focuses strictly on parsing and formatting according to RFC 2253 without extra LDAP client features. Requires an ES2015-compatible Map global; for older Node.js versions, a polyfill like core-js may be needed.

npm install rfc2253
INSTALL
IMPORT
SIG · RFC2253
R
rfc2253
securityjavascriptv0.2.0
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

parse
import { parse } from 'rfc2253';
const parse = require('rfc2253').parse;
The package ships CommonJS by default; ESM import works with bundlers or Node.js >=12 with --experimental-modules. The default export is the module object, not a function.
format
import { format } from 'rfc2253';
const rfc2253 = require('rfc2253'); rfc2253.format(dn);
Named import is idiomatic; calling the default export as a function will fail.
DistinguishedName
import { DistinguishedName } from 'rfc2253';
const DistinguishedName = require('rfc2253').DistinguishedName;
This is a class, so use 'new' when constructing. It is rarely instantiated directly; parse() returns an instance.
escape
import { escape } from 'rfc2253';
Also available as a function: rfc2253.escape.

Demonstrates parsing, formatting, escaping, matching, and getAll with a DN string.

import { parse, format, escape } from 'rfc2253'; // Parse a DN string const dn = parse('CN=Wayne\\, Bruce,DC=Wayne Enterprises'); console.log(dn.get('DC')); // 'Wayne Enterprises' console.log(dn.get(0).get('CN')); // 'Wayne, Bruce' // Format back to string const formatted = format(dn); console.log(formatted); // 'CN=Wayne\\, Bruce,DC=Wayne Enterprises' // Escape a value const escaped = escape(' "hello", <world> '); console.log(escaped); // '\\ \\"hello\\"\\, \\<world\\>\\ ' // Match DNs const dn2 = parse('cn=Wayne\\, Bruce,dc=Wayne Enterprises'); console.log(dn.match(dn2)); // false (case-sensitive) // Use getAll const dn3 = parse('CN=Alice,CN=Bob,DC=example'); console.log(dn3.getAll('CN')); // ['Alice', 'Bob']
Debug
Known issues
deprecatedThe `toString` method reverses RDN order, which may be surprising.
fix
Use `format()` for standard RFC 2253 output.
affects: >=0.0.0
gotchaParsing is case-sensitive; 'CN' and 'cn' are treated as different keys.
fix
Normalize keys to uppercase/lowercase before calling get or match.
affects: >=0.0.0
gotchaRequires global Map; older Node.js may fail without polyfill.
fix
Install core-js: require('core-js/modules/es6.map'); or use Node.js >=4.
affects: >=0.0.0
breakingNone reported; package is stable with no major version changes.
affects: 0.2.0
Errors
Common errors & fixes
ReferenceError: Map is not defined
Node.js version <4 does not have global Map.
fix
Install core-js: npm install core-js and add require('core-js/modules/es6.map') at entry point.
TypeError: rfc2253 is not a function
Using default import as a function; default export is the module object.
fix
Use named imports: import { parse } from 'rfc2253';
TypeError: dn.get is not a function
Calling get on a string instead of a DistinguishedName object.
fix
Ensure the variable is a result of parse(): const dn = parse(str);
Upgrade
Version history
0.2.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
16
OpenAI (training)
1
Resources
rfc2253 — npm install rfc2253 · libregistry