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

easy-normalizer

v1.0.5

Published

plugin for normalize and custom sort your array and objects in simplest way

Downloads

4

Readme

easy-normalizer

about

easy-normalizer uses a simple approach to return deeply nested entities with their ids.

Each entity is assumed to have a unique ID value.

The plugin allows you to sort alphabetically, numerically, and by month

The structure of the return data will be as follows:

{
    ids         : [],
    entities    : {}
}

documentation

installation

npm :

  npm install easy-normalizer

cdn :

<link href="https://cdn.jsdelivr.net/npm/easy-normalizer/dist/index.js" rel="stylesheet" crossorigin="anonymous" />

usage

to start using easy-noramlizer we need to:

  1. import EN from easy-normalizer plugin
  2. in set_config method choose your json parsed data in iterator key
  3. in set_config method choose your nested entity to find and extract
  4. with run method get your normalized data
import { EN } from "easy-normalizer";
EN.set_config({
  iterator      : iterator, //<your json to iterate>,
  key           : key       //<name of your key to find>
});

const result = EN.run();

note: Every entity must have a unique ID for this plugin to work, otherwise new items will overwrite old ones

note 2: Your Key must have unique id to seperate in this format

set parent id

In order to have parent id keys in every entity found with your custom name key, set parent_id_key in the configuration object

EN.set_config({
  parent_id_key  : 'user_id' //<name of parent id>
});

note: In this configuration, the parent entity must have a unique ID

sort

sort by alphabet

If you want to sort entities by alphabet, you should set your key to compare, language of alphabet, and isSort to true

EN.set_config({  
  sort          : {
    isSort       : true,
    keyToCompare : 'comments', //<name of key to compare>,
    lang         : 'en'        //<ISO 639-1 of language>,`  
  }
});

sort by number

Your key_to_compare will automatically sort by number if all values are numeric

sort by month

Your key_to_compare you should set strictSort to 'month' then it will be sort by month if all values are month name in accordance with lang key

EN.set_config({
  sort          : {
    isSort       : true,
    keyToCompare : 'articles', //<name of key to compare>
    lang         : 'fa',       //<ISO 639-1 of language>
    strictSort   : 'month'
  }
});

reverse

If the sorted entities are reverse from what you want, set reverse to true

EN.set_config({
  sort          : {
    reverse       : true,
  }
});

example

EN.set_config({
  iterator      : users,
  key           : 'comments',
  parent_id_key : 'user_id',
  sort          : {
    isSort       : true,
    keyToCompare : 'subject',
    lang         : 'en',
    reverse      : true,
  }
});

const result = EN.run();

add, update or remove entity

you can use these following method to modify your normalizedData object

  //add
  EN.addToNormalizedData(normalizedData, newData);

  //update
  EN.updateNormalizedData(normalizedData, newData);

  //remove
  EN.removeNormalizedData(normalizedData, data)

note: for each above method newData and data shoud have unique id