Skip to content

Commit

Permalink
fix: STRF-9673 Lodash removal, part 3 (#245)
Browse files Browse the repository at this point in the history
  • Loading branch information
jairo-bc authored Feb 8, 2023
1 parent f61267a commit 8903ce2
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
2 changes: 1 addition & 1 deletion helpers/3p/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ var helpers = module.exports;
*/

helpers.after = function(array, n) {
if (utils.isUndefined(array)) {return '';}
if (!array || utils.isUndefined(array)) {return '';}
return array.slice(n);
};

Expand Down
2 changes: 1 addition & 1 deletion helpers/pluck.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

const factory = () => {
return function(collection, path) {
if (collection) {
if (collection && Array.isArray(collection)) {
return collection.map(item => item.hasOwnProperty(path) ? item[path] : undefined);
}
return [];
Expand Down
2 changes: 1 addition & 1 deletion helpers/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const substring = require('stringz').substring;
*/
const factory = globals => {
return function(string, length) {
if (typeof string !== 'string') {
if (typeof string !== 'string' || string.length === 0) {
return string;
}

Expand Down
6 changes: 6 additions & 0 deletions spec/helpers/3p/array.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ describe('array', function() {
done();
});

it('should return all of the items in an array after the specified count.', function(done) {
var fn = hbs.compile('{{after notArray 5}}');
expect(fn(context)).to.equal('');
done();
});

it('should return all of the items in an array after the specified count.', function(done) {
var fn = hbs.compile('{{after array 5}}');
expect(fn(context)).to.equal(['f', 'g', 'h'].toString());
Expand Down
20 changes: 20 additions & 0 deletions spec/helpers/truncate.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ describe('truncate helper', function() {
spanish_string: 'mañana',
string: 'hello world',
unicode_string: 'She ❤️️ this',
empty_string: '',
null: null,
};

const runTestCases = testRunner({context});
Expand Down Expand Up @@ -55,6 +57,24 @@ describe('truncate helper', function() {
], done);
});

it('should handle empty strings', function(done) {
runTestCases([
{
input: '{{truncate empty_string 5}}',
output: '',
},
], done);
});

it('should handle null object', function(done) {
runTestCases([
{
input: '{{truncate null 5}}',
output: '',
},
], done);
});

it('should handle unicode strings', function(done) {
runTestCases([
{
Expand Down

0 comments on commit 8903ce2

Please sign in to comment.