Socket
Socket
Sign inDemoInstall

normal-store

Package Overview
Dependencies
0
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    normal-store

tools for interacting with normalized data structures


Version published
Weekly downloads
44
increased by2.33%
Maintainers
1
Install size
31.7 kB
Created
Weekly downloads
 

Readme

Source

Normal Store

npm version npm downloads

Utilities to transform data with unique identifiers to and from a normalized data store. All data is treated as immutable, new data structures are returned when updating.

Why?

Often when dealing with data in a single-page-application (SPA) it is useful to represent collections of resources in a way that is both easy to query and to update.

With normal-store you can convert the resources served by your backend into a format similar to an indexed database.

const resources = [{ id: 'a' }, { id: 'b' }];

const normalized = normalize(resources); // { allKeys: ['a', 'b'], byKey: { a: { id: 'a' }, b: { id: 'b' } }}

const denormalized = denormalize(normalized); // [{ id: 'a' }, { id: 'b' }]

Example

import axios from 'axios';
import { normalize, getOne, patchOne, removeOne } from 'normal-store';

const products = await axios.get('/products').then(res => res.data);

let productStore = normalize(products);

const decrementStock = (productID) => {
  productStore = patchOne(productStore, productID, ({ stock }) => ({ stock: stock - 1 }));
};

const removeProduct = (productID) => {
  productStore = removeOne(productStore, productID);
};

Installation

To use normal-store, install it as a dependency:

# If you use npm:
npm install normal-store

# Or if you use Yarn:
yarn add normal-store

This assumes that you’re using a package manager such as npm.

License

ISC

Keywords

FAQs

Last updated on 27 Jan 2022

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.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc