New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More

@algorithm.ts/base64

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@algorithm.ts/base64

A Base64 encoding implementation.

4.0.3
latest
Version published
Weekly downloads
107
12.63%
Maintainers
0
Weekly downloads
 
Created

@algorithm.ts/base64


A typescript implementation of the base64 encoding. Unlike traditional implementations, this project uses Uint8Array to represent byte streams.

Install

  • npm

    npm install --save @algorithm.ts/base64
    
  • yarn

    yarn add @algorithm.ts/base64
    

Usage

  • encode: Encode a Uint8Array into base64 encoded string.

    // node env: import { TextEncoder } from 'util'
    import { encode } from '@algorithm.ts/base64'
    
    const getBytes = (text: string): Uint8Array => {
      const textEncoder = new TextEncoder()
      const data: Uint8Array = textEncoder.encode(text)
      return data
    }
    
    encode(getBytes('Hello, world!')) // => 'SGVsbG8sIHdvcmxkIQ=='
    
  • decode: Decode a base64 encoded string to Uint8Array

    import { decode } from '@algorithm.ts/base64'
    
    const data: Uint8Array = decode('SGVsbG8sIHdvcmxkIQ==')
    const textDecoder = new TextDecoder()
    textDecoder.decode(data) // => 'Hello, world!'
    
  • validate: Check if a string is base64 encoded.

    validate('SGVsbG8sIHdvcmxkIQ==') // => true
    
  • Custom code map.

    // node env: import { TextEncoder } from 'util'
    import { Base64 } from '@algorithm.ts/base64'
    
    const getBytes = (text: string): Uint8Array => {
      const textEncoder = new TextEncoder()
      const data: Uint8Array = textEncoder.encode(text)
      return data
    }
    
    const base64 = new Base64({
      CODES: '#ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+'
    })
    base64.encode(getBytes('Hello, world!')) // => RFUraF7rHGcublwjHP==
    
  • BASE64 Table

    IndexBinaryCharIndexBinaryCharIndexBinaryCharIndexBinaryChar
    0000000A16010000Q32100000g48110000w
    1000001B17010001R33100001h49110001x
    2000010C18010010S34100010i50110010y
    3000011D19010011T35100011j51110011z
    4000100E20010100U36100100k521101000
    5000101F21010101V37100101l531101011
    6000110G22010110W38100110m541101102
    7000111H23010111X39100111n551101113
    8001000I24011000Y40101000o561110004
    9001001J25011001Z41101001p571110015
    10001010K26011010a42101010q581110106
    11001011L27011011b43101011r591110117
    12001100M28011100c44101100s601111008
    13001101N29011101d45101101t611111019
    14001110O30011110e46101110u62111110+
    15001111P31011111f47101111v63111111/
  • Base64 | Wikipedia

  • base-64 | github

  • atob() | MDN

  • btoa() | MDN

FAQs

Package last updated on 06 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts