This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Expand file tree Collapse file tree 3 files changed +32
-0
lines changed Original file line number Diff line number Diff line change
1
+ export default endsWith
2
+
3
+ /**
4
+ * Original source: http://stackoverflow.com/questions/280634/endswith-in-javascript
5
+ *
6
+ * Checks if a string ends with a given input
7
+ *
8
+ * @param {String } str - The string to validate against
9
+ * @param {String } suffix - The input to match
10
+ * @return {Boolean } - True if 'str' ends with 'suffix', otherwise false
11
+ */
12
+ function endsWith ( str , suffix ) {
13
+ return str . indexOf ( suffix , str . length - suffix . length ) !== - 1
14
+ }
Original file line number Diff line number Diff line change @@ -29,6 +29,7 @@ import toPower from './to-power'
29
29
import mod from './mod'
30
30
import shallowEqual from './shallow-equal'
31
31
import swapCase from './swap-case'
32
+ import endsWith from './endsWith'
32
33
33
34
export {
34
35
initArray ,
@@ -62,4 +63,5 @@ export {
62
63
mod ,
63
64
shallowEqual ,
64
65
swapCase ,
66
+ endsWith ,
65
67
}
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import { endsWith } from '../src'
3
+
4
+ test ( 'ends with input' , t => {
5
+ const string = 'Brasilia'
6
+ const input = 'lia'
7
+ const result = endsWith ( string , input )
8
+ t . true ( result )
9
+ } )
10
+
11
+ test ( 'does not end with input' , t => {
12
+ const string = 'Brazil'
13
+ const input = 'USA'
14
+ const result = endsWith ( string , input )
15
+ t . false ( result )
16
+ } )
You can’t perform that action at this time.
0 commit comments