Giter VIP home page Giter VIP logo

Comments (2)

samal-rasmussen avatar samal-rasmussen commented on July 17, 2024 1

01FZD39998855SS2YG4XP4T14P is a valid base32 encoded string and a base32 string should round trip between b32decode and b32encode to the same value. If it doesn't then there's a bug there. It has nothing to do with ulid.

I found a different encoding package crockford-base32 that isn't bugged:

import b32decode from 'base32-decode';
import b32encode from 'base32-encode';
import { CrockfordBase32 } from 'crockford-base32';

const uid = '01FZD39998855SS2YG4XP4T14P';

const buffer = CrockfordBase32.decode(uid);
console.log('decoded', new Uint8Array(buffer).toString());
const res = CrockfordBase32.encode(buffer);
console.log('encoded', res);

const decoded = b32decode(uid, 'Crockford');
console.log('DECODED', new Uint8Array(decoded).toString());
const encoded = b32encode(decoded, 'Crockford');
console.log('ENCODED', encoded);

Result:

decoded 1,127,218,52,165,40,65,75,156,139,208,39,108,77,4,150
encoded 01FZD39998855SS2YG4XP4T14P
DECODED 0,95,246,141,41,74,16,82,231,34,244,9,219,19,65,37
ENCODED 01FZD39998855SS2YG4XP4T14M

Run it on stackblitz:
https://stackblitz.com/edit/js-esmrfr

from javascript.

ErkoKnoll avatar ErkoKnoll commented on July 17, 2024

Thanks @samal-rasmussen!

from javascript.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.