Skip to content
This repository was archived by the owner on Feb 23, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Allow null values as pipe parameters
  • Loading branch information
flohw committed Feb 1, 2021
commit 91e48d45beeaec3bcf743b45753cdbfca11e4e5d
15 changes: 15 additions & 0 deletions src/array/merge.pipe.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@ describe('MergePipe', () => {
expect(result).toEqual([1, 2, 3, 4]);
});

it('Should merge with null value', () => {
const result = pipe.transform([1, 2], null);
expect(result).toEqual([1, 2]);
});

it('Should merge on null value', () => {
const result = pipe.transform(null, [1, 2]);
expect(result).toEqual([1, 2]);
});

it('Should merge null values', () => {
const result = pipe.transform(null, null);
expect(result).toEqual([]);
})

it('Should return an empty array', () => {
expect(pipe.transform('a')).toEqual([]);
expect(pipe.transform([], 'a')).toEqual([]);
Expand Down
4 changes: 3 additions & 1 deletion src/array/merge.pipe.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
import { Pipe, PipeTransform, NgModule } from '@angular/core';
import { isArray, isDeepObject, unwrapDeep, deepIndexOf } from '../utils/utils';
import { isArray, isDeepObject, unwrapDeep } from '../utils/utils';

@Pipe({
name: 'merge',
})
export class MergePipe implements PipeTransform {
transform(a?: any, b?: any): any {
a = a === null ? [] : a;
b = b === null ? [] : b;
if ((!isArray(a) && !isDeepObject(a)) || !isArray(b)) {
return [];
}
Expand Down