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

cerealizer

v0.1.3

Published

Serializes data and creates relationships

Downloads

1

Readme

Cerealizer

The purpose of this module is to serialize an array of objects (each containing one or more collection objects) into collection arrays of objects with references to relationships.

Usage

var cerealizer = require('cerealizer');
var data = [
  {
    majors: { id: 1, name: 'Capital' },
    minors: { id: 'a', height: 33 }
  },
  {
    majors: { id: 1, name: 'Capital' },
    minors: { id: 'b', height: 20 }
  },
  {
    majors: { id: 2, name: 'Class' },
    minors: { id: 'b', height: 20 }
  }
];
console.log(cerealizer(data));
// Outputs
// {
//   majors: [
//     { id: 1, name: 'Capital', minorIds: ['a', 'b'] },
//     { id: 2, name: 'Class', minorIds: ['b'] }
//   ],
//   minors: [
//     { id: 'a', height: 33, majorIds: [1] },
//     { id: 'b', height: 20, majorIds: [1, 2] }
//   ]
// }

Description

The serializer runs through a series of operations, which are merging of elements, merging of namespaces, building of relationships, and converting to arrays.

Merging of elements

This operation changes the data from being a single array of objects each containing one or more collection objects into an array for each collection containing all of their respective elements. The options identifier (default is id) is used to only add distinct entities to each collection.

Merging of namespaces

This operation merges collections with the same namespace into a single collection. An example of common usage with MySQL is a table containing two different references to a single table, like a user having both a primary and a secondary group. The collections should then be named something like groups:primary and groups:secondary, which will cause both of them to be merged into the collection groups.

Building of relationships

This operation builds relationships between entities. The options identifier (default is id) is used to find the identified relationship. Relationships are found by using singular collection names combined with the identifier (e.g. groupId for groups). It also handles many-to-many relationships, where the structure would be a collection called userGroups with userId and groupId, which will create a reference to userId and groupId on the corresponding group and user respectively. The userGroups collection will also be passed along.

Converting to arrays

This operation runs through all collections and converts the object containing the entities into an array.

API

cerealizer(array[, options])

Serializes the array of objects into collection arrays of objects with references to relationships.

  • array: Array of objects (each containing one or more collection objects)
  • options (optional):
    • identifier: String or array of identifier keys

Example

cerealizer([
  {
    majors: { id: 1 },
    minors: { id: 2 }
  }
]);
// Outputs
// {
//   majors: [ { id: 1 } ],
//   minors: [ { id: 2 } ]
// }

cerealizer.inflectors

addRule(plural, singular)

Adds a rule to the Inflectors module that will override existing patterns. Rules added are used for both pluralization and singularization.

  • plural: String of the plural form to match (or respond with when singularizing)
  • singular: String of the singular form to match (or respond with when pluralizing)

Example

cerealizer.inflectors.addRule('foo', 'bar');
cerealizer.inflectors.singularize('foo'); //-> bar
cerealizer.inflectors.pluralize('bar'); //-> foo

removeRule(plural)

Removes a rule from the Inflectors module.

  • plural: String of the plural form to remove

Example

cerealizer.inflectors.addRule('foo', 'bar');
cerealizer.inflectors.singularize('foo'); //-> bar
cerealizer.inflectors.removeRule('foo');
cerealizer.inflectors.pluralize('bar'); //-> bars

================

Mmmm.. Cereal

Homer Simpsons