Skip to content

Commit d7342df

Browse files
committed
Move checks to conditionals
1 parent 915e2e9 commit d7342df

File tree

6 files changed

+116
-115
lines changed

6 files changed

+116
-115
lines changed

dist/h.js

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,8 @@ exports.and = and;
111111
exports.or = or;
112112
exports.coalesce = coalesce;
113113
exports.includes = includes;
114+
exports.startsWith = startsWith;
115+
exports.endsWith = endsWith;
114116

115117
var _utils = require('../util/utils');
116118

@@ -430,6 +432,42 @@ function includes(array, value) {
430432

431433
return false;
432434
}
435+
436+
/**
437+
* Check if a string starts with a given substring.
438+
*
439+
* @example
440+
* {{startsWith 'Just Wow' 'Just'}} => true
441+
*
442+
* @param {string} str
443+
* @param {string} searchString
444+
* @returns {boolean}
445+
*/
446+
function startsWith(str, searchString) {
447+
if (typeof searchString !== 'string' || typeof str !== 'string') {
448+
return false;
449+
}
450+
451+
return str.startsWith(searchString);
452+
}
453+
454+
/**
455+
* Check if a string ends with a given substring.
456+
*
457+
* @example
458+
* {{endsWith 'Just Wow' 'Wow'}} => true
459+
*
460+
* @param {string} str
461+
* @param {string} searchString
462+
* @returns {boolean}
463+
*/
464+
function endsWith(str, searchString) {
465+
if (typeof searchString !== 'string' || typeof str !== 'string') {
466+
return false;
467+
}
468+
469+
return str.endsWith(searchString);
470+
}
433471
},{"../util/utils":9}],4:[function(require,module,exports){
434472
(function (global){(function (){
435473
'use strict';
@@ -808,8 +846,6 @@ exports.first = first;
808846
exports.last = last;
809847
exports.concat = concat;
810848
exports.join = join;
811-
exports.startsWith = startsWith;
812-
exports.endsWith = endsWith;
813849
exports.unique = unique;
814850
exports.trim = trim;
815851

@@ -1059,42 +1095,6 @@ function join(params, delimiter) {
10591095
return params.join(delimiter);
10601096
}
10611097

1062-
/**
1063-
* Check if a string starts with a given substring.
1064-
*
1065-
* @example
1066-
* {{startsWith 'Just Wow' 'Just'}} => true
1067-
*
1068-
* @param {string} str
1069-
* @param {string} searchString
1070-
* @returns {boolean}
1071-
*/
1072-
function startsWith(str, searchString) {
1073-
if (typeof searchString !== 'string' || typeof str !== 'string') {
1074-
return false;
1075-
}
1076-
1077-
return str.startsWith(searchString);
1078-
}
1079-
1080-
/**
1081-
* Check if a string ends with a given substring.
1082-
*
1083-
* @example
1084-
* {{endsWith 'Just Wow' 'Wow'}} => true
1085-
*
1086-
* @param {string} str
1087-
* @param {string} searchString
1088-
* @returns {boolean}
1089-
*/
1090-
function endsWith(str, searchString) {
1091-
if (typeof searchString !== 'string' || typeof str !== 'string') {
1092-
return false;
1093-
}
1094-
1095-
return str.endsWith(searchString);
1096-
}
1097-
10981098
/**
10991099
* Extract unique elements from given collection.
11001100
*

dist/h.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/helpers/conditionals.js

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,40 @@ export function includes(array, value, strict = true) {
302302

303303
return false;
304304
}
305+
306+
307+
/**
308+
* Check if a string starts with a given substring.
309+
*
310+
* @example
311+
* {{startsWith 'Just Wow' 'Just'}} => true
312+
*
313+
* @param {string} str
314+
* @param {string} searchString
315+
* @returns {boolean}
316+
*/
317+
export function startsWith(str, searchString) {
318+
if (typeof searchString !== 'string' || typeof str !== 'string') {
319+
return false;
320+
}
321+
322+
return str.startsWith(searchString);
323+
}
324+
325+
/**
326+
* Check if a string ends with a given substring.
327+
*
328+
* @example
329+
* {{endsWith 'Just Wow' 'Wow'}} => true
330+
*
331+
* @param {string} str
332+
* @param {string} searchString
333+
* @returns {boolean}
334+
*/
335+
export function endsWith(str, searchString) {
336+
if (typeof searchString !== 'string' || typeof str !== 'string') {
337+
return false;
338+
}
339+
340+
return str.endsWith(searchString);
341+
}

src/helpers/strings.js

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -234,42 +234,6 @@ export function join(params, delimiter) {
234234
return params.join(delimiter);
235235
}
236236

237-
/**
238-
* Check if a string starts with a given substring.
239-
*
240-
* @example
241-
* {{startsWith 'Just Wow' 'Just'}} => true
242-
*
243-
* @param {string} str
244-
* @param {string} searchString
245-
* @returns {boolean}
246-
*/
247-
export function startsWith(str, searchString) {
248-
if (typeof searchString !== 'string' || typeof str !== 'string') {
249-
return false;
250-
}
251-
252-
return str.startsWith(searchString);
253-
}
254-
255-
/**
256-
* Check if a string ends with a given substring.
257-
*
258-
* @example
259-
* {{endsWith 'Just Wow' 'Wow'}} => true
260-
*
261-
* @param {string} str
262-
* @param {string} searchString
263-
* @returns {boolean}
264-
*/
265-
export function endsWith(str, searchString) {
266-
if (typeof searchString !== 'string' || typeof str !== 'string') {
267-
return false;
268-
}
269-
270-
return str.endsWith(searchString);
271-
}
272-
273237
/**
274238
* Extract unique elements from given collection.
275239
*

tests/helpers/conditionals.spec.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,4 +481,44 @@ describe('conditionals', () => {
481481
expect(template({ array: array, value: value })).toEqual('false');
482482
});
483483
});
484+
485+
describe('startsWith', () => {
486+
it('should return true if the string starts with the provided substring', () => {
487+
expect(conditionals.startsWith('Hello World!', 'Hello')).toEqual(true);
488+
});
489+
490+
it('should return false if the string does not start with the provided substring', () => {
491+
expect(conditionals.startsWith('Hello World!', 'World')).toEqual(false);
492+
});
493+
494+
it('should work as expected after compilation (Basic Support)', () => {
495+
const template = compile('{{startsWith string subString}}');
496+
const obj = {
497+
string: 'Hello World!',
498+
subString: 'Hello'
499+
};
500+
501+
expect(JSON.parse(template(obj))).toEqual(true);
502+
});
503+
});
504+
505+
describe('endsWith', () => {
506+
it('should return true if the string ends with the provided substring', () => {
507+
expect(conditionals.endsWith('Hello World!', 'World!')).toEqual(true);
508+
});
509+
510+
it('should return false if the string does not end with the provided substring', () => {
511+
expect(conditionals.endsWith('Hello World!', 'Hello')).toEqual(false);
512+
});
513+
514+
it('should work as expected after compilation (Basic Support)', () => {
515+
const template = compile('{{endsWith string subString}}');
516+
const obj = {
517+
string: 'Hello World!',
518+
subString: 'World!'
519+
};
520+
521+
expect(JSON.parse(template(obj))).toEqual(true);
522+
});
523+
});
484524
});

tests/helpers/strings.spec.js

Lines changed: 0 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -293,46 +293,6 @@ describe('strings', () => {
293293
});
294294
});
295295

296-
describe('startsWith', () => {
297-
it('should return true if the string starts with the provided substring', () => {
298-
expect(strings.startsWith('Hello World!', 'Hello')).toEqual(true);
299-
});
300-
301-
it('should return false if the string does not start with the provided substring', () => {
302-
expect(strings.startsWith('Hello World!', 'World')).toEqual(false);
303-
});
304-
305-
it('should work as expected after compilation (Basic Support)', () => {
306-
const template = compile('{{startsWith string subString}}');
307-
const obj = {
308-
string: 'Hello World!',
309-
subString: 'Hello'
310-
};
311-
312-
expect(template(obj)).toEqual(true);
313-
});
314-
});
315-
316-
describe('endsWith', () => {
317-
it('should return true if the string ends with the provided substring', () => {
318-
expect(strings.endsWith('Hello World!', 'World!')).toEqual(true);
319-
});
320-
321-
it('should return false if the string does not end with the provided substring', () => {
322-
expect(strings.endsWith('Hello World!', 'Hello')).toEqual(false);
323-
});
324-
325-
it('should work as expected after compilation (Basic Support)', () => {
326-
const template = compile('{{endsWith string subString}}');
327-
const obj = {
328-
string: 'Hello World!',
329-
subString: 'World!'
330-
};
331-
332-
expect(template(obj)).toEqual(true);
333-
});
334-
});
335-
336296
describe('unique', () => {
337297
it('should return unique elements from an array', () => {
338298
expect(strings.unique(['apple', 'banana', 'apple', 'mango', 'banana'])).toEqual(['apple', 'banana', 'mango']);

0 commit comments

Comments
 (0)