npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

tlv-to-json

v1.0.9

Published

A TLV string converter to JSON object

Downloads

25

Readme

TLV string to JSON object

This library provides a simple way to convert TLV string to a JSON object.

The type and length are fixed in size, and the value field is of variable size.

More information here: https://en.wikipedia.org/wiki/Type–length–value

Examples

Simple example

Input string:

0105HELLO0205WORLD0304A943

Implementation:

import { TLV } from 'tlv-to-json';

const output = TLV.toJSON('/* PUT HERE THE INPUT STRING */');

console.log(JSON.stringify(output, null, 2));

Output JSON:

{
  "T01": "HELLO",
  "T02": "WORLD",
  "T03": "A943"
}

Please note types are prefixed with the letter T.

Advanced example

Input string:

00020101021226430012com.facebook011259703395303802079990997520400005303152540410.05802US5907SHOPIFY6008Beaumont80540024com.facebook.pay.options0108B08262600203002030300281730029com.facebook.pay.options.uuid013628c729bb-0b23-4014-9974-da73573cbc8463040989

Implementation:

import { TLV } from 'tlv-to-json';

const output = TLV.toJSON('/* PUT HERE THE INPUT STRING */');

console.log(JSON.stringify(output, null, 2));

Output JSON:

{
  "T00": "01",
  "T01": "12",
  "T26": {
    "T00": "com.facebook",
    "T01": "597033953038",
    "T02": "9990997"
  },
  "T52": "0000",
  "T53": "152",
  "T54": "10.0",
  "T58": "US",
  "T59": "SHOPIFY",
  "T60": "Beaumont",
  "T80": {
    "T00": "com.facebook.pay.options",
    "T01": "B0826260",
    "T02": "002",
    "T03": "002"
  },
  "T81": {
    "T00": "com.facebook.pay.options.uuid",
    "T01": "28c729bb-0b23-4014-9974-da73573cbc84"
  },
  "T63": "0989"
}

Please note types are prefixed with the letter T.

Recursive example

Input string:

0105HELLO0229012501210117011301090105WORLD03044369

Implementation:

import { TLV } from 'tlv-to-json';

const output = TLV.toJSON('/* PUT HERE THE INPUT STRING */');

console.log(JSON.stringify(output, null, 2));

Output JSON:

{
  "T01": "HELLO",
  "T02": {
    "T01": {
      "T01": {
        "T01": {
          "T01": {
            "T01": {
              "T01": "WORLD"
            }
          }
        }
      }
    }
  },
  "T03": "4369"
}

Please note types are prefixed with the letter T.

CRC Check

By default, the toJSON function assume the input string's last 4 digits are a CRC16 Checksum Hexadecimal.

To disable the checksum verificación you can pass false to the second parameter:

const json = TLV.toJSON('/* THE INPUT STRING */', false);

In case of checksum error, this message will be displayed:

Checksum failed (Calculated: AAE6, Expected: 0989)