@nodecfdi/utils-internal-baseconverter

Librería que convierte un numero entre bases arbitrarias

Usage no npm install needed!

<script type="module">
  import nodecfdiUtilsInternalBaseconverter from 'https://cdn.skypack.dev/@nodecfdi/utils-internal-baseconverter';
</script>

README

@nodecfdi/utils-internals-baseconverter

Source Code Software License Latest Version Discord

TS utility for converting an input from any base to another base the min base this library accepts is 2 and max base is 36.

Main features

  • Convert an input from any valid base to another.

Installation

npm i @nodecfdi/utils-internal-baseconverter --save

or

yarn add @nodecfdi/utils-internal-baseconverter

Implementation

The converter expects 3 parameters: converter.convert(input, fromBase, toBase)

import { BaseConverter } from '@nodecfdi/utils-internal-baseconverter';
// this is the main reason to exists of BaseConverter class
// since parseInt and toString cannot handle large inputs
const input = '3330303031303030303030333030303233373038';
const converter = BaseConverter.createBase36();
// result will be: 292233162870206001759766198425879490508935868472
const result = converter.convert(input, 16, 10);

alternatively you can define your own sequence:

import { BaseConverter, BaseConverterSequence } from '@nodecfdi/utils-internal-baseconverter';
const hexSequence = new BaseConverterSequence('0123456789ABCDEF');
const converter = new BaseConverter(hexSequence);
const input = 'FFFF';
// resut will be: 1111111111111111
converter.convert(input, 16, 2);