1.0.6 • Published 5 years ago

butifl v1.0.6

Weekly downloads
3
License
ISC
Repository
github
Last release
5 years ago

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}
1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago