mirror of
https://github.com/google/blockly.git
synced 2026-01-30 20:20:09 +01:00
chore: Make startsWith faster (#6118)
by using built-in function (polyfill will handle IE).
This commit is contained in:
@@ -19,17 +19,22 @@
|
||||
*/
|
||||
goog.module('Blockly.utils.string');
|
||||
|
||||
const deprecation = goog.require('Blockly.utils.deprecation');
|
||||
|
||||
|
||||
/**
|
||||
* Fast prefix-checker.
|
||||
* Copied from Closure's goog.string.startsWith.
|
||||
* Obsolete prefix-checker.
|
||||
* @param {string} str The string to check.
|
||||
* @param {string} prefix A string to look for at the start of `str`.
|
||||
* @return {boolean} True if `str` begins with `prefix`.
|
||||
* @alias Blockly.utils.string.startsWith
|
||||
* @deprecated April 2022. Use built-in string.startsWith.
|
||||
*/
|
||||
const startsWith = function(str, prefix) {
|
||||
return str.lastIndexOf(prefix, 0) === 0;
|
||||
deprecation.warn(
|
||||
'Blockly.utils.string.startsWith()', 'April 2022', 'April 2023',
|
||||
'Use built-in string.startsWith');
|
||||
return str.startsWith(prefix);
|
||||
};
|
||||
exports.startsWith = startsWith;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user