Skip to content

Commit

Permalink
fix: Improve strReplace to remove characters (#259)
Browse files Browse the repository at this point in the history
Co-authored-by: Rafa Avila <107151606+rafa-avila-bc@users.noreply.github.com>
  • Loading branch information
jairo-bc and rafa-avila-bc authored Mar 17, 2023
1 parent 35f6d5b commit 95ae182
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 5 deletions.
1 change: 1 addition & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"node": true,
"es2017": true // suppport globals (like Promise) up to es2017 (es2018 doesn't have new globals)
},
"ignorePatterns": ["dist/**/*"],
"rules": {
"curly": 2,
"no-eq-null": 2,
Expand Down
9 changes: 4 additions & 5 deletions helpers/strReplace.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
'use strict';
const common = require('./lib/common.js');
const utils = require('./3p/utils');
const { ValidationError } = require('../lib/errors');

const factory = globals => {
Expand All @@ -10,11 +9,11 @@ const factory = globals => {
newSubstr = common.unwrapIfSafeString(globals.handlebars, newSubstr);
iteration = common.unwrapIfSafeString(globals.handlebars, iteration);

if (!utils.isString(str)) {
if (typeof str !== 'string') {
throw new ValidationError("Invalid query parameter string passed to strReplace");
} else if (!utils.isString(substr)) {
throw new ValidationError("Invalid query paramter substring passed to strReplace");
} else if (!utils.isString(newSubstr)) {
} else if (typeof substr !== 'string') {
throw new ValidationError("Invalid query parameter substring passed to strReplace");
} else if (typeof newSubstr !== 'string') {
throw new ValidationError("Invalid query parameter new substring passed to strReplace");
}

Expand Down
9 changes: 9 additions & 0 deletions spec/helpers/strReplace.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,15 @@ describe('strReplace helper', function() {
], done);
});

it('should remove characters from string', function(done) {
runTestCases([
{
input: '{{strReplace "123-45-6789" "-" ""}}',
output: '123456789',
},
], done);
});

it('should replace multiple if given quantity', function(done) {
runTestCases([
{
Expand Down

0 comments on commit 95ae182

Please sign in to comment.