Skip to content

Commit

Permalink
feat: add arrayify utility function
Browse files Browse the repository at this point in the history
  • Loading branch information
eels committed Oct 28, 2021
1 parent a51489a commit eb1093c
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
3 changes: 3 additions & 0 deletions src/utils/arrayify.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
export default function arrayify(target: any | any[]) {
return Array.isArray(target) ? target : [target];
}
11 changes: 11 additions & 0 deletions test/utils/arrayify.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import arrayify from '@src/utils/arrayify';

describe('utils/arrayify', () => {
it('should convert a non-array to an array', () => {
expect(arrayify('example')).toEqual(['example']);
});

it('should convert a non-array to an array', () => {
expect(arrayify(['example'])).toEqual(['example']);
});
});

0 comments on commit eb1093c

Please sign in to comment.