npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

byteview

v2.0.1

Published

TypedArray. Work with bytes. Can be used as a Buffer, TypedArray, BitView, DataView. Client side and server side support.

Downloads

73

Readme

ByteView

plot plot JavaScript Style Guide

Work with bytes. Can be used as a Buffer, TypedArray, BitView, DataView. Client side and server side support. Encode strings & serialize objects.

Table of Contents

Install

npm i byteview 

Usage

static ByteView.from:

import ByteView from 'byteview'

const bv = ByteView.from('Hello World!')

/*
 * nodejs prints: <ByteView SGVsbG8gV29ybGQh />
 * browser prints: ByteView(12) [
 *   72, 101, 108, 108, 111,
 *   32,  87, 111, 114, 108,
 *   100,  33
 * ]
 */
console.log(bv)
class ByteView extends Uint8Array {

  static from (
    input: ArrayLike | ArrayBufferView | ArrayBuffer | string | bigint,
    encodingOrOffset?: string | number,
    length?: number
  ): ByteView

  static alloc (size: number, encoding?: string): ByteView

  static allocBits (size: number, encoding?: string): ByteView

  static concat (list: Array<ByteView>, length?: number): ByteView

  /**
   *
   * Returns true if instance of ByteView.
   */
  static isByteView (byteView: any): boolean

  /**
   *
   * Returns true if instance of TypedArray or DataView.
   */
  static isView (input: any): boolean

  /**
   *
   * Returns true if instance of ArrayBuffer.
   */
  static isNativeBuffer (input: any): boolean

  /**
   *
   * Returns a base64 encoded string.
   */
  static serialize (input: object): string

  /**
   *
   * Get byteLength of string.
   */
  static byteLength (
    string: string,
    encoding = 'utf8'
  ): number

  /**
   *
   * If running process is little endian.
   */
  static isOSLittleEndian: boolean

  /**
   *
   * Get real size of ByteView.
   * Useful when being used as a bit array.
   */
  get size (): number

  /**
   *
   * Get bitOffset of ByteView.
   * Useful when being used as a bit array.
   */
  get bitOffset (): number

  get encoding (): string

  set encoding (encoding: string)

  /**
   *
   * Interprets byteView as an array of unsigned 16-bit integers and swaps the byte order in-place.
   */
  swap16 (): this

  /**
   *
   * Interprets byteView as an array of unsigned 32-bit integers and swaps the byte order in-place.
   */
  swap32 (): this

  /**
   *
   * Interprets byteView as an array of unsigned 64-bit integers and swaps the byte order in-place.
   */
  swap64 (): this

  /**
   *
   * Gets an array of 3 valid colors.
   */
  getRGB (index: number): [number, number, number]

  /**
   *
   * Gets a color hex at the specified index.
   */
  getColorHex (index: number): string

  /**
   *
   * Returns the bit at the specified index.
   * Accounts for ByteView.bitOffset.
   */
  getBit (index: number): 1 | 0

  /**
   *
   * Sets the bit at the specified index.
   * Accounts for ByteView.bitOffset.
   */
  setBit (index: number, value: number): number

  /**
   *
   * Returns the bits from start to end.
   */
  sliceBits (start: number, end: number): number

  /**
   *
   * Get an unsigned 5-bit integer.
   */
  getUint5 (index: number): number

  /**
   *
   * Get an unsigned 6-bit integer.
   */
  getUint6 (index: number): number

  /**
   *
   * Get an unsigned 8-bit integer.
   */
  getUint8 (offset: number): number

  /**
   *
   * Set an unsigned 8-bit integer.
   */
  setUint8 (
    offset: number,
    value: number
  ): number

  /**
   *
   * Get an unsigned 16-bit integer.
   */
  getUint16 (
    offset: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Set an unsigned 16-bit integer.
   */
  setUint16 (
    offset: number,
    value: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Get an unsigned 32-bit integer.
   */
  getUint32 (
    offset: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Set an unsigned 32-bit integer.
   */
  setUint32 (
    offset: number,
    value: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Get an unsigned 64-bit bigint.
   */
  getBigUint64 (
    offset: number,
    littleEndian = ByteView.isOSLittleEndian
  ): bigint

  /**
   *
   * Set an unsigned 64-bit bigint.
   */
  setBigUint64 (
    offset: number,
    value: bigint,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Get a signed integer.
   */
  getInt (
    offset: number,
    byteLength: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Get a signed 8-bit integer.
   */
  getInt8 (offset: number): number

  /**
   *
   * Set a signed 8-bit integer.
   */
  setInt8 (offset: number, value: number): number

  /**
   *
   * Get a signed 16-bit integer.
   */
  getInt16 (
    offset: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Set a signed 16-bit integer.
   */
  setInt16 (
    offset: number,
    value: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Get a signed 32-bit integer.
   */
  getInt32 (
    offset: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Set a signed 32-bit integer.
   */
  setInt32 (
    offset: number,
    value: number,
    littleEndian = ByteView.isOSLittleEndian
  ): number

  /**
   *
   * Set a signed 6-bit integer.
   */
  getInt6 (index: number): number

  /**
   *
   * Get a JSON object representation of a ByteView.
   */
  toJSON (): {
    type: 'ByteView',
    data: Array<number>
  }

  /**
   *
   * Prints a ByteView string.
   */
  inspect (): string

  toString (
    encoding?: 'utf8' |
      'hex' |
      'base32' |
      'base32hex' |
      'base32crockford' |
      'base64' |
      'base64url' |
      'ascii' |
      'latin1' |
      'binary' |
      'ucs2' |
      'ucs-2' |
      'utf16le' |
      'utf-16le'
  ): string

  subarray (start: number, end?: number): ByteView

  copy (
    target: ByteView | ArrayBufferView,
    targetStart?: number,
    start?: number,
    end?: number
  ): number

  fill (
    val: ByteView | number | Array,
    start: number,
    end?: number,
    encoding?: number
  ): this

  equals (byteView: ByteView): boolean

  compare (
    target: ByteView,
    start?: number,
    end?: number,
    thisStart?: number,
    thisEnd?: number
  ): -1 | 0 | 1

  write (
    string: string,
    offset: number,
    length?: number,
    encoding?: string
  ): number

  toBigInt (): bigint

  padStart (targetLength: number): this
}