{"id":17680693,"url":"https://github.com/elbywan/normaliz","last_synced_at":"2025-04-15T12:18:50.231Z","repository":{"id":38237974,"uuid":"147118740","full_name":"elbywan/normaliz","owner":"elbywan","description":"A tiny library that normalizes data. :factory:","archived":false,"fork":false,"pushed_at":"2024-09-24T08:04:02.000Z","size":884,"stargazers_count":14,"open_issues_count":1,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-15T12:18:38.619Z","etag":null,"topics":["data","javascript","normalize","schema","tiny-library"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/elbywan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-09-02T20:19:26.000Z","updated_at":"2024-09-24T08:04:03.000Z","dependencies_parsed_at":"2024-06-18T06:56:17.028Z","dependency_job_id":"a1013d43-fdcc-4ab7-abfb-22114c355559","html_url":"https://github.com/elbywan/normaliz","commit_stats":{"total_commits":46,"total_committers":3,"mean_commits":"15.333333333333334","dds":0.5,"last_synced_commit":"c2cace289488eabb04fe4b294c65d77f5d757a7a"},"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbywan%2Fnormaliz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbywan%2Fnormaliz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbywan%2Fnormaliz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/elbywan%2Fnormaliz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/elbywan","download_url":"https://codeload.github.com/elbywan/normaliz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249067787,"owners_count":21207396,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["data","javascript","normalize","schema","tiny-library"],"created_at":"2024-10-24T09:08:38.159Z","updated_at":"2025-04-15T12:18:50.191Z","avatar_url":"https://github.com/elbywan.png","language":"JavaScript","readme":"# normaliz\n\n[![Npm](https://img.shields.io/npm/v/normaliz.svg)](https://www.npmjs.com/package/normaliz)\n[![Build Status](https://travis-ci.org/elbywan/normaliz.svg?branch=master)](https://travis-ci.org/elbywan/normaliz)\n[![Coverage Status](https://coveralls.io/repos/github/elbywan/normaliz/badge.svg?branch=master)](https://coveralls.io/github/elbywan/normaliz?branch=master)\n[![Minzipped size](https://badgen.net/bundlephobia/minzip/normaliz)](https://bundlephobia.com/result?p=normaliz)\n\n## A tiny library that normalizes data according to a schema.\n\n**Inspired by [normalizr](https://github.com/paularmstrong/normalizr) which is a great library. I just needed something more intuitive and lightweight.**\n\n### Features\n\n- 💸 **Lightweight** (~ 800 bytes minzipped)\n\n- 💪 **Simple but powerful and intuitive API**\n\n- ✅ **Battle tested**\n\n### Setup\n\n`npm i normaliz`\n\n### Usage\n\n```js\nimport { normaliz, denormaliz } from 'normaliz'\n\nconst payload = {\n  id: 1,\n  title: 'My Item',\n  post: { id: 4, date: '01-01-1970' },\n  users: [\n    {\n      userId: 1,\n      name: 'john'\n    }, {\n      userId: 2,\n      name: 'jane',\n      comments: [{\n        id: 3,\n        sub_id: 1,\n        content: 'Hello'\n      }]\n    }\n  ]\n}\n// Note: payload can also be an array of items.\n\nconst entities = normaliz(payload, {\n  entity: 'items',\n  schema: [\n    // An 'item' contains:\n    // - a post, stored under the 'posts' key…\n    ['post', { mapping: 'posts' }]\n    // - and a list of users.\n    [ 'users',\n      [\n        // An 'item.user' contains a list of comments.\n        // A comment has a custom id value made with the concatenation of the  'id' and the 'sub_id' fields.\n        [ 'comments', { key: comment =\u003e comment.id + ' - ' + comment.sub_id } ]\n      ],\n      // Use the 'userId' field as the key instead of the default ('id' field).\n      { key: 'userId' }\n    ]\n  ],\n  // If the payload belongs to an existing entity pointed out by its id\n  from: {\n    itemsContainer: 'container_1'\n  }\n})\n\n// Normalized entities:\n\n{\n  items : {\n    1: {\n      id: 1,\n      title: 'My Item',\n      post: 4,\n      users: [ 1, 2 ]\n    }\n  },\n  users: {\n    1: { userId: 1, name: 'john' },\n    2: { userId: 2, name: 'jane', comments: [ '3 - 1' ] }\n  },\n  posts: {\n    4: { id: 4, date: '01-01-1970' }\n  },\n  comments: {\n    '3 - 1': { id: 3, sub_id: 1, content: 'Hello' }\n  },\n  itemsContainer: {\n    container_1: {\n      items: 1\n    }\n  },\n}\n\n// De-normalize an entity\nconst originalData = denormaliz(entities.items[1], {\n  entities,\n  schema: [\n    [ 'post', { mapping: 'posts' }],\n    [ 'users', [ 'comments' ]]\n  ]\n})\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbywan%2Fnormaliz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felbywan%2Fnormaliz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felbywan%2Fnormaliz/lists"}