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

mapez

v1.0.4

Published

Map source object into destination object with ease

Downloads

13

Readme

mapez

Map source object into destination object with ease

Installation

    npm i mapez

or

    yarn add mapez

Usage

ES6

import mapez from "mapez";
const result = mapez(source, spec);

CommonJS

const mapez = require("mapez/dist");
const result = mapez(source, spec);

A spec object key is the destination object key, and the value is selected value of the source object.

Map source object property to destination object property

const source = { foo: 1 };
const spec = {
  bar:
    // select foo value from source
    "foo",
};
const result = mapez(source, spec);
/*
    The result is
    {
        bar: 1
    }
 */

Nested mapping

const source = {
  name: "Box",
  width: 100,
  height: 100,
  category: { name: "Misc" },
};
const spec = {
  name: "name",
  // map category.name to category
  category: "category.name",
  // map width and height to dimension object
  dimension: {
    width: "width",
    height: "height",
  },
};
const result = mapez(source, spec);
/*
    The result is
    {
        name: 'Box',
        category: 'Misc',
        dimension: {
            width: 100,
            height: 100
        }
    }
 */

Using transformer

const source = { foo: 1 };
const spec = {
  visible: () => true,
  bar: (source) => source.foo * 2,
};
const result = mapez(source, spec);
/*
    The result is
    {
        visible: true,
        bar: 2
    }
 */

Using transformer with selectors

const source = { a: 1, b: 2 };
const spec = {
  sum: [
    // select a and b values from source
    "a",
    "b",
    // retrieve a and b values as transformer arguments
    (a, b) => a + b,
  ],
};
const result = mapez(source, spec);
/*
    The result is
    {
        sum: 3
    }
 */

Extending destination object properties

const source = {
  name: "Box",
  dimention: { data: { width: 100, height: 100 } },
  description: {
    data: { shortDescription: "hello", longDescription: "world" },
  },
};
const spec = { name: "name", "*": ["dimension.data", "description.data"] };
const result = mapez(source, spec);
/*
    The result is
    {
        name: 'Box',
        width: 100,
        height: 100,
        shortDescription: 'hello',
        longDescription: 'world'
    }
 */

Syntactic sugar

Selecting source object

"*";

Selecting property

"propertyName";

Selecting nested property

"level1Property.level2Property";

Selecting specified properties

Indicate included properties

"dimension>width|height";
// source: { dimension: { width: 0, height: 0, depth: 0 } }
// value: { width: 0, height: 0 }

Indicate excluded properties

"dimension!width|height";
// source: { dimension: { width: 0, height: 0, depth: 0 } }
// value: { depth: 0 }

Advanced Usage

You can use multiple transformers in a row, the first transformer retrieves all selected values as arguments, the following transformer receives the result of the previous transformer as an argument

const classyGreeting = (firstName, lastName) =>
  "The name's " + lastName + ", " + firstName + " " + lastName;
const toUpper = (string) => string.toUpperCase();
const source = {
  firstName: "James",
  lastName: "Bond",
};
const spec = [
  "firstName",
  "lastName",
  // classyGreeting retrieves firstName and lastName from selectors
  classyGreeting,
  // toUpper retrieves result of classyGreeting
  toUpper,
];
const result = mapez(source, spec);
// result: "THE NAME'S BOND, JAMES BOND"