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

@nutshelllabs/fns

v3.1.4

Published

React-pdf helper functions

Readme

@nutshelllabs/fns

Lightweight utility functions for react-pdf

A collection of functional programming utilities used internally by react-pdf. Zero dependencies, tree-shakeable, and fully typed.

Installation

yarn add @nutshelllabs/fns

Table of Contents

Functions

adjust

Applies a function to the value at the given index of an array.

import { adjust } from '@nutshelllabs/fns';

adjust(1, (x) => x * 2, [1, 2, 3]); // => [1, 4, 3]
adjust(-1, (x) => x + 10, [1, 2, 3]); // => [1, 2, 13]

asyncCompose

Performs right-to-left function composition with async functions support. asyncCompose(f, g, h)(x) is equivalent to await f(await g(await h(x))).

import { asyncCompose } from '@nutshelllabs/fns';

const addAsync = async (x) => x + 1;
const double = (x) => x * 2;

const fn = asyncCompose(double, addAsync);
await fn(5); // => 12

capitalize

Capitalizes the first letter of each word in a string.

import { capitalize } from '@nutshelllabs/fns';

capitalize('hello world'); // => 'Hello World'
capitalize('foo bar baz'); // => 'Foo Bar Baz'

castArray

Wraps a value in an array if it isn't one already.

import { castArray } from '@nutshelllabs/fns';

castArray('foo'); // => ['foo']
castArray(['foo']); // => ['foo']
castArray(123); // => [123]

compose

Performs right-to-left function composition. compose(f, g, h)(x) is equivalent to f(g(h(x))).

import { compose } from '@nutshelllabs/fns';

const add1 = (x) => x + 1;
const double = (x) => x * 2;

const fn = compose(double, add1);
fn(5); // => 12

dropLast

Drops the last element from an array or string.

import { dropLast } from '@nutshelllabs/fns';

dropLast([1, 2, 3]); // => [1, 2]
dropLast('hello'); // => 'hell'

evolve

Applies transformations to an object's values based on a transformation map.

import { evolve } from '@nutshelllabs/fns';

evolve(
  { count: (n) => n + 1, name: (s) => s.toUpperCase() },
  { name: 'item', count: 5 },
);
// => { name: 'ITEM', count: 6 }

get

Retrieves a value at a given path from an object with a default fallback.

import { get } from '@nutshelllabs/fns';

get({ a: { b: 1 } }, ['a', 'b'], 0); // => 1
get({ a: { b: 1 } }, ['a', 'c'], 0); // => 0
get({ a: { b: 1 } }, 'a', {}); // => { b: 1 }

isNil

Checks if a value is null or undefined.

import { isNil } from '@nutshelllabs/fns';

isNil(null); // => true
isNil(undefined); // => true
isNil(0); // => false
isNil(''); // => false

last

Returns the last element of an array or last character of a string.

import { last } from '@nutshelllabs/fns';

last([1, 2, 3]); // => 3
last('abc'); // => 'c'
last([]); // => undefined

mapValues

Maps over the values of an object, applying a function to each value.

import { mapValues } from '@nutshelllabs/fns';

mapValues({ a: 1, b: 2 }, (v) => v * 2); // => { a: 2, b: 4 }
mapValues({ x: 'foo', y: 'bar' }, (v, k) => `${k}:${v}`);
// => { x: 'x:foo', y: 'y:bar' }

matchPercent

Parses a percentage string and returns both the numeric value and decimal percent.

import { matchPercent } from '@nutshelllabs/fns';

matchPercent('50%'); // => { value: 50, percent: 0.5 }
matchPercent('-25%'); // => { value: -25, percent: -0.25 }
matchPercent('abc'); // => null

omit

Creates a new object excluding specified keys.

import { omit } from '@nutshelllabs/fns';

omit('b', { a: 1, b: 2, c: 3 }); // => { a: 1, c: 3 }
omit(['a', 'c'], { a: 1, b: 2, c: 3 }); // => { b: 2 }

parseFloat

Parses a string to a float. Non-string values pass through unchanged.

import { parseFloat } from '@nutshelllabs/fns';

parseFloat('3.14'); // => 3.14
parseFloat('10px'); // => 10
parseFloat(42); // => 42
parseFloat(null); // => null

pick

Creates a new object with only the specified keys.

import { pick } from '@nutshelllabs/fns';

pick(['a', 'c'], { a: 1, b: 2, c: 3 }); // => { a: 1, c: 3 }
pick(['x'], { a: 1, b: 2 }); // => {}

repeat

Creates an array with an element repeated a specified number of times.

import { repeat } from '@nutshelllabs/fns';

repeat('a', 3); // => ['a', 'a', 'a']
repeat(0, 4); // => [0, 0, 0, 0]

reverse

Returns a new array with elements in reverse order (does not mutate original).

import { reverse } from '@nutshelllabs/fns';

reverse([1, 2, 3]); // => [3, 2, 1]
reverse(['a', 'b', 'c']); // => ['c', 'b', 'a']

upperFirst

Converts the first character of a string to uppercase.

import { upperFirst } from '@nutshelllabs/fns';

upperFirst('hello'); // => 'Hello'
upperFirst('hELLO'); // => 'HELLO'

without

Returns a new array excluding the specified values.

import { without } from '@nutshelllabs/fns';

without([2, 4], [1, 2, 3, 4, 5]); // => [1, 3, 5]
without(['b'], ['a', 'b', 'c']); // => ['a', 'c']

License

MIT