mirror of
https://github.com/status-im/react-native.git
synced 2025-01-10 01:25:39 +00:00
ad0fe15e2e
Summary:
React Native bundler (aka Metro Bundler) was splitted from the main codebase some time ago (now it lives [[https://github.com/facebook/metro-bundler|here]]). To make it more agnostic, polyfills will be moved out from it, so people who doesn't need them does not include them. However, RN will still need them, so the first step is to copy them back to RN so that we can provide them to Metro Bundler later.
We also include a way of passing the list of polyfills to include, as an `Array<string>`. The field is called `polyfills`, and defaults to the traditional list that is currently included in the package manager [see here](be1843cddc/packages/metro-bundler/src/defaults.js (L27-L37)
).
In future commits, `metro-bundler` will be able to manage the `polyfills` array passed to it, and use it, instead of the pre-defined ones.
Reviewed By: davidaurelio
Differential Revision: D5381614
fbshipit-source-id: 749d536b781843ecb3067803e44398cd6df941f1
93 lines
2.2 KiB
JavaScript
93 lines
2.2 KiB
JavaScript
/**
|
|
* Copyright (c) 2013-present, Facebook, Inc.
|
|
* All rights reserved.
|
|
*
|
|
* This source code is licensed under the BSD-style license found in the
|
|
* LICENSE file in the root directory of this source tree. An additional grant
|
|
* of patent rights can be found in the PATENTS file in the same directory.
|
|
*
|
|
* @polyfill
|
|
*/
|
|
|
|
/* eslint-disable strict, no-extend-native, no-bitwise */
|
|
|
|
/*
|
|
* NOTE: We use (Number(x) || 0) to replace NaN values with zero.
|
|
*/
|
|
|
|
if (!String.prototype.startsWith) {
|
|
String.prototype.startsWith = function(search) {
|
|
'use strict';
|
|
if (this == null) {
|
|
throw TypeError();
|
|
}
|
|
var string = String(this);
|
|
var pos = arguments.length > 1 ?
|
|
(Number(arguments[1]) || 0) : 0;
|
|
var start = Math.min(Math.max(pos, 0), string.length);
|
|
return string.indexOf(String(search), pos) === start;
|
|
};
|
|
}
|
|
|
|
if (!String.prototype.endsWith) {
|
|
String.prototype.endsWith = function(search) {
|
|
'use strict';
|
|
if (this == null) {
|
|
throw TypeError();
|
|
}
|
|
var string = String(this);
|
|
var stringLength = string.length;
|
|
var searchString = String(search);
|
|
var pos = arguments.length > 1 ?
|
|
(Number(arguments[1]) || 0) : stringLength;
|
|
var end = Math.min(Math.max(pos, 0), stringLength);
|
|
var start = end - searchString.length;
|
|
if (start < 0) {
|
|
return false;
|
|
}
|
|
return string.lastIndexOf(searchString, start) === start;
|
|
};
|
|
}
|
|
|
|
if (!String.prototype.repeat) {
|
|
String.prototype.repeat = function(count) {
|
|
'use strict';
|
|
if (this == null) {
|
|
throw TypeError();
|
|
}
|
|
var string = String(this);
|
|
count = Number(count) || 0;
|
|
if (count < 0 || count === Infinity) {
|
|
throw RangeError();
|
|
}
|
|
if (count === 1) {
|
|
return string;
|
|
}
|
|
var result = '';
|
|
while (count) {
|
|
if (count & 1) {
|
|
result += string;
|
|
}
|
|
if ((count >>= 1)) {
|
|
string += string;
|
|
}
|
|
}
|
|
return result;
|
|
};
|
|
}
|
|
|
|
if (!String.prototype.includes) {
|
|
String.prototype.includes = function(search, start) {
|
|
'use strict';
|
|
if (typeof start !== 'number') {
|
|
start = 0;
|
|
}
|
|
|
|
if (start + search.length > this.length) {
|
|
return false;
|
|
} else {
|
|
return this.indexOf(search, start) !== -1;
|
|
}
|
|
};
|
|
}
|