Skip to content
Permalink
Branch: master
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
38 lines (28 sloc) 771 Bytes
import { Pipe, PipeTransform } from '@angular/core';
import { isObject, isArray, isNil } from '../utils/utils';
@Pipe({ name: 'defaults' })
export class DefaultsPipe implements PipeTransform {
transform (input: any, defaults: any): any {
if (!isObject(defaults)) {
return input;
}
if (isNil(input)) {
return defaults;
}
if (isArray(input)) {
return input.map((item: any) => {
if (isObject(item)) {
return Object.assign({}, defaults, item);
}
if (isNil(item)) {
return defaults;
}
return item;
});
}
if (isObject(input)) {
return Object.assign({}, defaults, input);
}
return input;
}
}
You can’t perform that action at this time.