synchsafe

A simple module to decode and encode synchsafe integers.

Usage no npm install needed!

<script type="module">
  import synchsafe from 'https://cdn.skypack.dev/synchsafe';
</script>

README

synchsafe

A simple module to decode and encode synchsafe integers.

dependencies version

This module provides two functions to decode and encode synchsafe integers as it is for example required by the ID3 standard. It is basically a fork of this Gist by raym.

Usage

The synchsafe module is available on npm and can be installed as usual.

npm install synchsafe

You can then import its public functions decode() and encode() like this:

import { decode, encode } from 'synchsafe';

As you might guess, the encode() function turns a regular integer into a synchsafed integer and the decode() function does the opposite. Therefore the following line would evaluate to true.

decode(encode(30201)) === 30201;