4.0.3 • Published 9 months ago

@algorithm.ts/base64 v4.0.3

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

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==

Related

  • 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
4.0.3

9 months ago

4.0.2

10 months ago

4.0.1

1 year ago

4.0.0

1 year ago

3.1.1

2 years ago

3.1.0

2 years ago

3.0.0-alpha.8

2 years ago

3.0.0

2 years ago

3.0.0-alpha.7

2 years ago

3.0.0-alpha.6

3 years ago

3.0.0-alpha.3

3 years ago

3.0.0-alpha.2

3 years ago

3.0.0-alpha.5

3 years ago

3.0.0-alpha.4

3 years ago

3.0.0-alpha.1

3 years ago

3.0.0-alpha.0

3 years ago

2.0.14

3 years ago

2.0.13

3 years ago

2.0.12

3 years ago

2.0.8-alpha.0

3 years ago

2.0.7-alpha.1

3 years ago

2.0.7-alpha.0

3 years ago

2.0.5

3 years ago

2.0.4

3 years ago

2.0.11

3 years ago

2.0.7

3 years ago

2.0.6

3 years ago

2.0.9

3 years ago

2.0.10

3 years ago

2.0.8

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

2.0.0-alpha.0

3 years ago

1.0.24

3 years ago