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

@trinly01/remap.js

v1.0.3

Published

"JavaScript utility that simplifies data transformation. Remap complex, nested data structures into a more straightforward and user-friendly format. Custom Mapping: Define your own key mapping configuration"

Downloads

20

Readme

Remap.JS Library Documentation

The Remap.JS library is a versatile JavaScript utility that simplifies data transformation, making it suitable for a wide range of use cases like complex data, including nested data, arrays, and objects. You can adapt these concepts to suit various use cases, making the library a valuable tool for data manipulation..

Benefits

  • Data Simplification: Remap complex, nested data structures into a more straightforward and user-friendly format, making it easier to work with and understand.

  • Custom Mapping: Define your own key mapping configuration, giving you full control over which data fields to extract and where to place them in the destination object. The keyMap configuration can be dynamically generated based on user input or system-generated requirements.

  • Iterator Support: Process each mapped item asynchronously with an optional iterator function, making it versatile for various use cases.

Installation

To get started with the Remap library, import it into your JavaScript file:

 npm i @trinly01/remap.js
import { remap, notate } from '@trinly01/remap.js';

Complex Usage Examples

Complex remap Example

Consider a complex data structure with nested objects and arrays:

import { remap } from '@trinly01/remap.js';

const originalSourceData = [
  {
    id: 1,
    name: 'John Doe',
    contact: {
      emails: ['[email protected]', '[email protected]'],
      phones: [
        { type: 'work', number: '123-456-7890' },
        { type: 'personal', number: '098-765-4321' },
      ],
    },
    addresses: [
      { type: 'home', location: '123 Main St, Apt 101' },
      { type: 'work', location: '456 Business St, Suite 200' },
    ],
  },
  // Additional source data objects here
];

const keyMap = {
  'Profile.id': 'id',
  'Profile.name': 'name',
  'Profile.emails[0]': 'contact.emails.0',
  'Profile.emails[1]': 'contact.emails.1',
  'Profile.workPhone': 'contact.phones[0].number',
  'Profile.homeAddress': 'addresses[0].location',
  'Profile.workAddress': 'addresses[1].location',
};

const transformedData = remap(originalSourceData, keyMap);

console.log(transformedData);

In this complex remap example, we're extracting various data fields from a nested data structure. The resulting transformed data will have a flattened structure.

Complex notate Example

Now, let's use the notate function to create complex objects with specific key notations:

import { notate } from '@trinly01/remap.js';

const result = {};

notate('Profile.id', 1, result);
notate('Profile.name', 'John Doe', result);

// Nested objects and arrays
notate('Profile.emails[0]', '[email protected]', result);
notate('Profile.emails[1]', '[email protected]', result);
notate('Profile.contact.phones[0].type', 'work', result);
notate('Profile.contact.phones[0].number', '123-456-7890', result);
notate('Profile.contact.phones[1].type', 'personal', result);
notate('Profile.contact.phones[1].number', '098-765-4321', result);
notate('Profile.addresses[0].type', 'home', result);
notate('Profile.addresses[0].location', '123 Main St, Apt 101', result);
notate('Profile.addresses[1].type', 'work', result);
notate('Profile.addresses[1].location', '456 Business St, Suite 200', result);

console.log(result);

This notate example demonstrates creating a complex object structure with nested objects and arrays, allowing precise control over the resulting data structure.

Functions

remap Function Parameters

The remap function transforms an array of objects into a new array with the mapped data according to the specified key mapping.

| Parameter | Type | Description | |--------------|------|-------------------------------------------------------------------------------------| | arr | Array | The array of source objects to remap. | | keyMap | Object | The key mapping configuration defining how to map the source data to the destination object. This configuration can be dynamically generated based on user input or system-generated requirements. | | iterator | Function (Optional) | An asynchronous function for processing each mapped item. |

notate Function Parameters

The notate function is used to create and assign values to objects with a specific key notation. It's highly flexible and adaptable for various use cases.

| Parameter | Type | Description | |--------------|------|-------------------------------------------------------------------------------------| | notation | Object or String | The key notation in the destination object. If it's an object, you can set multiple values at once. If it's a single path notation (string), the value parameter is required. | | value | Any | The value to assign to the destination object. Required when notation is a single path notation (string). | | result | (Optional) The result object where the data will be assigned. If provided, the assigned data will be stored in this object. |

These two separate markdown tables provide a clear and structured overview of the parameter information for the remap and notate functions without the "Default" column.