Skip to content

Commit 8903ce2

Browse files
authored
fix: STRF-9673 Lodash removal, part 3 (#245)
1 parent f61267a commit 8903ce2

5 files changed

Lines changed: 29 additions & 3 deletions

File tree

helpers/3p/array.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ var helpers = module.exports;
2626
*/
2727

2828
helpers.after = function(array, n) {
29-
if (utils.isUndefined(array)) {return '';}
29+
if (!array || utils.isUndefined(array)) {return '';}
3030
return array.slice(n);
3131
};
3232

helpers/pluck.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const factory = () => {
44
return function(collection, path) {
5-
if (collection) {
5+
if (collection && Array.isArray(collection)) {
66
return collection.map(item => item.hasOwnProperty(path) ? item[path] : undefined);
77
}
88
return [];

helpers/truncate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const substring = require('stringz').substring;
2525
*/
2626
const factory = globals => {
2727
return function(string, length) {
28-
if (typeof string !== 'string') {
28+
if (typeof string !== 'string' || string.length === 0) {
2929
return string;
3030
}
3131

spec/helpers/3p/array.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,12 @@ describe('array', function() {
3737
done();
3838
});
3939

40+
it('should return all of the items in an array after the specified count.', function(done) {
41+
var fn = hbs.compile('{{after notArray 5}}');
42+
expect(fn(context)).to.equal('');
43+
done();
44+
});
45+
4046
it('should return all of the items in an array after the specified count.', function(done) {
4147
var fn = hbs.compile('{{after array 5}}');
4248
expect(fn(context)).to.equal(['f', 'g', 'h'].toString());

spec/helpers/truncate.js

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@ describe('truncate helper', function() {
1111
spanish_string: 'mañana',
1212
string: 'hello world',
1313
unicode_string: 'She ❤️️ this',
14+
empty_string: '',
15+
null: null,
1416
};
1517

1618
const runTestCases = testRunner({context});
@@ -55,6 +57,24 @@ describe('truncate helper', function() {
5557
], done);
5658
});
5759

60+
it('should handle empty strings', function(done) {
61+
runTestCases([
62+
{
63+
input: '{{truncate empty_string 5}}',
64+
output: '',
65+
},
66+
], done);
67+
});
68+
69+
it('should handle null object', function(done) {
70+
runTestCases([
71+
{
72+
input: '{{truncate null 5}}',
73+
output: '',
74+
},
75+
], done);
76+
});
77+
5878
it('should handle unicode strings', function(done) {
5979
runTestCases([
6080
{

0 commit comments

Comments
 (0)