The `node-tlv` library provides a robust parser and builder for Tag-Length-Value (TLV) encoded data, commonly found in smart card protocols like EMV and ISO7816. It supports parsing both simple TLV and BER-TLV structures, allowing developers to extract and manipulate data elements such as DGI, EMV, ISO7816, and DOL tags. Currently at stable version 1.5.14, the package does not explicitly state a release cadence, but its versioning and continuous updates suggest ongoing maintenance. Its key differentiator lies in its focused support for financial and smart card industry standards, offering both parsing of raw hexadecimal strings into structured TLV objects and the ability to programmatically construct complex TLV hierarchies, useful for building responses like PPSE FCI or PSE records. It is designed for Node.js environments, providing a programmatic interface to navigate and construct TLV data structures.
npm install node-tlvVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse a raw hexadecimal string containing TLV data into a structured object, navigate its child elements, and find specific tags by their hexadecimal value or string representation, crucial for EMV transaction processing.
For ESM projects, consider using a dynamic import (`await import('node-tlv')`) or configure your bundler/Node.js environment to handle CommonJS modules. The recommended approach is to use `const TLV = require('node-tlv');`.Ensure all input strings passed to TLV methods are clean, even-length hexadecimal strings. Implement rigorous input validation and error handling before parsing, especially if data sources are untrusted or external.
Provide only the hexadecimal value data for the `value` argument. For example, for a tag `82` with value `5800`, you would use `new TLV('82', '5800')`, not `new TLV('82', '82025800')`.Change `import TLV from 'node-tlv';` to `const TLV = require('node-tlv');`. If your `package.json` contains `"type": "module"`, consider removing it or explicitly configuring your file to be CommonJS (e.g., using a `.cjs` extension).Verify your import statement. For CommonJS, it should typically be `const TLV = require('node-tlv');`. Ensure you are not trying to destructure `TLV` (e.g., `const { parse } = require('node-tlv');`) as `parse` is a static method of the main `TLV` export.Carefully inspect the input string. Ensure it's a valid, clean hexadecimal representation of TLV data, where length fields correctly correspond to the subsequent value data length. Use a hex editor or online TLV decoder to validate the input structure.
No dependency data recorded yet.