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 🙏

© 2026 – Pkg Stats / Ryan Hefner

nv-buf-resize-util

v1.0.0

Published

[![npm version](https://img.shields.io/npm/v/nv-buf-resize-util.svg)](https://www.npmjs.com/package/nv-buf-resize-util) [![npm downloads](https://img.shields.io/npm/dm/nv-buf-resize-util.svg)](https://www.npmjs.com/package/nv-buf-resize-util) [![license](

Readme

nv-buf-resize-util

npm version npm downloads license

Tiny and fast utilities for resizing TypedArray buffers.

This library provides simple helpers to:

  • expand a TypedArray
  • shrink a TypedArray
  • resize a TypedArray to a specific size

It keeps the original TypedArray type, allows custom allocation strategies, and has zero dependencies.


Features

  • Works with all TypedArrays
  • Keeps the original array type
  • Custom allocation and copy strategies
  • Configurable stride
  • Zero dependencies
  • Very small and simple

Supported arrays:

  • Int8Array
  • Uint8Array
  • Uint8ClampedArray
  • Int16Array
  • Uint16Array
  • Int32Array
  • Uint32Array
  • Float32Array
  • Float64Array
  • BigInt64Array
  • BigUint64Array

Installation

npm install nv-buf-resize-util

Quick Example

const resize = require("nv-buf-resize-util")

const src = new Uint8Array([1,2,3,4])

const expanded = resize.expand(src,2)
const shrunk   = resize.shrink(src,1)
const resized  = resize(src,10)

console.log(expanded.length) // 6
console.log(shrunk.length)   // 3
console.log(resized.length)  // 10

API

resize(src, unit_cnt, cfg?)

Resize a typed array to a specific unit count.

new_length = stride * unit_cnt

Example:

const resize = require("nv-buf-resize-util")

const a = new Uint8Array([1,2,3])

const b = resize(a,10)

console.log(b.length) // 10

expand(src, incr_unit_cnt, cfg?)

Increase array size.

new_length = src.length + stride * incr_unit_cnt

Example:

const { expand } = require("nv-buf-resize-util")

const a = new Uint8Array([1,2,3])

const b = expand(a,2)

console.log(b.length) // 5

shrink(src, decr_unit_cnt, cfg?)

Decrease array size.

new_length = src.length - stride * decr_unit_cnt

Example:

const { shrink } = require("nv-buf-resize-util")

const a = new Uint8Array([1,2,3,4])

const b = shrink(a,1)

console.log(b.length) // 3

Configuration

All operations accept an optional configuration object.

Example:

const resize = require("nv-buf-resize-util")

const cfg = {
  stride: 2,
  aloc_when_shirnk: false
}

const buf = new Uint8Array([1,2,3,4])

const out = resize(buf,10,cfg)

Configuration options:

| option | description | |------|-------------| | aloc | custom allocation function | | copy | custom copy function | | stride | element stride | | aloc_when_shirnk | allocate new buffer when shrinking | | expand_ratio | expansion hint |

Default configuration:

{
  aloc: (new_len,src)=>new src.constructor(new_len),
  copy: (src,dst)=>dst.set(src,0),
  stride: 1,
  aloc_when_shirnk: true,
  expand_ratio: 0.5
}

Internal APIs

These functions skip config normalization and are slightly faster.

  • _expand
  • _shrink

Example:

const resize = require("nv-buf-resize-util")

const cfg = resize.fmt_cfg()

const out = resize._expand(new Uint8Array([1,2,3]),1,cfg)

Performance

Benchmark environment:

  • Node.js
  • rounds = 10,000,000

Results:

expand               3186.00 ms 3138731 ops/s
expand stride        2643.44 ms 3782945 ops/s
shrink               7966.60 ms 1255240 ops/s
shrink no realloc    6662.46 ms 1500947 ops/s
resize expand        3235.88 ms 3090347 ops/s
resize shrink        8168.45 ms 1224222 ops/s
resize equal         2484.73 ms 4024583 ops/s
_expand internal     2014.37 ms 4964340 ops/s
_shrink internal     7393.33 ms 1352570 ops/s

Notes:

  • expand is usually faster than shrink
  • shrinking may involve additional memory operations
  • internal APIs avoid config normalization overhead

When to Use

This utility is useful when implementing:

  • dynamic buffers
  • binary parsers
  • streaming decoders
  • ring buffers
  • custom memory pools
  • high performance data pipelines

Design Philosophy

The library focuses on:

  • minimal abstraction
  • predictable behavior
  • high performance
  • small code size

It does one thing only: resizing TypedArrays safely and efficiently.


License

ANY