Skip to content

Commit

Permalink
fix: 🐛 DEFAULT map array like others transformersx
Browse files Browse the repository at this point in the history
  • Loading branch information
touv committed Jan 19, 2023
1 parent 44bbff2 commit fd3c22c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
9 changes: 8 additions & 1 deletion packages/transformers/src/operations/DEFAULT.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,16 @@
import { rawTransformerWithArg } from './transformer';

const isEmpty = (value) => (String(value).trim() === '' || value === null || value === undefined);


export const defval = (value, alternative) => {
if (Array.isArray(value) && value.length === 0) {
return [alternative];
} else if (value === '' || value === null || value === undefined) {
}
if (Array.isArray(value)) {
return value.map(x => isEmpty(x) ? alternative: x);
}
if (isEmpty(value)) {
return alternative;
}
return value;
Expand Down
4 changes: 4 additions & 0 deletions packages/transformers/src/operations/DEFAULT.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ describe('DEFAULT', () => {
expect(defval([], 'Yo')).toEqual(['Yo']);
});

it('should return filled array with default ', () => {
expect(defval(['', null, undefined, ' '], 'Yo')).toEqual(['Yo', 'Yo', 'Yo', 'Yo']);
});

it('should return value', () => {
expect(defval('Ya', 'Yo')).toEqual('Ya');
});
Expand Down

0 comments on commit fd3c22c

Please sign in to comment.