Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

data-filler

Package Overview
Dependencies
Maintainers
1
Versions
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

data-filler

make your backend response data shape reliable, with data-filler you can stay away from optional chain

  • 1.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

data-filler 🍋

make your backend response data shape reliable, with data-filler you can stay away from optional chain.

Quick Start

install

npm i data-filler
  • example 1
    missed level 1 key filled by template
import { fillDataByTemplate } from 'data-filler';

const data = { a: 1, b: 2 };
const template = { a: 0, b: 0, c: 0, d: [] };
const filled = fillDataByTemplate(data, template);
// filled is: { a: 1, b: 2, c: 0, d: [] }
  • example 2
    fixed incorrect type of key values by template
import { fillDataByTemplate } from 'data-filler';

const data = { a: 1, b: 2, c: { c1: 100 } };
const template = { a: 0, b: 0, c: 0 };
const filled = fillDataByTemplate(data, template);
// filled is: { a: 1, b: 2, c: 0 }
  • example 3
    missed child level key filled by template
import { fillDataByTemplate } from 'data-filler';

const data = { a: 1, b: 2, c: { c1: 100 } };
const template = { a: 0, b: 0, c: { c1: 0, c2: 0, c3: 0 } };
const filled = fillDataByTemplate(data, template);
// filled is: { a: 1, b: 2, c: { c1: 100, c2: 0, c3: 0 } }
  • example 4
    missed array item key filled by template
import { fillDataByTemplate } from 'data-filler';

const data = { a: 1, b: 2, c: [{ c1: 1, c2: 1 }] };
const template = { a: 0, b: 0, c: [] };
const filled = fillDataByTemplate(data, template, { 'c': { c1: 100, c2: 100, c3: 100 } });
// filled is: { a: 1, b: 2, c: [{ c1: 1, c2: 1, c3: 100 }] }

use 3rd param arrItemTemplates to describe array item data shape

  • example 5
    missed child array item key filled by template
import { fillDataByTemplate } from 'data-filler';

const data = { a: 1, b: 2, c: [{ c1: 1, c2: [{ d1: 1 }] }] };
const template = { a: 0, b: 0, c: [] };
const filled = fillDataByTemplate(data, template, {
  'c': { c1: 100, c2: [], c3: 100 },
  'c.c2': { d1: 0, d2: 100 },
});
// filled is: { a: 1, b: 2, c: [{ c1: 1, c2: [{ d1: 1, d2: 100 }], c3: 100 }] }

3rd param arrItemTemplates support key path to describe nested array item data shape

License

concent is released under the MIT License. http://www.opensource.org/licenses/mit-license

Keywords

FAQs

Package last updated on 03 Dec 2021

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc