From 340b34b278735433ee33738e52f7eba2cdbddcf1 Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Mon, 7 Feb 2022 10:15:21 -0500 Subject: [PATCH 01/12] Rename string replace and put in helpers --- helpers.js | 1 + helpers/strReplace.js | 25 +++++++++++++++++++ spec/helpers.js | 1 + spec/helpers/strReplace.js | 51 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 78 insertions(+) create mode 100644 helpers/strReplace.js create mode 100644 spec/helpers/strReplace.js diff --git a/helpers.js b/helpers.js index 78cd1ba..f8c725a 100644 --- a/helpers.js +++ b/helpers.js @@ -44,6 +44,7 @@ const helpersList = [ 'setURLQueryParam', 'snippets', 'stripQuerystring', + 'strReplace', 'stylesheet', 'thirdParty', 'toLowerCase', diff --git a/helpers/strReplace.js b/helpers/strReplace.js new file mode 100644 index 0000000..73adba5 --- /dev/null +++ b/helpers/strReplace.js @@ -0,0 +1,25 @@ +'use strict'; + +const factory = () => { + return function(string, substr, newSubstr, token) { + if (typeof string !== 'string' || typeof substr !== 'string' || typeof newSubstr !== 'string') { + return 'Invalid Input'; + } + + if (token && typeof token === 'string') { + return string.replace(new RegExp(escapeRegex(substr), token), newSubstr); + } else { + return string.replace(new RegExp(escapeRegex(substr), 'g'), newSubstr); + } + + }; +}; + +function escapeRegex(string) { + return string.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"); +} + +module.exports = [{ + name: 'strReplace', + factory: factory, +}]; diff --git a/spec/helpers.js b/spec/helpers.js index deb2683..b3e24c6 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -63,6 +63,7 @@ describe('helper registration', () => { 'setURLQueryParam', 'snippet', 'stripQuerystring', + 'strReplace', 'stylesheet', 'after', 'arrayify', diff --git a/spec/helpers/strReplace.js b/spec/helpers/strReplace.js new file mode 100644 index 0000000..4a467f5 --- /dev/null +++ b/spec/helpers/strReplace.js @@ -0,0 +1,51 @@ +const Lab = require('lab'), + lab = exports.lab = Lab.script(), + describe = lab.experiment, + it = lab.it, + testRunner = require('../spec-helpers').testRunner; + +describe('strReplace helper', function() { + const context = { + string: "My name is Albe Albe Albe", + substr: "Albe", + newSubstr: "Alex", + object: {} + }; + + const runTestCases = testRunner({context}); + + it('should replace all by default', function(done) { + runTestCases([ + { + input: '{{strReplace string substr newSubstr}}', + output: 'My name is Alex Alex Alex', + }, + { + input: '{{strReplace "Your name is none" "none" "Bob"}}', + output: 'Your name is Bob', + }, + ], done); + }); + + it('should replace one if given token', function(done) { + runTestCases([ + { + input: '{{strReplace string substr newSubstr "i"}}', + output: 'My name is Alex Albe Albe', + }, + ], done); + }); + + it('should only handle string', function(done) { + runTestCases([ + { + input: '{{strReplace 5 5 5}}', + output: 'Invalid Input', + }, + { + input: '{{strReplace object "none" "Bob"}}', + output: 'Invalid Input', + }, + ], done); + }); +}); From 7df11ad467193fd95cad8a615c20e62066bebc00 Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Tue, 8 Feb 2022 12:55:50 -0500 Subject: [PATCH 02/12] Update String Replace input options --- helpers/strReplace.js | 30 ++++++++++++++++++++++++------ spec/helpers/strReplace.js | 22 +++++++++++++++++++--- 2 files changed, 43 insertions(+), 9 deletions(-) diff --git a/helpers/strReplace.js b/helpers/strReplace.js index 73adba5..92e87a4 100644 --- a/helpers/strReplace.js +++ b/helpers/strReplace.js @@ -1,17 +1,30 @@ 'use strict'; const factory = () => { - return function(string, substr, newSubstr, token) { - if (typeof string !== 'string' || typeof substr !== 'string' || typeof newSubstr !== 'string') { + return function(str, substr, newSubstr, iteration) { + if (typeof str !== 'string' || typeof substr !== 'string' || typeof newSubstr !== 'string') { return 'Invalid Input'; } - if (token && typeof token === 'string') { - return string.replace(new RegExp(escapeRegex(substr), token), newSubstr); - } else { - return string.replace(new RegExp(escapeRegex(substr), 'g'), newSubstr); + if (typeof iteration !== 'number') { + return str.replace(new RegExp(escapeRegex(substr), 'g'), newSubstr); } + const occurrence = getOccurrences(str, substr); + + if (iteration > 0 && occurrence > 0) { + if (iteration >= occurrence) { + return str.replace(new RegExp(escapeRegex(substr), 'g'), newSubstr); + } else { + let result = str; + for (let i = 0; i < iteration; i++) { + result = result.replace(substr, newSubstr); + } + return result; + } + } else { + return str; + } }; }; @@ -19,6 +32,11 @@ function escapeRegex(string) { return string.replace(/[-\\^$*+?.()|[\]{}]/g, "\\$&"); } +function getOccurrences(str, substr) { + const matches = str.match(new RegExp(escapeRegex(substr),'g')); + return matches ? matches.length : 0; +} + module.exports = [{ name: 'strReplace', factory: factory, diff --git a/spec/helpers/strReplace.js b/spec/helpers/strReplace.js index 4a467f5..38bf4fc 100644 --- a/spec/helpers/strReplace.js +++ b/spec/helpers/strReplace.js @@ -27,11 +27,27 @@ describe('strReplace helper', function() { ], done); }); - it('should replace one if given token', function(done) { + it('should replace multiple if given quantity', function(done) { runTestCases([ { - input: '{{strReplace string substr newSubstr "i"}}', - output: 'My name is Alex Albe Albe', + input: '{{strReplace string substr newSubstr -5}}', + output: 'My name is Albe Albe Albe', + }, + { + input: '{{strReplace string substr newSubstr 0}}', + output: 'My name is Albe Albe Albe', + }, + { + input: '{{strReplace string substr newSubstr 2}}', + output: 'My name is Alex Alex Albe', + }, + { + input: '{{strReplace string substr newSubstr 4}}', + output: 'My name is Alex Alex Alex', + }, + { + input: '{{strReplace string substr newSubstr 100}}', + output: 'My name is Alex Alex Alex', }, ], done); }); From 6b2867f64d408d860e1eaa5035ffbf556a308db2 Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Tue, 15 Feb 2022 09:34:56 -0500 Subject: [PATCH 03/12] Update input type checking method --- helpers/strReplace.js | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/helpers/strReplace.js b/helpers/strReplace.js index 92e87a4..cd8c553 100644 --- a/helpers/strReplace.js +++ b/helpers/strReplace.js @@ -1,9 +1,20 @@ 'use strict'; +const common = require('./lib/common.js'); +const utils = require('handlebars-utils'); -const factory = () => { +const factory = globals => { return function(str, substr, newSubstr, iteration) { - if (typeof str !== 'string' || typeof substr !== 'string' || typeof newSubstr !== 'string') { - return 'Invalid Input'; + str = common.unwrapIfSafeString(globals.handlebars, str); + substr = common.unwrapIfSafeString(globals.handlebars, substr); + newSubstr = common.unwrapIfSafeString(globals.handlebars, newSubstr); + iteration = common.unwrapIfSafeString(globals.handlebars, iteration); + + if (!utils.isString(str)){ + throw new TypeError("Invalid query parameter string passed to strReplace"); + } else if (!utils.isString(substr)){ + throw new TypeError("Invalid query paramter substring passed to strReplace"); + } else if(!utils.isString(newSubstr)) { + throw new TypeError("Invalid query parameter new substring passed to strReplace"); } if (typeof iteration !== 'number') { From fd1a41a4868b087dfba9c7496652a9f631bf4b8e Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Wed, 16 Feb 2022 15:03:27 -0500 Subject: [PATCH 04/12] Update string replace test cases to handle error --- spec/helpers/strReplace.js | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/spec/helpers/strReplace.js b/spec/helpers/strReplace.js index 38bf4fc..f273e0f 100644 --- a/spec/helpers/strReplace.js +++ b/spec/helpers/strReplace.js @@ -2,7 +2,9 @@ const Lab = require('lab'), lab = exports.lab = Lab.script(), describe = lab.experiment, it = lab.it, - testRunner = require('../spec-helpers').testRunner; + specHelpers = require('../spec-helpers'), + testRunner = require('../spec-helpers').testRunner, + renderString = specHelpers.renderString;; describe('strReplace helper', function() { const context = { @@ -53,15 +55,14 @@ describe('strReplace helper', function() { }); it('should only handle string', function(done) { - runTestCases([ - { - input: '{{strReplace 5 5 5}}', - output: 'Invalid Input', - }, - { - input: '{{strReplace object "none" "Bob"}}', - output: 'Invalid Input', - }, - ], done); + renderString('{{strReplace object "none" "Bob"}}').catch(e => { + renderString('{{strReplace "none" 3 "Bob"}}').catch(e => { + renderString('{{strReplace "none" "Bob" object}}').catch(e => { + renderString('{{strReplace string substr newSubstr "3"}}').catch(e => { + done(); + }); + }); + }); + }); }); }); From 71c63edd44c8ae980e9d9a85e8ab0c8dcb2eee24 Mon Sep 17 00:00:00 2001 From: Alex Shi Date: Wed, 23 Feb 2022 10:00:52 -0500 Subject: [PATCH 05/12] Update throw error message --- spec/helpers/strReplace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/strReplace.js b/spec/helpers/strReplace.js index f273e0f..aad779c 100644 --- a/spec/helpers/strReplace.js +++ b/spec/helpers/strReplace.js @@ -54,7 +54,7 @@ describe('strReplace helper', function() { ], done); }); - it('should only handle string', function(done) { + it('should throw error if parameters have invalid type', function(done) { renderString('{{strReplace object "none" "Bob"}}').catch(e => { renderString('{{strReplace "none" 3 "Bob"}}').catch(e => { renderString('{{strReplace "none" "Bob" object}}').catch(e => { From e95ce8cbfe0a1551b57257094f751f86b54b6577 Mon Sep 17 00:00:00 2001 From: Jared Yap Date: Wed, 23 Feb 2022 09:15:06 -0800 Subject: [PATCH 06/12] updated phrasing of error --- spec/helpers/strReplace.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/helpers/strReplace.js b/spec/helpers/strReplace.js index aad779c..142190d 100644 --- a/spec/helpers/strReplace.js +++ b/spec/helpers/strReplace.js @@ -54,7 +54,7 @@ describe('strReplace helper', function() { ], done); }); - it('should throw error if parameters have invalid type', function(done) { + it('should throw an exception if the parameters have an invalid type', function(done) { renderString('{{strReplace object "none" "Bob"}}').catch(e => { renderString('{{strReplace "none" 3 "Bob"}}').catch(e => { renderString('{{strReplace "none" "Bob" object}}').catch(e => { From 06014e3d2dc9953cc63df379231be87efe2a97c8 Mon Sep 17 00:00:00 2001 From: Julia Chen Date: Thu, 29 Dec 2022 17:48:25 -0500 Subject: [PATCH 07/12] multiConcat test and function --- helpers.js | 1 + helpers/multiConcat.js | 45 ++++++++++++++++++++++++++ spec/helpers.js | 1 + spec/helpers/multiConcat.js | 64 +++++++++++++++++++++++++++++++++++++ 4 files changed, 111 insertions(+) create mode 100644 helpers/multiConcat.js create mode 100644 spec/helpers/multiConcat.js diff --git a/helpers.js b/helpers.js index f8c725a..5536e86 100644 --- a/helpers.js +++ b/helpers.js @@ -32,6 +32,7 @@ const helpersList = [ 'langJson', 'limit', 'money', + 'multiConcat', 'nl2br', 'occurrences', 'or', diff --git a/helpers/multiConcat.js b/helpers/multiConcat.js new file mode 100644 index 0000000..73136b3 --- /dev/null +++ b/helpers/multiConcat.js @@ -0,0 +1,45 @@ +'use strict'; +const common = require('./lib/common.js'); +const utils = require('handlebars-utils'); + +/** + * Concats multi values, primarily used as a subhelper + * @example + * {{multiConcat "string1" "string2" "string3"}} + */ + + +const factory = globals => { + return function(...args) { + // str = common.unwrapIfSafeString(globals.handlebars, str); + + args.forEach(element => { + const substr = common.unwrapIfSafeString(globals.handlebars, element); + if (!utils.isString(substr)){ + throw new TypeError("Invalid query parameter string passed to multiConcat"); + } + }); + + // args.forEach(element => { + // const substr= new globals.handlebars.SafeString(element); + // if (!utils.isString(substr)) { + // throw new TypeError("multiConcat parameters must be string"); + // } + // }); + + // _.every(args, function (arg) { + // if (!utils.isString(arg)) { + // throw new TypeError("multiConcat parameters must be string"); + // } + // }); + + return args.join(''); + }; + +}; + + +module.exports = [{ + name: 'multiConcat', + factory: factory, +}]; diff --git a/spec/helpers.js b/spec/helpers.js index b3e24c6..e7a8feb 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -77,6 +77,7 @@ describe('helper registration', () => { 'last', 'lengthEqual', 'map', + 'multiConcat', 'some', 'sort', 'sortBy', diff --git a/spec/helpers/multiConcat.js b/spec/helpers/multiConcat.js new file mode 100644 index 0000000..328bb43 --- /dev/null +++ b/spec/helpers/multiConcat.js @@ -0,0 +1,64 @@ +const Lab = require('lab'), + lab = exports.lab = Lab.script(), + describe = lab.experiment, + it = lab.it, + // specHelpers = require('../spec-helpers'), + testRunner = require('../spec-helpers').testRunner; + // renderString = specHelpers.renderString; + + +describe('multiConcat helper', function() { + const context = { + string: "First", + string2: "Second", + string3: "Third" + }; + + const runTestCases = testRunner({context}); + + it('should concat all string by default', function(done) { + runTestCases([ + { + input: '{{multiConcat string string2 string3}}', + output: 'FirstSecondThird', + } + ], done); + }); + + // it('should replace multiple if given quantity', function(done) { + // runTestCases([ + // { + // input: '{{multiConcat string string2 string3 -5}}', + // output: 'My name is Albe Albe Albe', + // }, + // { + // input: '{{multiConcat string string2 string3 0}}', + // output: 'My name is Albe Albe Albe', + // }, + // { + // input: '{{multiConcat string string2 string3 2}}', + // output: 'My name is Alex Alex Albe', + // }, + // { + // input: '{{multiConcat string string2 string3 4}}', + // output: 'My name is Alex Alex Alex', + // }, + // { + // input: '{{multiConcat string string2 string3 100}}', + // output: 'My name is Alex Alex Alex', + // }, + // ], done); + // }); + + // it('should throw an exception if the parameters have an invalid type', function(done) { + // renderString('{{multiConcat object "none" "Bob"}}').catch(e => { + // renderString('{{multiConcat "none" 3 "Bob"}}').catch(e => { + // renderString('{{multiConcat "none" "Bob" object}}').catch(e => { + // renderString('{{multiConcat string string2 string3 "3"}}').catch(e => { + // done(); + // }); + // }); + // }); + // }); + // }); +}); From bb9a597d911ed721279e693487cfb16e037d9d9a Mon Sep 17 00:00:00 2001 From: Matthew Coy Date: Thu, 5 Jan 2023 10:05:02 -0800 Subject: [PATCH 08/12] clean up test --- spec/helpers/multiConcat.js | 45 +++---------------------------------- 1 file changed, 3 insertions(+), 42 deletions(-) diff --git a/spec/helpers/multiConcat.js b/spec/helpers/multiConcat.js index 328bb43..3fa149f 100644 --- a/spec/helpers/multiConcat.js +++ b/spec/helpers/multiConcat.js @@ -2,63 +2,24 @@ const Lab = require('lab'), lab = exports.lab = Lab.script(), describe = lab.experiment, it = lab.it, - // specHelpers = require('../spec-helpers'), testRunner = require('../spec-helpers').testRunner; - // renderString = specHelpers.renderString; describe('multiConcat helper', function() { const context = { - string: "First", + string1: "First", string2: "Second", string3: "Third" }; const runTestCases = testRunner({context}); - it('should concat all string by default', function(done) { + it('should concatenate all strings by default', function(done) { runTestCases([ { - input: '{{multiConcat string string2 string3}}', + input: '{{multiConcat string1 string2 string3}}', output: 'FirstSecondThird', } ], done); }); - - // it('should replace multiple if given quantity', function(done) { - // runTestCases([ - // { - // input: '{{multiConcat string string2 string3 -5}}', - // output: 'My name is Albe Albe Albe', - // }, - // { - // input: '{{multiConcat string string2 string3 0}}', - // output: 'My name is Albe Albe Albe', - // }, - // { - // input: '{{multiConcat string string2 string3 2}}', - // output: 'My name is Alex Alex Albe', - // }, - // { - // input: '{{multiConcat string string2 string3 4}}', - // output: 'My name is Alex Alex Alex', - // }, - // { - // input: '{{multiConcat string string2 string3 100}}', - // output: 'My name is Alex Alex Alex', - // }, - // ], done); - // }); - - // it('should throw an exception if the parameters have an invalid type', function(done) { - // renderString('{{multiConcat object "none" "Bob"}}').catch(e => { - // renderString('{{multiConcat "none" 3 "Bob"}}').catch(e => { - // renderString('{{multiConcat "none" "Bob" object}}').catch(e => { - // renderString('{{multiConcat string string2 string3 "3"}}').catch(e => { - // done(); - // }); - // }); - // }); - // }); - // }); }); From cdebde9ef5cb9e0b0d92af478051f68e3bc6af71 Mon Sep 17 00:00:00 2001 From: Julia Chen Date: Wed, 18 Jan 2023 14:41:53 -0500 Subject: [PATCH 09/12] update args function --- helpers/multiConcat.js | 36 ++++++++++++++++++------------------ spec/helpers.js | 2 +- 2 files changed, 19 insertions(+), 19 deletions(-) diff --git a/helpers/multiConcat.js b/helpers/multiConcat.js index 73136b3..3547e8e 100644 --- a/helpers/multiConcat.js +++ b/helpers/multiConcat.js @@ -1,4 +1,5 @@ 'use strict'; +const _ = require('lodash'); const common = require('./lib/common.js'); const utils = require('handlebars-utils'); @@ -11,29 +12,28 @@ const utils = require('handlebars-utils'); const factory = globals => { return function(...args) { - // str = common.unwrapIfSafeString(globals.handlebars, str); + // Take the last arg which is a Handlebars options object out of args array + args.pop(); - args.forEach(element => { - const substr = common.unwrapIfSafeString(globals.handlebars, element); - if (!utils.isString(substr)){ - throw new TypeError("Invalid query parameter string passed to multiConcat"); + // Check if all the args are valid / truthy + const result = _.every(args, function (arg) { + if (utils.isArray(arg)) { + return !!arg.length; + } + // If an empty object is passed, arg is false + else if (utils.isEmpty(arg) && utils.isObject(arg)) { + return false; + } + // Everything else + else { + return !!arg; } }); - // args.forEach(element => { - // const substr= new globals.handlebars.SafeString(element); - // if (!utils.isString(substr)) { - // throw new TypeError("multiConcat parameters must be string"); - // } - // }); - - // _.every(args, function (arg) { - // if (!utils.isString(arg)) { - // throw new TypeError("multiConcat parameters must be string"); - // } - // }); + if (result) { + return args.join(''); + } - return args.join(''); }; }; diff --git a/spec/helpers.js b/spec/helpers.js index e7a8feb..721592d 100644 --- a/spec/helpers.js +++ b/spec/helpers.js @@ -51,6 +51,7 @@ describe('helper registration', () => { 'langJson', 'limit', 'money', + 'multiConcat', 'nl2br', 'occurrences', 'or', @@ -77,7 +78,6 @@ describe('helper registration', () => { 'last', 'lengthEqual', 'map', - 'multiConcat', 'some', 'sort', 'sortBy', From 329fbb73d5cfa963b6735047205fdacffb22b91a Mon Sep 17 00:00:00 2001 From: Julia Chen Date: Fri, 20 Jan 2023 17:49:57 -0500 Subject: [PATCH 10/12] remove validate since join could accept all types of data --- helpers/multiConcat.js | 23 +---------------------- spec/helpers/multiConcat.js | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 23 deletions(-) diff --git a/helpers/multiConcat.js b/helpers/multiConcat.js index 3547e8e..7ef91ee 100644 --- a/helpers/multiConcat.js +++ b/helpers/multiConcat.js @@ -1,7 +1,4 @@ 'use strict'; -const _ = require('lodash'); -const common = require('./lib/common.js'); -const utils = require('handlebars-utils'); /** * Concats multi values, primarily used as a subhelper @@ -15,25 +12,7 @@ const factory = globals => { // Take the last arg which is a Handlebars options object out of args array args.pop(); - // Check if all the args are valid / truthy - const result = _.every(args, function (arg) { - if (utils.isArray(arg)) { - return !!arg.length; - } - // If an empty object is passed, arg is false - else if (utils.isEmpty(arg) && utils.isObject(arg)) { - return false; - } - // Everything else - else { - return !!arg; - } - }); - - if (result) { - return args.join(''); - } - + return args.join(''); }; }; diff --git a/spec/helpers/multiConcat.js b/spec/helpers/multiConcat.js index 3fa149f..84e8027 100644 --- a/spec/helpers/multiConcat.js +++ b/spec/helpers/multiConcat.js @@ -9,7 +9,8 @@ describe('multiConcat helper', function() { const context = { string1: "First", string2: "Second", - string3: "Third" + string3: "Third", + string4: "Fourth" }; const runTestCases = testRunner({context}); @@ -19,6 +20,27 @@ describe('multiConcat helper', function() { { input: '{{multiConcat string1 string2 string3}}', output: 'FirstSecondThird', + }, + { + input: '{{multiConcat string1 string2 string3 string4}}', + output: 'FirstSecondThirdFourth', + } + ], done); + }); + + it('should accept string, number, boolean, empty', function(done) { + runTestCases([ + { + input: '{{multiConcat "First" 2}}', + output: 'First2', + }, + { + input: '{{multiConcat string1 3 "" "4" true}}', + output: 'First34true', + }, + { + input: '{{multiConcat string1 3 false "" "4" true}}', + output: 'First3false4true', } ], done); }); From ef37d109e61c53096803f4f0b16569f3762daa86 Mon Sep 17 00:00:00 2001 From: Julia Chen Date: Fri, 20 Jan 2023 18:03:56 -0500 Subject: [PATCH 11/12] add more test case --- spec/helpers/multiConcat.js | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/spec/helpers/multiConcat.js b/spec/helpers/multiConcat.js index 84e8027..e91c043 100644 --- a/spec/helpers/multiConcat.js +++ b/spec/helpers/multiConcat.js @@ -24,6 +24,10 @@ describe('multiConcat helper', function() { { input: '{{multiConcat string1 string2 string3 string4}}', output: 'FirstSecondThirdFourth', + }, + { + input: '{{multiConcat string1 string2}}', + output: 'FirstSecond', } ], done); }); @@ -41,6 +45,10 @@ describe('multiConcat helper', function() { { input: '{{multiConcat string1 3 false "" "4" true}}', output: 'First3false4true', + }, + { + input: '{{multiConcat string1 ""}}', + output: 'First', } ], done); }); From 579150348392d8d9cc477b2ddd3c23bda88953a3 Mon Sep 17 00:00:00 2001 From: Julia Chen Date: Fri, 20 Jan 2023 18:42:19 -0500 Subject: [PATCH 12/12] Merge branch 'bigcommerce-master' into feature/multi-concat # Solve Conflicts: # helpers/strReplace.js --- helpers/strReplace.js | 19 ------------------- 1 file changed, 19 deletions(-) diff --git a/helpers/strReplace.js b/helpers/strReplace.js index 8e25a80..a542e64 100644 --- a/helpers/strReplace.js +++ b/helpers/strReplace.js @@ -1,34 +1,19 @@ 'use strict'; const common = require('./lib/common.js'); -<<<<<<< HEAD -const utils = require('handlebars-utils'); - -const factory = globals => { - return function(str, substr, newSubstr, iteration) { -======= const utils = require('./3p/utils'); const factory = globals => { return function (str, substr, newSubstr, iteration) { ->>>>>>> bigcommerce-master str = common.unwrapIfSafeString(globals.handlebars, str); substr = common.unwrapIfSafeString(globals.handlebars, substr); newSubstr = common.unwrapIfSafeString(globals.handlebars, newSubstr); iteration = common.unwrapIfSafeString(globals.handlebars, iteration); -<<<<<<< HEAD - if (!utils.isString(str)){ - throw new TypeError("Invalid query parameter string passed to strReplace"); - } else if (!utils.isString(substr)){ - throw new TypeError("Invalid query paramter substring passed to strReplace"); - } else if(!utils.isString(newSubstr)) { -======= if (!utils.isString(str)) { throw new TypeError("Invalid query parameter string passed to strReplace"); } else if (!utils.isString(substr)) { throw new TypeError("Invalid query paramter substring passed to strReplace"); } else if (!utils.isString(newSubstr)) { ->>>>>>> bigcommerce-master throw new TypeError("Invalid query parameter new substring passed to strReplace"); } @@ -59,11 +44,7 @@ function escapeRegex(string) { } function getOccurrences(str, substr) { -<<<<<<< HEAD - const matches = str.match(new RegExp(escapeRegex(substr),'g')); -======= const matches = str.match(new RegExp(escapeRegex(substr), 'g')); ->>>>>>> bigcommerce-master return matches ? matches.length : 0; }