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 🙏

© 2024 – Pkg Stats / Ryan Hefner

jul-data-mapper

v1.1.3

Published

A tool for mapping a JavaScript object from a data schema to another data schema

Downloads

13

Readme

jul-data-mapper

A tool for mapping a JavaScript object from a data schema to another data schema

Install

Install with NPM

npm install --save jul-data-mapper

Usage

mapper.js

Use this tool to map a JavaScript object from a data schema to another data schema

Use with parsed JSON responses or any native JavaScript object structures.

Code example:

'use strict';
const {mapper} = require('jul-data-mapper');

const oSrc = {
server: 'express',
items: [
    {id: 101, name: 'Ana'},
    {id: 102, name: 'Bell'},
    {id: 103, name: 'Kevin'}
],
pref: {perPage: 25, filter: false},
grid: [[1, 2, 3], [4, 5, 6], [7, 8, 9]]
};
const oDest = {version: '1.0.0'};
const oMap = {
'server': 'result.source',
'items[$u].id': 'result.entries[$u].uid',
'items[$u].name': 'result.entries[$u].fullName',
'grid[$i][$j]': 'map[$i][$j].value',
pref: 'result.show'
};

// source -> destination
console.info(
mapper(oDest, oSrc, oMap)
);

// destination -> source
const oReverseMap = Object.fromEntries(Object.entries(oMap).map(aItem =>aItem.reverse()));
console.info(
mapper({}, oDest, oReverseMap)
);

// using a more compact form of mapping
const oCompactMap = {
'server': 'result.source',
'items[$u]': {
    _mapTo: 'result.entries[$u]',
    id: 'uid',
    name: 'fullName'
},
'grid[$i][$j]': 'map[$i][$j].value',
pref: 'result.show'
};
console.info(
mapper({}, oSrc, oCompactMap, {prefixProp: '_mapTo'})
);

Version:

  • 1.1.3

Author:

Source:

API

jul-data-mapper

Converts an object to another using a namespace path mapping.

Isomorphic: works both in backends and in frontends via e.g. webpack

Source:

Methods

compact

(inner) compact(oMap)→ {Object}

Compacts a mapping (key:value) object into a tree-like structure

Parameters:

oMapObject Key-value object to compact

Source:

mapper

(inner) mapper(oDest, oSrc, oMap, oConfigopt)→ {Object}

Performs a mapping with a given object from a data schema to another data schema

Parameters:

oDestObject The destination object where the mapped values are applied over

oSrcObject The source object

oMapObject A key-value hash (mapping) between namespace paths in the source and those in the destination

oConfigObject Optional configuration object with any of the following options:

  • uint {RegExp|String}- regular expression or string to match an array index placeholder e.g. '$n'.

Defaults to /\$[a-z]/

  • prefixProp {String}- name of a property of the mapping the will be used as a prefix when computing the destination namespace for the current siblings.

Defaults to '_mapToPrefix'

  • strict {Boolean}- performs checkings of not overwriting descendant values that are already mapped.

Defaults to false

Source:

License

Licensed under GNU GPLv2 or later and under GNU LGPLv3 or later. See enclosed 'licenses' folder.

About

This utility is based on JUL, which is a set of tools for managing configuration trees.

Resources