This package offers low-level utilities for deterministically encoding and decoding JavaScript records into binary formats suitable for database storage, particularly within contexts like B-trees or LevelDB-style key-value stores. It provides an `Encoder` class that accepts a schema-like definition of fields, allowing developers to precisely control the binary representation of structured data. This deterministic encoding is crucial for correct sorting and indexing in ordered data structures. The library is currently at version 1.0.1 and has not received updates in approximately ten years, indicating it is no longer actively maintained. Its core functionality revolves around efficient, type-aware binary serialization and deserialization of objects to and from Node.js `Buffer` instances, a key differentiator for performance-critical database operations over more generic serialization methods like JSON. The `Encoder` also exposes a `compare` method for comparing encoded binary records directly.
npm install encodeVerified import paths — ran on the pinned version, not inferred.
Demonstrates defining an `Encoder` schema, encoding a JavaScript object into a binary `Buffer`, decoding it back, and using the built-in comparator.
Use `const Encoder = require('encode');` in CommonJS modules. For ESM projects, consider dynamic import (`import('encode').then(mod => const Encoder = mod)`) or transpilation if full ESM integration is required.Evaluate carefully before adopting for new projects. For existing projects, consider migrating to actively maintained alternatives if long-term support or modern features are critical.
Create a `declare module 'encode';` file (e.g., `types/encode.d.ts`) or provide more specific typings for the `Encoder` class and its methods manually if type safety is required.
Ensure that the input data strictly conforms to the `Encoder`'s schema during encoding, and that the same schema (or a compatible one) is used for decoding. Validate input data before encoding.
Change the module to CommonJS (`.js` without `type: "module"`) or use a dynamic `import('encode')` call within an async function in your ESM code. Example: `const { Encoder } = await import('encode');`The package exports the `Encoder` class as the module's default export. Use `const Encoder = require('encode');` for CommonJS environments.No dependency data recorded yet.