Socket
Socket
Sign inDemoInstall

uint8arrays

Package Overview
Dependencies
27
Maintainers
1
Versions
43
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    uint8arrays

Utility functions to make dealing with Uint8Arrays easier


Version published
Weekly downloads
712K
decreased by-4.75%
Maintainers
1
Install size
10.3 MB
Created
Weekly downloads
 

Changelog

Source

1.1.0 (2020-08-07)

Features

  • support ascii encoding (#2) (098724d)

<a name="1.0.0"></a>

Readme

Source

Uint8Arrays

Some utility functions to make dealing with Uint8Arrays more pleasant.

API

compare(a, b)

Compare two Uint8Arrays

Example
const compare = require('uint8arrays/compare')

const arrays = [
  Uint8Array.from([3, 4, 5]),
  Uint8Array.from([0, 1, 2])
]

const sorted = arrays.sort(compare)

console.info(sorted)
// [
//    Uint8Array[0, 1, 2]
//    Uint8Array[3, 4, 5]
// ]

concat(arrays, [length])

Concatenate one or more array-likes and return a Uint8Array with their contents.

If you know the length of the arrays, pass it as a second parameter, otherwise it will be calculated by traversing the list of arrays.

Example
const concat = require('uint8arrays/concat')

const arrays = [
  Uint8Array.from([0, 1, 2]),
  Uint8Array.from([3, 4, 5])
]

const all = concat(arrays, 6)

console.info(all)
// Uint8Array[0, 1, 2, 3, 4, 5]

equals(a, b)

Returns true if the two arrays are the same array or if they have the same length and contents.

Example
const equals = require('uint8arrays/equals')

const a = Uint8Array.from([0, 1, 2])
const b = Uint8Array.from([3, 4, 5])
const c = Uint8Array.from([0, 1, 2])

console.info(equals(a, b)) // false
console.info(equals(a, c)) // true
console.info(equals(a, a)) // true

fromString(string, encoding = 'utf8')

Returns a new Uint8Array created from the passed string and interpreted as the passed encoding.

Supports utf8 and any of the multiformats encodings.

Example
const fromString = require('uint8arrays/from-string')

console.info(fromString('hello world')) // Uint8Array[104, 101 ...
console.info(fromString('00010203aabbcc', 'base16')) // Uint8Array[0, 1 ...
console.info(fromString('AAECA6q7zA', 'base64')) // Uint8Array[0, 1 ...
console.info(fromString('01234', 'ascii')) // Uint8Array[48, 49 ...

toString(array, encoding = 'utf8')

Returns a string created from the passed Uint8Array in the passed encoding.

Supports utf8 and any of the multiformats encodings.

Example
const fromString = require('uint8arrays/from-string')

console.info(toString(Uint8Array.from([104, 101...]))) // 'hello world'
console.info(toString(Uint8Array.from([0, 1, 2...]), 'base16')) // '00010203aabbcc'
console.info(toString(Uint8Array.from([0, 1, 2...]), 'base64')) // 'AAECA6q7zA'
console.info(toString(Uint8Array.from([48, 49, 50...]), 'ascii')) // '01234'

FAQs

Last updated on 07 Aug 2020

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc