This repository was archived by the owner on Feb 20, 2019. It is now read-only.
File tree 3 files changed +34
-0
lines changed
3 files changed +34
-0
lines changed Original file line number Diff line number Diff line change @@ -11,6 +11,7 @@ import isArray from './is-array'
11
11
import validateEmail from './validateEmail'
12
12
import hex2rgb from './hex2rgb'
13
13
import isNullOrWhitespace from './is-null-or-whitespace'
14
+ import startsWith from './startsWith'
14
15
15
16
export {
16
17
flatten ,
@@ -26,4 +27,5 @@ export {
26
27
validateEmail ,
27
28
hex2rgb ,
28
29
isNullOrWhitespace ,
30
+ startsWith ,
29
31
}
Original file line number Diff line number Diff line change
1
+ export default startsWith
2
+
3
+ /**
4
+ * Original Source: http://stackoverflow.com/a/646631/5954939
5
+ *
6
+ * This method will return a bollean indicating whether a string starts with a given input.
7
+ *
8
+ * @param {String } str - The string to validate against
9
+ * @param {String } head - The input to match with str substring
10
+ * @return {Bollean } - True if 'str' starts with 'head', otherwise false
11
+ */
12
+ function startsWith ( str , head ) {
13
+ const tmp = str . substring ( 0 , head . length )
14
+ const res = ( tmp === head )
15
+ return res
16
+ }
Original file line number Diff line number Diff line change
1
+ import test from 'ava'
2
+ import { startsWith } from '../src'
3
+
4
+ test ( 'check correct input' , t => {
5
+ const string = 'First PR'
6
+ const head = 'Fir'
7
+ const result = startsWith ( string , head )
8
+ t . true ( result )
9
+ } )
10
+
11
+ test ( 'check wrong input' , t => {
12
+ const string = 'First PR'
13
+ const head = 'Foo'
14
+ const result = startsWith ( string , head )
15
+ t . false ( result )
16
+ } )
You can’t perform that action at this time.
0 commit comments