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 +34
-0
lines changed Expand file tree Collapse file tree 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'
1111import validateEmail from './validateEmail'
1212import hex2rgb from './hex2rgb'
1313import isNullOrWhitespace from './is-null-or-whitespace'
14+ import startsWith from './startsWith'
1415
1516export {
1617 flatten ,
@@ -26,4 +27,5 @@ export {
2627 validateEmail ,
2728 hex2rgb ,
2829 isNullOrWhitespace ,
30+ startsWith ,
2931}
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