a7c170e55c76d830729b4fec8e15dba7f3aa201f
[yaffs-website] / node_modules / grunt-legacy-util / node_modules / lodash / startsWith.js
1 var baseClamp = require('./_baseClamp'),
2     toInteger = require('./toInteger'),
3     toString = require('./toString');
4
5 /**
6  * Checks if `string` starts with the given target string.
7  *
8  * @static
9  * @memberOf _
10  * @category String
11  * @param {string} [string=''] The string to search.
12  * @param {string} [target] The string to search for.
13  * @param {number} [position=0] The position to search from.
14  * @returns {boolean} Returns `true` if `string` starts with `target`, else `false`.
15  * @example
16  *
17  * _.startsWith('abc', 'a');
18  * // => true
19  *
20  * _.startsWith('abc', 'b');
21  * // => false
22  *
23  * _.startsWith('abc', 'b', 1);
24  * // => true
25  */
26 function startsWith(string, target, position) {
27   string = toString(string);
28   position = baseClamp(toInteger(position), 0, string.length);
29   return string.lastIndexOf(target, position) == position;
30 }
31
32 module.exports = startsWith;