Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Improve strReplace to remove characters #259

Merged
merged 1 commit into from
Mar 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
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
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