Giter Site home page Giter Site logo

umamiappearance / baseexjs Goto Github PK

View Code? Open in Web Editor NEW
10.0 2.0 2.0 2.33 MB

A collection of classes for data representation from Base16 (hex) to Base2048 written in JavaScript.

License: MIT License

JavaScript 100.00%
hexadecimal hex base16 base32 base64 base85 base91 javascript standalone nodejs browser ecoji golden-ratio phi unary leb128 base2048 binary base58 uuencode

baseexjs's Introduction

BaseEx

License npm

BaseEx is a collection of classes for data representation from Base16 (hex) to Base2048 or even BasePhi. BaseEx is completely standalone and works client and server side. There are other good solutions for e.g. Base32, Base64, Base85, but BaseEx has them all in one place. The Ex in the name stands for Exponent (of n) or - as read out loud - for an X.

Available converters/charsets:

converter
(external links)
charsets
(as required as argument)
standalone builds
>> CDN links
Base1/Unary
  • all
  • sequence
  • default
  • tmark
Base16
  • default
Base32
  • crockford
  • rfc3548
  • rfc4648
  • zbase32
Base58
  • default
  • bitcoin
  • flickr
Base64
  • standard
  • urlsafe
UUencode
  • default
  • original
  • xx
Base85
  • adobe
  • ascii85
  • rfc1924 (charset only)
  • z85
Base91
  • default
LEB128
  • default
  • hex
Ecoji
  • emojis_v1
  • emojis_v2
Base2048
  • default
SimpleBase
(Base2-Base62)
  • default
BasePhi (Golden Ratio Base)
  • default
ByteConverter ---
BaseEx Ready to use instances of the above converters:
  • base1
  • base16
  • base32_crockford
  • base32_rfc3548
  • base32_rfc4648
  • base32_zbase32
  • base58
  • base58_bitcoin
  • base58_flickr
  • base64
  • base64_urlsafe
  • uuencode
  • uuencode_original
  • xxencode
  • base85_adobe
  • base85_ascii
  • base85_z85
  • base91
  • leb128
  • ecoji_v1
  • ecoji_v2
  • base2048
  • byteConverter
  • simpleBase
    • base2
    • base36
    • base62
(complete builds)

Additional charsets can be added. Watch this live example.

Installation

GitHub

git clone https://github.com/UmamiAppearance/BaseExJS.git

npm

nmp install base-ex

Builds

There are multiple builds available which are always grouped as esm and iife, plus a minified version of each. The full build with all converters included can be found at dist, which contains:

  • base-ex.esm.js
  • base-ex.esm.min.js
  • base-ex.iife.js
  • base-ex.iife.min.js

Apart from the full build, every converter can be used standalone. The associated builds can be found at dist/converters. Or at the table above. Ready to use CDN-links are listed here.

Note that standalone converters are exported as default.

Usage

Importing

Browser

<!-- the classic -->
<script src="path/base-ex.iife.min.js"></script>
// ESM6 module

// main class
import { BaseEx } from "./path/BaseEx.esm.min.js"

// explicit converter (e.g. Base32)
import { Base32 } from "./path/BaseEx.esm.min.js"

// explicit converter from a standalone build
import Base32 from "./path/base-32.esm.min.js"

Node

// ESM6 Module

// main class
import { BaseEx } from "base-ex"

// explicit converter (e.g. Base64)
import { Base64 } from "base-ex"

// CommonJS
const BaseEx = require("base-ex");

Command Line Interface

A CLI can be found at: https://github.com/UmamiAppearance/BaseExCLI.

Available imports Browser/Node

The classic import via script tag has them all available without further ado. As it is a iife, everything is available under the scope of BaseEx.

  • BaseEx.Base1
  • BaseEx.Base16
  • BaseEx.Base32
  • ...
  • BaseEx.BaseEx

(Which is not true for standalone builds, which are directly accessible, eg: Base16, Base32, ... See list)

The same goes for the CommonJS import from Node. The only difference is, that the scope is not necessarily named BaseEx, as this is defined by the user (const myName = require("base-ex") --> myName.Base16...).

Full import for ES6 modules:

// browser
import {
    Base1,
    Base16,
    Base32,
    Base58,
    Base64,
    UUencode,
    Base85,
    Base91,
    LEB128,
    Ecoji,
    Base2048,
    SimpleBase,
    BasePhi,
    ByteConverter,
    BaseEx 
} from "./path/BaseEx.esm.min.js"

// node
import { ... } from "base-ex"

Creating an instance

Regardless of the environment, at instance of a converter gets created like so:

const b32 = new Base32();

The constructor takes some arguments/options (which may differ between different encoder types). Those can also can be passed ephemeral to the encoder and/or decoder.

Options

propertyarguments
endiannessbele
paddingnopadpad
signunsignedsigned
caselowerupper
charset<various>
number-modenumber
decimal-modedecimal
IO handler
  • bytesIn   >> accept only bytes as input
  • bytesOut   >> limits output to byte-like values
  • bytesInOut  >> in- and output limited to bytes
output types
  • bigint64
  • bigint_n
  • biguint64
  • buffer
  • bytes
  • float32
  • float64
  • float_n
  • int8
  • int16
  • int32
  • int_n
  • str
  • uint8
  • uint16
  • uint32
  • uint_n
  • view

En- and Decoding

Example:
(Ecoji is simply picked, because of its picturesque appearance, any other converter works the same)

const ecoji = new Ecoji();
ecoji.encode("Hello World!");
// result: 🏯🔩🚗🌷🍉👇🦒🪁👡📢☕

// default output is an ArrayBuffer, pass 'str' to convert to string
ecoji.decode("🏯🔩🚗🌷🍉👇🦒🪁👡📢☕", "str");
// result: "Hello World!"

Demonstration

More explanation is shown at the LiveExamples. Also try out the Online Base Converter for additional code examples.


You can play with the Examples on your local machine by running:

npm start

(devDependencies required, run npm install from the package folder first)

License

MIT

Copyright (c) 2023, UmamiAppearance

  • The basE91 en-/decoder relies on the work of Joachim Henke. The original code is licensed under BSD-3-Clause. His method was transpiled to JavaScript with small adjustments.

  • The test files for the Ecoji decoder (ecoji-orig.test.js) are copied from the Ecoji repository and are created by Keith Turner. These are licensed under Apache-2.0

  • The Base2048 Decoder relies on the work of qntm. The original code is licensed under the MIT-License. The original code is already written in JavaScript and was slightly adjusted.

  • Non Integer Bases can only work with a high decimal precision, this is done with the help of Big.js. The code is reduced to the requirements of the converters (at the moment this is only BasePhi). Big.js, created by Michael Mclaughlin, is licensed under the MIT-License.

baseexjs's People

Contributors

dependabot[bot] avatar umamiappearance avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Forkers

kalepail jeniex

baseexjs's Issues

Slow decoding results for binary files

          Hi,

First of all, thank you! I tested and for all graphics it appears to work
now. However, it is not working in other case of uuencoded binaries. I
double checked everything (including used regexp).

In some cases it is just return 3 bytes and those bytes always representing
this uint8array [ 80, 75, 3 ]. For example the first lines when just
returning those 3 bytes are:
M4$L#!!0 ( ..@.*** +$ 0 9&]C4')O<',O87!P+GAM
M;$V./0L",1!$_\IQO;=!P4)B0-!2L+(/>QLOD&1#LD)^OCG!CVX>;QA&WPIG
MNI#BV&5(C(I(/ !47BK9.7:=N')=HI6-Y #OGD<Z,STA)8O4'J@)I9GF
@.
**>K7A.YNJQ<&4GPZ4A!0W
J=0U[R;UEA_6#MI7E!+ P04
M " #CAFI6/HK7?.\ K @ $0 &1O8U!R;W!S+V-O&ULS9+/
M3L,P#(=?!>7>.FT9AZC+96BG(2$Q"<0M2KPMHOFCQ*C=V].6K1."!^ 8^Y?/
[...]

In other cases, the CPU is running hot and decoding is not stopping or it
takes a very long time but the decoding result is not correct.
Not sure how I can help to find the reason.

Am So., 21. Mai 2023 um 12:33 Uhr schrieb UmamiAppearance <
@.***>:

Give it a try now.


Reply to this email directly, view it on GitHub
#52 (comment),
or unsubscribe
https://github.com/notifications/unsubscribe-auth/ABI2CFKRFQIIEQBEL6647RLXHHVQVANCNFSM6AAAAAAYIAFCKI
.
You are receiving this because you authored the thread.Message ID:
@.***>

Originally posted by @ecofi in #52 (comment)

Invalid decoding for original UUencode charset

Hi,

I don't know if I'm using the incorrect options but I don't get UUencode working for decoding the attached string ( see attached file).
I'm using:
let buffer = UUencode().decode(str)

The string contains space and I get an error message for invalid space character. The attache sample represents an encoded binary as jpg picture.

pic_uue.txt

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.