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

@campfhir/object-mapper

v3.5.1

Published

This is a utility that helps with object mapping from one data structure to another with declarative instructions.

Readme

Object Mapper

This is a utility that helps with object mapping from one data structure to another with declarative instructions.

APIs

  • Map
  • Compare Objects
  • Coalesce Array Object
  • Add Parameters to SQL Request (requires mssql)
  • SQL Parameter Mapping (requires mssql)
  • SQL Table Parameter Mapping (requires mssql)

Map

This method takes an object and a mapping definition object and returns a new object based on that definition. Can throw an error or array or errors if definition functions throws internally or if options.throwOnFalseValidation is true and the evaluation of validation or pre-validation returns false.

Returns any

| Argument/Parameter | Required | Purpose | Default | | ------------------------------ | -------- | -------------------------------------------------------------------------------------------------------- | ------- | | data | Required | The data to map from, should be an object or array of object | | | map | Required | The mapping definition to determine how to map | | | options.throwOnFalseValidation | Optional | If pre or post-validator is false will throw an error | false | | options.mapNullIfUndefined | Optional | If value is undefined it will cast to null | false | | options.allErrors | Optional | Finish mapping logic before throwing the error on the function level. Will throw an array of all Errors. | false |

Example

import ObjectMapper, { ObjectMap } from "@campfhir/object-mapper"

const data = {
    firstName: "scott",
    lastName: "eremia-roden"
    age: 18
}

const definition: ObjectMap<typeof data> = {
    firstName: {
        name: "fName",
        validator: {
            validate: (firstName) => {
                if (firstName === "scott") return true;
                else if (firstName === "not my name") return false
                else return false
            }
            message: "Name should be scott"
        },
        transformer: (firstName) => {
            return firstName.toUpperCase()
        }
    }
    lastName: false,
    age: "ageInYears"
}

let newData = ObjectMapper.map(data, definition);
console.log(newData.fName) // "SCOTT"
console.log(newData.ageInYears) // 18

Compare Objects

This method is used to compare one object to another.

Returns {status: string; errors: Error[]}

| Arguments/Parameters | Required | Purpose | Default | | ---------------------- | -------- | ---------------------------------------------------------------------------------------------------- | ------- | | lh | Required | The object to compare | | | rh | Required | The object to compare against | | | options.matchDataTypes | optional | Test that the keys in left hand object match and the data type is identical to the right hand object | false | | options.exactValue | optional | Test that the keys and the values in left hand match exactly the data in right hand of the same key | false |

Coalesce Array Object

Given an array of objects we group by like objects and reduce/coalesce to a single object. Returns an object. Throws if group by properties do not have identical elements.

Returns ReverseCoalesce<T,P>

| Arguments/Parameters | Required | Purpose | | -------------------- | -------- | ------------------------------- | | arr | Required | The array of object to coalesce | | groupBy | Required | Array of properties to group by |

Add Parameters to SQL Request

Add array of parameters to mssql Request object

Returns void

| Arguments/Parameters | Required | Purpose | | -------------------- | -------- | -------------------------------------------------- | | params | Required | The array of SQL Parameters to add to the request | | sp | Required | The request that the parameters should be added to |

SQL Parameter Mapping

Given some data and mapping definition to generate an array of parameters, that can later be applied to a mssql Request object.

Returns SQLParameter[]

| Arguments/Parameters | Required | Purpose | Default | | --------------------------------- | -------- | --------------------------------------------------------------------------------------------- | ------- | | input | Required | The data to map against | | | map | Required | A definition on what parameters to create and set | | | mapOptions.throwOnFalseValidation | Optional | If validator evaluates to false and this parameter is set to true the whole method will throw | false | | mapOptions.allErrors | Optional | When true will iterate through the entire map before throwing error from method | false |

SQL Table Parameter Mapping

Given some data and table definition will generate a table variable parameter to be used in a mssql Request object.

Returns mssql.Table

| Arguments/Parameters | Required | Purpose | | --------------------------- | -------- | -------------------------------- | | input | Required | The data used to map against | | tableDefinition | Required | Array of column definitions | | tableDefinition.name | Required | Name of the column | | tableDefinition.option.type | Required | The SQL data type for the column |