Version 1
[yaffs-website] / node_modules / core-js / library / modules / es6.string.starts-with.js
1 // 21.1.3.18 String.prototype.startsWith(searchString [, position ])
2 'use strict';
3 var $export     = require('./_export')
4   , toLength    = require('./_to-length')
5   , context     = require('./_string-context')
6   , STARTS_WITH = 'startsWith'
7   , $startsWith = ''[STARTS_WITH];
8
9 $export($export.P + $export.F * require('./_fails-is-regexp')(STARTS_WITH), 'String', {
10   startsWith: function startsWith(searchString /*, position = 0 */){
11     var that   = context(this, searchString, STARTS_WITH)
12       , index  = toLength(Math.min(arguments.length > 1 ? arguments[1] : undefined, that.length))
13       , search = String(searchString);
14     return $startsWith
15       ? $startsWith.call(that, search, index)
16       : that.slice(index, index + search.length) === search;
17   }
18 });