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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@mrpelz/misc-utils

v3.0.1

Published

Miscellaneous TypeScript helpers.

Readme

@mrpelz/misc-utils

Miscellaneous TypeScript helpers.

data

Miscellaneous data conversion helpers.

emptyBuffer

Empty/zero-length Buffer.

falseBuffer

One-byte 0 Buffer.

trueBuffer

One-byte 1 Buffer.

arrayCompare

const arrayCompare = <
  A extends Array<unknown>,
  B extends Array<unknown>,
>(
  a: A,
  b: B,
): b is B

Returns true if all elements of array a strict-equal array b.

arrayPadLeft

const arrayPadLeft = <T>(
  input: T[],
  length: number,
  value: T = null as unknown as T,
): T[]

Inserts length-n of value at the start of array input.
Modifies array in-place and returns it.

arrayPadRight

const arrayPadRight = <T>(
  input: T[],
  length: number,
  value: T = null as unknown as T,
): T[]

Inserts length-n of value at the end of array input.
Modifies array in-place and returns it.

bufferChunks

const bufferChunks = (input: Buffer, chunkSize = 1): Buffer[]

Splits Buffer input into chunks of size chunkSize each.
Returns array of Buffer chunks. Throws if input Buffer is smaller than chunkSize.

concatBytes

const concatBytes = (input: number[]): Buffer

Concatenates number-array as bytes and returns as Buffer.

humanPayload

const humanPayload = (input: Buffer): string

Pretty-prints Buffer input’s binary contents in a human readable format, represented as binary, decimal and hexadecimal:

0b00000000 | 0b00000001 | 0b00000010 | 0b00001111 | 0b00010000
         0 |          1 |          2 |         15 |         16
      0x00 |       0x01 |       0x02 |       0x0f |       0x10

Returns pre-formatted multi-line string.

jsonParseGuarded

const jsonParseGuarded = <T>(input: unknown): T | Error

Guarded JSON-parse. Tries to parse anything in input, returns JSON.parse result. Returns Error if input is not a string. If parsing of the string fails, catches the Error and returns it. Error is returned instead of thrown to ease implementation of fallback code paths.

numberToDigits

const numberToDigits = (
  input: number,
  pad = 0,
  radix = 10,
): number[]

Splits number in input into single digits and returns them as number-array. Throws if input is not an integer.

readNumber

const readNumber = (input: Buffer, bytes = 1): number

Read number value from Buffer input with number of bytes. Throws if the buffer isn’t long enough to fit the desired byte count.

  • bytes = 1 → UInt8
  • bytes = 2 → UInt16LE
  • bytes = 4 → UInt32LE

Throws otherwise.

booleanToBuffer

const booleanToBuffer = (input: boolean): Buffer

Turns boolean input into trueBuffer or falseBuffer respectively.

bufferToBoolean

const bufferToBoolean = (input: Buffer): boolean

Turns Buffer input into boolean. A buffer whose first byte is zero is considered false, everything else is considered true. Throws if Buffer isn’t long enough.

swapByte

const swapByte = (input: number): number

Bitwise-invert the the input value. Use for single byte values.

writeNumber

const writeNumber = (input: number, bytes = 1): Buffer

Write number value from input with number of bytes into Buffer. Throws if the number cannot be represented using the desired byte count.

  • bytes = 1 → UInt8
  • bytes = 2 → UInt16LE
  • bytes = 4 → UInt32LE

Throws otherwise.

number

bitRange

const bitRange = (count: number): number

Returns the number bit range of given bit length in count, e.g.

  • 4 → 15
  • 8 → 255
  • 16 → 65535

byteRange

const byteRange = (count: number): number

Returns the number range of given byte length in count, e.g. 4 → 4294967295.