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

map-recursive

v1.2.3

Published

map-recursive

Downloads

19

Readme

map-recursive

map-recursive

Transform object to other form, recursively.

This package has no dependency.

Build Status Node.js CI

mapRecursiveLeaf

declare function mapRecursiveLeaf(
    o: object, 
    callback?: (
        value: boolean | number | string, 
        key?: boolean | number | string, 
        parent?: object
    ) => any
): object;     

Parameters

  • o: The object to transform.
  • callback(optional): The function to process each item against. callback will be invoked for leaf nodes only. The returned value is added to new object.
    • value: The current value being processed in the object.
    • key(optional): The key of the current value being processed in the object.
    • parent(optional): The parent of the current value being processed in the object.

Return Value

A new object with each value being the result of the callback function.

Usage

const mapRecursive = require('map-recursive');

mapRecursive.mapRecursiveLeaf(
    {a: 1, b: 2, c: 3,}, 
    v => v * 10
); // == {a: 10, b: 20, c: 30,}

mapRecursive.mapRecursiveLeaf(
    {a: {b: 1, c: [3, {d: 4, e: 5,}, 6], f: 7},},
    v => v * 10
); // === {a: {b: 10, c: [30, {d: 40, e: 50,}, 60], f: 70},}

mapRecursiveKey

declare function mapRecursiveKey(
    o: object, 
    callback?: (
        key: boolean | number | string, 
        value?: object, 
        parent?: object
    ) => boolean | number | string
): object;     

Parameters

  • o: The object to transform.
  • callback(optional): The function to process each item against. callback will be invoked for internal nodes only. The returned key is added to new object.
    • key: The key of the current value being processed in the object.
    • value(optional): The current value being processed in the object.
    • parent(optional): The parent of the current value being processed in the object.

Return Value

A new object with each key being the result of the callback function.

Usage

const mapRecursive = require('map-recursive');

mapRecursive.mapRecursiveKey(
    {a: {b: 1, c: [3, {d: 4, e: 5,}, 6], f: 7},},
    v => v + v
); // === {aa: {bb: 1, cc: [3, {dd: 4, ee: 5,}, 6], ff: 7},},

mapRecursive.mapRecursiveKey(
    {"@id": "id", name: "name", "@some": "some",},
    v => v.replace(/^@/, "")
); // === {id: "id", name: "name", some: "some",},

mapRecursive

declare function mapRecursive(
    o: object, 
    callback?: (
        value: any, 
        key?: boolean | number | string, 
        parent?: object
    ) => any,
    key?: boolean | number | string,
    parent?: object 
): object;     

Parameters

  • o: The object to transform.
  • callback(optional): The function to process each item against. callback will be invoked for all nodes. The returned value is added to new object.
    • value: The current value being processed in the object.
    • key(optional): The key of the current value being processed in the object.
    • parent(optional): The parent of the current value being processed in the object.
  • key(optional): for internal use.
  • parent(optional): for internal use.

Return Value

A new object with each value being the result of the callback function.

Usage

const mapRecursive = require('map-recursive');

const convertObjectOnlyHaveAtIdToString = v => {
    if (typeof v !== 'object')
        return v;

    const keys = Object.keys(v);
    if (keys.length !== 1)
        return v;

    if (keys[0] !== '@id')
        return v;

    return v['@id'];
};

mapRecursive.mapRecursive(
    {a: {"@id": "id"}}, 
    convertObjectOnlyHaveAtIdToString
); // === {a: "id"}

mapRecursive.mapRecursive(
    {
        "@id": "http://schema.org/preparation",
        "@type": "rdf:Property",
        "http://schema.org/domainIncludes": {
            "@id": "http://schema.org/MedicalProcedure"
        },
        "http://schema.org/isPartOf": {
            "@id": "http://health-lifesci.schema.org"
        },
        "http://schema.org/rangeIncludes": [
            {
                "@id": "http://schema.org/Text"
            },
            {
                "@id": "http://schema.org/MedicalEntity"
            }
        ],
        "rdfs:comment": "Typical preparation that a patient must undergo before having the procedure performed.",
        "rdfs:label": "preparation"
    },
    convertObjectOnlyHaveAtIdToString
); /* ===
    {
        "@id": "http://schema.org/preparation",
        "@type": "rdf:Property",
        "http://schema.org/domainIncludes": "http://schema.org/MedicalProcedure",
        "http://schema.org/isPartOf": "http://health-lifesci.schema.org",
        "http://schema.org/rangeIncludes": [
            "http://schema.org/Text",
            "http://schema.org/MedicalEntity"
        ],
        "rdfs:comment": "Typical preparation that a patient must undergo before having the procedure performed.",
        "rdfs:label": "preparation"
    }
*/