/
githubmirror
/
amphtml
Обзор
Документация
Войти
/
githubmirror
/
amphtml
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/polyfills/string-starts-with.js
29 строк
843 B
Kristofer Baxter
♻️ Remove Notice from JS and Markdown (#35717)
19 авг 2021, 21:21
Не верифицирован
19 авг 2021, 21:21
f564b7e
Код
Авторство
О чём код?
/** * Return true if string begins with the characters of the specified string. * Polyfill copied from MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/string/startsWith * * @param {string} search * @param {number=} rawPos * @return {boolean} * @this {string} */ function startsWith(search, rawPos) { const pos = rawPos > 0 ? rawPos | 0 : 0; // eslint-disable-next-line local/no-invalid-this return this.substr(pos, search.length) === search; } /** * Sets the String.startsWith polyfill if it does not exist. * @param {!Window} win */ export function install(win) { if (!win.String.prototype.startsWith) { win.Object.defineProperty(win.String.prototype, 'startsWith', { enumerable: false, configurable: true, writable: true, value: startsWith, }); } }