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

@rcompat/fn

v0.3.0

Published

Standard library functions

Readme

@rcompat/fn

Function utilities for JavaScript runtimes.

What is @rcompat/fn?

A cross-runtime module providing common function utilities for functional programming patterns. Works consistently across Node, Deno, and Bun.

Installation

npm install @rcompat/fn
pnpm add @rcompat/fn
yarn add @rcompat/fn
bun add @rcompat/fn

Usage

defined

A predicate function that checks if a value is not undefined.

import fn from "@rcompat/fn";

fn.defined("hello");    // true
fn.defined(0);          // true
fn.defined(null);       // true
fn.defined(false);      // true
fn.defined(undefined);  // false

Useful for filtering out undefined values:

import fn from "@rcompat/fn";

const values = [1, undefined, 2, undefined, 3];
const filtered = values.filter(fn.defined);
// [1, 2, 3]

identity

The identity function — returns its input unchanged.

import fn from "@rcompat/fn";

fn.identity(42);        // 42
fn.identity("hello");   // "hello"
fn.identity({ a: 1 });  // { a: 1 }

Useful as a default callback or no-op transformer:

import fn from "@rcompat/fn";

function transform(data, transformer = fn.identity) {
  return transformer(data);
}

transform({ name: "Bob" });  // { name: "Bob" }
transform({ name: "Bob" }, x => ({ ...x, id: 1 }));  // { name: "Bob", id: 1 }

async.map

Parallel async map over an array using Promise.all. Maps all items concurrently and waits for all to complete.

import fn from "@rcompat/fn";

const urls = ["/api/users/1", "/api/users/2", "/api/users/3"];

// fetch all users in parallel
const users = await fn.async.map(urls, async (url) => {
  const response = await fetch(url);
  return response.json();
});
// [{ id: 1, ... }, { id: 2, ... }, { id: 3, ... }]
import fn from "@rcompat/fn";

// with index parameter
const results = await fn.async.map([10, 20, 30], async (value, index) => {
  return { index, doubled: value * 2 };
});
// [{ index: 0, doubled: 20 }, { index: 1, doubled: 40 }, { index: 2, doubled: 60 }]

API Reference

defined(value)

declare function defined<T>(value: T): boolean;

Checks if a value is not undefined.

| Parameter | Type | Description | |-----------|------|---------------------| | value | T | The value to check |

Returns: true if the value is not undefined, false otherwise.

identity(value)

declare function identity<T>(value: T): T;

Returns the input value unchanged.

| Parameter | Type | Description | |-----------|------|----------------------| | value | T | The value to return |

Returns: The same value that was passed in.

async.map(array, mapper)

declare function map<T, U>(
  array: T[],
  mapper: (item: T, index: number, array: T[]) => Promise<U>
): Promise<U[]>;

Maps an array with an async function, executing all operations in parallel.

| Parameter | Type | Description | | --------- | ---------------------------------------------------- | ---------------------- | | array | T[] | The array to map over | | mapper | (item: T, index: number, array: T[]) => Promise<U> | Async mapping function |

Returns: A promise that resolves to an array of mapped values.

Examples

Filter undefined from array

import fn from "@rcompat/fn";

const users = [
  { name: "John" },
  undefined,
  { name: "Bob" },
  undefined,
];

users.filter(fn.defined);
// [{ name: "John" }, { name: "Bob" }]

Optional transformation pipeline

import fn from "@rcompat/fn";

function processData(data, options = {}) {
  const {
    preProcess = fn.identity,
    postProcess = fn.identity,
  } = options;

  const prepared = preProcess(data);
  const result = doWork(prepared);
  return postProcess(result);
}

// use with default (no-op) transformations
processData(myData);

// use with custom transformations
processData(myData, {
  preProcess: data => data.map(x => x * 2),
  postProcess: result => result.filter(x => x > 10),
});

Conditional mapping

import fn from "@rcompat/fn";

function conditionalMap(array, condition, mapper) {
  return array.map(condition ? mapper : fn.identity);
}

const numbers = [1, 2, 3];

conditionalMap(numbers, true, x => x * 2);   // [2, 4, 6]
conditionalMap(numbers, false, x => x * 2);  // [1, 2, 3]

Parallel API requests

import fn from "@rcompat/fn";

async function products(ids) {
  return fn.async.map(ids, async id => {
    const response = await fetch(`/api/products/${id}`);
    return response.json();
  });
}

const products = await products([1, 2, 3, 4, 5]);

## Cross-Runtime Compatibility

| Runtime | Supported |
|---------|-----------|
| Node.js | ✓         |
| Deno    | ✓         |
| Bun     | ✓         |

No configuration required — just import and use.

## License

MIT

## Contributing

See [CONTRIBUTING.md](../../CONTRIBUTING.md) in the repository root.