Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
data-filler
Advanced tools
make your backend response data shape reliable, with data-filler you can stay away from optional chain
make your backend response data shape reliable, with data-filler you can stay away from optional chain.
install
npm i data-filler
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: [] }
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 }
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 } }
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
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
concent is released under the MIT License. http://www.opensource.org/licenses/mit-license
FAQs
make your backend response data shape reliable, with data-filler you can stay away from optional chain
We found that data-filler demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer 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.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.