
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
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.
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] }
// ]
// }
The serializer runs through a series of operations, which are merging of elements, merging of namespaces, building of relationships, and converting to arrays.
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.
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.
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.
This operation runs through all collections and converts the object containing the entities into an array.
Serializes the array of objects into collection arrays of objects with references to relationships.
Example
cerealizer([
{
majors: { id: 1 },
minors: { id: 2 }
}
]);
// Outputs
// {
// majors: [ { id: 1 } ],
// minors: [ { id: 2 } ]
// }
Adds a rule to the Inflectors module that will override existing patterns. Rules added are used for both pluralization and singularization.
Example
cerealizer.inflectors.addRule('foo', 'bar');
cerealizer.inflectors.singularize('foo'); //-> bar
cerealizer.inflectors.pluralize('bar'); //-> foo
Removes a rule from the Inflectors module.
Example
cerealizer.inflectors.addRule('foo', 'bar');
cerealizer.inflectors.singularize('foo'); //-> bar
cerealizer.inflectors.removeRule('foo');
cerealizer.inflectors.pluralize('bar'); //-> bars
================
Mmmm.. Cereal

FAQs
Serializes data and creates relationships
We found that cerealizer demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.