Git Product home page Git Product logo

base32-encode's Introduction

Base32 Encode

Base32 encoder with support for multiple variants.

Installation

npm install --save base32-encode

Usage

import base32Encode from 'base32-encode'
const data = new Uint8Array([0x74, 0x65, 0x73, 0x74])

console.log(base32Encode(data, 'Crockford'))
//=> EHJQ6X0

console.log(base32Encode(data, 'RFC4648'))
//=> ORSXG5A=

console.log(base32Encode(data, 'RFC4648', { padding: false }))
//=> ORSXG5A

console.log(base32Encode(data, 'RFC4648-HEX'))
//=> EHIN6T0=

API

base32Encode(data, variant[, options])

  • data (ArrayBuffer | Int8Array | Uint8Array | Uint8ClampedArray, required)
  • variant ('RFC3548' | 'RFC4648' | 'RFC4648-HEX' | 'Crockford', required)
  • options (object, optional)
    • padding (boolean, optional) - If set, forcefully enable or disable padding. The default behavior is to follow the default of the selected variant.
  • returns string

Encode the data in data into a Base32 encoded string.

Variants

See also

base32-encode's People

Contributors

linusu avatar vasco-santos avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

base32-encode's Issues

[Runtime error] Cannot use import statement outside a module

     /home/runner/work/skynet-js/skynet-js/node_modules/base32-encode/index.js:1
    ({"Object.<anonymous>":function(module,exports,require,__dirname,__filename,global,jest){import toDataView from 'to-data-view'
                                                                                             ^^^^^^

    SyntaxError: Cannot use import statement outside a module

      1 | import base32Decode from "base32-decode";
    > 2 | import base32Encode from "base32-encode";
        | ^
      3 | import { fromByteArray, toByteArray } from "base64-js";
      4 |
      5 | import { assertUint64 } from "./number";

      at Runtime.createScriptFromCode (../node_modules/jest-runtime/build/index.js:1350:14)
      at Object.<anonymous> (utils/encoding.ts:2:1)

https://github.com/SkynetLabs/skynet-js/pull/227/checks?check_run_id=3160347860

ArrayBuffer concerns and feature request

Hi, we're using this library to encode bytes to a character set that works well with QR codes. We noticed that the input to your API is an ArrayBuffer rather than a view on that ArrayBuffer, such as a Uint8Array.

If a view were accepted instead, we wouldn't have to worry about corner cases where the underlying ArrayBuffer isn't the same size as the view. If a Uint8Array, x, is a view on an ArrayBuffer that is larger than the Uint8Array, then passing the x.buffer to the API in this library would result in it encoding outside of the view. This requires the caller to check that the underlying ArrayBuffer is the same size, and if not, create a new ArrayBuffer made by copying the data within the view.

Could your API and documentation be adjusted to accept views -- or, at least minimally, a Uint8Array view as it is likely the most common? Looking at the code, a Uint8Array is internally used to wrap the ArrayBuffer parameter. My understanding is that this wouldn't need to change if the input were a Uint8Array as opposed to an ArrayBuffer.

I'll be filing a similar issue on https://github.com/LinusU/base32-decode -- where the return value is an ArrayBuffer instead of a view on one.

Related: digitalbazaar/vpqr#2

Please add a LICENSE file

Please add a LICENSE file with your copyright information and the full text of the MIT LICENSE. The MIT licenses requires that the full text of the license accompany the source code.

[Install error] The engine "node" is incompatible with this module.

$ yarn
yarn install v1.22.10
[1/4] ๐Ÿ”  Resolving packages...
[2/4] ๐Ÿšš  Fetching packages...
error [email protected]: The engine "node" is incompatible with this module. Expected version "^12.20.0 || ^14.13.1 || >=16.0.0". Got "15.11.0"
error Found incompatible module.
info Visit https://yarnpkg.com/en/docs/cli/install for documentation about this command.

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.