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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@teslanick/normalizr

v4.1.0

Published

Normalizes and denormalizes JSON according to schema for Redux and Flux applications

Downloads

271

Readme

normalizr

Normalizes and denormalizes JSON according to schema for Redux and Flux applications.

Install

npm install normalizr

Motivation

Many APIs, public or not, return JSON data that has deeply nested objects. Using data in this kind of structure is often very difficult for JavaScript applications, especially those using Flux or Redux.

Solution

Normalizr is a small, but powerful utility for taking JSON with a schema definition and returning nested entities with their IDs, gathered in dictionaries.

Quick Start

Consider a typical blog post. The API response for a single post might look something like this:

{
  "id": "123",
  "author": {
    "id": "1",
    "name": "Paul"
  },
  "title": "My awesome blog post",
  "comments": [
    {
      "id": "324",
      "commenter": {
        "id": "2",
        "name": "Nicole"
      }
    }
  ]
}

We have two nested entity types within our article: users and comments. Using various schema, we can normalize all three entity types down:

import { normalize, schema } from 'normalizr';

// Define a users schema
const user = new schema.Entity('users');

// Define your comments schema
const comment = new schema.Entity('comments', {
  commenter: user,
});

// Define your article
const article = new schema.Entity('articles', {
  author: user,
  comments: [comment],
});

const normalizedData = normalize(originalData, article);

Now, normalizedData will be:

{
  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" }
    }
  }
}

Denormalization

To convert normalized data back to its nested form, use denormalize:

import { denormalize } from 'normalizr';

const denormalizedArticle = denormalize('123', article, normalizedData.entities);
// Returns the original nested structure

Circular References

Normalizr handles circular references in both schemas and data. When denormalizing, circular references maintain referential equality—the same object instance is returned for the same entity.

import { normalize, denormalize, schema } from 'normalizr';

const user = new schema.Entity('users');
user.define({ friends: [user] });

// Circular data: user references themselves
const input = { id: '1', name: 'Alice', friends: [] };
input.friends.push(input);

const { result, entities } = normalize(input, user);
// entities.users['1'] = { id: '1', name: 'Alice', friends: ['1'] }

const output = denormalize(result, user, entities);
// Referential equality is preserved:
output === output.friends[0]; // true

TypeScript

Normalizr is written in TypeScript and includes comprehensive type definitions. Type utilities like Denormalized<S>, Normalized<S>, and AllEntitiesOf<S> help you infer types from your schemas.

The .as<T>() Method (Recommended)

Use .as<T>() to associate a TypeScript interface with your schema while preserving full type inference for nested schemas:

import { normalize, schema, Denormalized, AllEntitiesOf } from 'normalizr';

interface User {
  id: string;
  name: string;
}

interface Article {
  id: string;
  title: string;
  author: User;
}

// Create schemas with .as<T>() for full type inference
const userSchema = new schema.Entity('users').as<User>();
const articleSchema = new schema.Entity('articles', {
  author: userSchema,
}).as<Article>();

// Type utilities work with full nested type information
type Entities = AllEntitiesOf<typeof articleSchema>;
// { users: Record<string, User>; articles: Record<string, Article> }

Why .as<T>()? TypeScript has a limitation with partial type parameter inference. When you write new schema.Entity<'users', User>('users', { ... }), TypeScript uses the default {} for the unspecified TDefinition parameter instead of inferring it from the constructor argument. This breaks type inference for nested schemas. The .as<T>() method sidesteps this by letting TypeScript infer all parameters first, then narrowing the data type.

Build Files

Normalizr ships with two module formats:

  • ESM (dist/normalizr.js) - ES Modules format, suitable for modern bundlers like Vite, webpack, Rollup, or esbuild. This is the default when using import.
  • CommonJS (dist/normalizr.cjs) - CommonJS format for Node.js and older bundlers. This is the default when using require().

TypeScript declaration files (dist/index.d.ts) are included for full type support.

Documentation

Credits

Normalizr was originally created by Dan Abramov and inspired by a conversation with Jing Chen. Version 3 was a complete rewrite by Paul Armstrong. Version 4 is a TypeScript rewrite by Nicholas Husher.

License

MIT