Gathering detailed insights and metrics for uint8arrays
Gathering detailed insights and metrics for uint8arrays
Gathering detailed insights and metrics for uint8arrays
Gathering detailed insights and metrics for uint8arrays
@lit-protocol/uint8arrays
This submodule provides functions to make dealing with Uint8Arrays easier.
uint8array-tools
A library for dealing with Uint8Arrays.
uint8-varint
Read/write unsigned varints from Uint8Arrays and Uint8ArrayLists
isomorphic-textencoder
encode/decode Uint8Arrays to strings
npm install uint8arrays
Module System
Min. Node Version
Typescript Support
Node Version
NPM Version
37 Stars
124 Commits
25 Forks
3 Watching
4 Branches
11 Contributors
Updated on 20 Sept 2024
TypeScript (72.84%)
JavaScript (27.16%)
Cumulative downloads
Total Downloads
Last day
9.5%
197,908
Compared to previous day
Last week
13%
1,079,554
Compared to previous week
Last month
11.9%
4,093,656
Compared to previous month
Last year
47.7%
39,765,323
Compared to previous year
1
3
Utility functions to make dealing with Uint8Arrays easier
Uint8Array
s bring memory-efficient(ish) byte handling to browsers - they are similar to Node.js Buffer
s but lack a lot of the utility methods present on that class.
This module exports a number of function that let you do common operations - joining Uint8Arrays together, seeing if they have the same contents etc.
Since Node.js Buffer
s are also Uint8Array
s, it falls back to Buffer
internally where it makes sense for performance reasons.
Create a new Uint8Array
. When running under Node.js, Buffer
will be used in preference to Uint8Array
.
1import { alloc } from 'uint8arrays/alloc' 2 3const buf = alloc(100)
Create a new Uint8Array
. When running under Node.js, Buffer
will be used in preference to Uint8Array
.
On platforms that support it, memory referenced by the returned Uint8Array
will not be initialized.
1import { allocUnsafe } from 'uint8arrays/alloc' 2 3const buf = allocUnsafe(100)
Compare two Uint8Arrays
1import { compare } from 'uint8arrays/compare' 2 3const arrays = [ 4 Uint8Array.from([3, 4, 5]), 5 Uint8Array.from([0, 1, 2]) 6] 7 8const sorted = arrays.sort(compare) 9 10console.info(sorted) 11// [ 12// Uint8Array[0, 1, 2] 13// Uint8Array[3, 4, 5] 14// ]
Concatenate one or more Uint8Array
s 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.
1import { concat } from 'uint8arrays/concat' 2 3const arrays = [ 4 Uint8Array.from([0, 1, 2]), 5 Uint8Array.from([3, 4, 5]) 6] 7 8const all = concat(arrays, 6) 9 10console.info(all) 11// Uint8Array[0, 1, 2, 3, 4, 5]
Returns true if the two arrays are the same array or if they have the same length and contents.
1import { equals } from 'uint8arrays/equals' 2 3const a = Uint8Array.from([0, 1, 2]) 4const b = Uint8Array.from([3, 4, 5]) 5const c = Uint8Array.from([0, 1, 2]) 6 7console.info(equals(a, b)) // false 8console.info(equals(a, c)) // true 9console.info(equals(a, a)) // true
Returns a new Uint8Array
created from the passed string and interpreted as the passed encoding.
Supports utf8
and any of the multibase encodings as implemented by the multiformats module.
1import { fromString } from 'uint8arrays/from-string' 2 3console.info(fromString('hello world')) // Uint8Array[104, 101 ... 4console.info(fromString('00010203aabbcc', 'base16')) // Uint8Array[0, 1 ... 5console.info(fromString('AAECA6q7zA', 'base64')) // Uint8Array[0, 1 ... 6console.info(fromString('01234', 'ascii')) // Uint8Array[48, 49 ...
Returns a string created from the passed Uint8Array
in the passed encoding.
Supports utf8
and any of the multibase encodings as implemented by the multiformats module.
1import { toString } from 'uint8arrays/to-string' 2 3console.info(toString(Uint8Array.from([104, 101...]))) // 'hello world' 4console.info(toString(Uint8Array.from([0, 1, 2...]), 'base16')) // '00010203aabbcc' 5console.info(toString(Uint8Array.from([0, 1, 2...]), 'base64')) // 'AAECA6q7zA' 6console.info(toString(Uint8Array.from([48, 49, 50...]), 'ascii')) // '01234'
Returns a Uint8Array
containing a
and b
xored together.
1import { xor } from 'uint8arrays/xor' 2 3console.info(xor(Uint8Array.from([1, 0]), Uint8Array.from([0, 1]))) // Uint8Array[1, 1]
Compares the distances between two xor Uint8Array
s.
1import { xor } from 'uint8arrays/xor' 2import { xorCompare } from 'uint8arrays/xor-compare' 3 4const target = Uint8Array.from([1, 1]) 5const val1 = Uint8Array.from([1, 0]) 6const xor1 = xor(target, val1) 7 8const val2 = Uint8Array.from([0, 1]) 9const xor2 = xor(target, val2) 10 11console.info(xorCompare(xor1, xor2)) // -1 or 0 or 1
1$ npm i uint8arrays
<script>
tagLoading this module through a script tag will make it's exports available as Uint8arrays
in the global namespace.
1<script src="https://unpkg.com/uint8arrays/dist/index.min.js"></script>
Licensed under either of
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
0 existing vulnerabilities detected
Reason
license file detected
Details
Reason
Found 3/23 approved changesets -- score normalized to 1
Reason
1 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
Reason
project is not fuzzed
Details
Reason
branch protection not enabled on development/release branches
Details
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
Score
Last Scanned on 2024-11-25
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More