Skip to content

Commit

Permalink
fix(transformers): non string search value
Browse files Browse the repository at this point in the history
non string search value was not stringified in REPLACE
  • Loading branch information
parmentf committed Jul 23, 2021
1 parent 6f0760e commit fc2edef
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/transformers/src/operations/REPLACE_REGEX.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { transformerWithTwoArgs } from './transformer';

export const replace = (value, searchValue, replaceValue) => {
const template = typeof input === 'string' ? searchValue : searchValue.toString();
const template = typeof searchValue === 'string' ? searchValue : searchValue.toString();
const cleantemplate = template.trim().replace(/^[/]+/, '').replace(/[/]+$/, '');
return value.replace(RegExp(cleantemplate, 'gi'), replaceValue);
};
Expand Down
3 changes: 3 additions & 0 deletions packages/transformers/src/operations/REPLACE_REGEX.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@ describe('REPLACE_REGEX', () => {
it('should return new value from string', () => {
expect(replace('hello world', '\\s*wo\\w+', '')).toBe('hello');
});
it('should return new value from number search value', () => {
expect(replace('1', 1, '2')).toBe('2');
});
});

0 comments on commit fc2edef

Please sign in to comment.