1.1.3 • Published 3 years ago
sure-assign v1.1.3
Sure ~ assign
Does the same thing as Object.assign
but ensure you to only assign existing properties/fields
Getting started
- Install the package into your node project.
$ npm i sure-assign
- Instenciate :
You will use it as an object
const assigner = new ConsistentAssigner ();
Use it :
const obj_A = { ... }; // A is the base const obj_a = { ... }; // a is subset of A => OK const obj_Ɑ = { ... }; // alfa is superset of A => see complience (*) const result = assigner.assign(obj_A, obj_a, obj_Ɑ); console.log(result); // Outputed object // result : composition of content of theses 3 objects having this relation: // Ɑ <= a <= A
Options
The options help you to generate the result object of your desire and more.
Note : None of these is mandatory. It is just a way to tweak the outcomes and behaviors of the assigner
option | type | default | note |
---|---|---|---|
verbose | boolean | true | |
complient | boolean | true | |
passmiss | boolean | false | |
secure | boolean | true | |
sort | string | "no" | no, asc or dsc |
- Complient
On false, the assigner will
THROW
exception to prevent you to make a bad assignement. - Verbose
Once
false
, it prevents you to have warnings, whencomplient
istrue
. - Passmiss Tells if you take the triggering objects of the assignment in count in the final result.
- Secure
If you set to
false
, the assigner do the same as theObject.assign
funciton. - Sort Offers you the chance to sort the fields or properties of the result object in order ASC, DSC , or NOne of these