Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
Normalizr is a powerful library for normalizing nested JSON data. It helps in transforming complex nested data structures into a flat structure, making it easier to manage and work with in applications, especially in state management scenarios.
Define Schemas
Normalizr allows you to define schemas for your data. In this example, we define schemas for users, comments, and articles, where comments have a relationship with users, and articles have relationships with both users and comments.
const { schema } = require('normalizr');
const user = new schema.Entity('users');
const comment = new schema.Entity('comments', {
commenter: user
});
const article = new schema.Entity('articles', {
author: user,
comments: [comment]
});
Normalize Data
Once schemas are defined, you can use the `normalize` function to transform your nested data into a normalized form. This example shows how to normalize a nested JSON object representing an article with an author and comments.
const { normalize } = require('normalizr');
const originalData = {
id: '123',
author: {
id: '1',
name: 'Paul'
},
title: 'My awesome blog post',
comments: [
{
id: '324',
commenter: {
id: '2',
name: 'Nicole'
}
}
]
};
const normalizedData = normalize(originalData, article);
console.log(JSON.stringify(normalizedData, null, 2));
Denormalize Data
Normalizr also provides a `denormalize` function to convert normalized data back into its original nested form. This example demonstrates how to denormalize data using the previously defined schemas.
const { denormalize } = require('normalizr');
const normalizedData = {
result: '123',
entities: {
articles: {
'123': { id: '123', author: '1', title: 'My awesome blog post', comments: ['324'] }
},
users: {
'1': { id: '1', name: 'Paul' },
'2': { id: '2', name: 'Nicole' }
},
comments: {
'324': { id: '324', commenter: '2' }
}
}
};
const denormalizedData = denormalize('123', article, normalizedData.entities);
console.log(JSON.stringify(denormalizedData, null, 2));
normalizr-immutable is a fork of normalizr that works with Immutable.js data structures. It provides similar functionality to normalizr but is designed to work seamlessly with Immutable.js, making it a good choice for applications that use Immutable.js for state management.
redux-orm is a library for managing relational data in Redux. It provides an ORM-like interface for defining models and relationships, and it integrates with Redux to manage normalized data. Unlike normalizr, which focuses on normalization and denormalization, redux-orm provides a more comprehensive solution for managing relational data in Redux applications.
Due to lack of ability to find an invested maintainer and inability to find time to do routine maintenance and community building, this package is no longer maintained. Please see the discussion 🤝 Maintainer help wanted for more information.
If you need it, yes. Normalizr is and has been at a stable release for a very long time, used by thousands of others without issue.
Fork Normalizr on Github and maintain a version yourself.
There are no current plans to resurrect this origin of Normalizr. If a forked version becomes sufficiently maintained and popular, please reach out about merging the fork and changing maintainers.
FAQs
Normalizes and denormalizes JSON according to schema for Redux and Flux applications
We found that normalizr demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 2 open source maintainers 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.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.