Skip to content

Strongly Typed Utilities for Javascript and Typescript

Notifications You must be signed in to change notification settings

hasahmed/butifl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Butifl

Strongly Typed Typescript Utility Library

.assignExisting

static assignExisting<T, U>(target: T, source: U, skipNullAndUndefined: boolean=true): T;

Basic usage is exactly like Object.assign except it only copies properties from source that already exist on target. When skipNullAndUndefiend is true then source properties that are null or undefined will not be copied into target

Basic Usage

class A {
	a: number = 0;
	b: number = 5;
}

let obj = {
	a: 10,
	b: 100,
	c: 1000
};
let aInst = Butifl.assignExisting(new A(), obj);
console.log(aInst); // {a: 10, b: 100}

Skipping or not skipping undefined properties

class A {
	a: number = 0;
	b: number = 5;
	c: number = 100
	d: number = 1;
}
let obj = {
	a: 10,
	b: 100,
	c: undefined,
	d: null
};
let aSkipUndefined = Butifl.assignExisting(new A(), obj);
console.log(aSkipUndefined); // {a: 10, b: 100, c: 100, d: 1}
let aTakeUndefined = Butifl.assignExisting(new A(), obj, false);
console.log(aTakeUndefined); // {a: 10, b: 100, c: undefined, d: null}

About

Strongly Typed Utilities for Javascript and Typescript

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published