Skip to content

ManuUseGitHub/sure-assign

Repository files navigation

Sure ~ assign
npm version Build Status License: MIT

INTRO

Does the same thing as Object.assign but ensure you to only assign existing properties/fields. Imagine that you have to merge multiple objects but you do not desire to merge fields that do not exist in the structure of your object (maybe autogenerated). So this little package comes to play nicely.

Get started NPM package

Light demo

const { ConsistentAssigner } = require( "../sure-assign/index.js" );

// TODO : manipulate the service
const assigner = new ConsistentAssigner ();

// Define you objects
const objA = { Hello : "word" , this_ : "is" , something : "that is" , so : "cool" };
const objB = { cool : "world" , but : "yet" , something : "yet" , so : "strict" };
const objC = { so : "strict" };

// Options
const options = { verbose : false , sort : 'asc' };

Either do

// Assign with no options (defaults will be applied)
const newlyAssigned = assigner
    .with(options)
    .assign( objA , objB , objC );

Either

// Assign with the options applied
const newlyAssigned = assigner.assign( objA , objB , objC );

Then consume

console.log( newlyAssigned );

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published