xmpp.chapril.org-conversejs/src/polyfill.js
JC Brand ab0ec7301f Various fixes for browser that don't support ES2015
Specifically for IE11.

* Add a polyfill for String.prototype.includes
* Make sure all bundled code is transpiled
* Add IE specific fix in converse-otr.js
2017-08-21 15:43:36 +02:00

46 lines
1.4 KiB
JavaScript

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; // eslint-disable-line lodash/prefer-includes
}
};
}
if (!String.prototype.endsWith) {
String.prototype.endsWith = function (searchString, position) {
var subjectString = this.toString();
if (position === undefined || position > subjectString.length) {
position = subjectString.length;
}
position -= searchString.length;
var lastIndex = subjectString.indexOf(searchString, position);
return lastIndex !== -1 && lastIndex === position;
};
}
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (searchString, position) {
position = position || 0;
return this.substr(position, searchString.length) === searchString;
};
}
if (!String.prototype.splitOnce) {
String.prototype.splitOnce = function (delimiter) {
var components = this.split(delimiter);
return [components.shift(), components.join(delimiter)];
};
}
if (!String.prototype.trim) {
String.prototype.trim = function () {
return this.replace(/^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g, '');
};
}