Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
122 changes: 54 additions & 68 deletions src/polyfill.js
Original file line number Diff line number Diff line change
@@ -1,94 +1,80 @@
/* eslint no-extend-native: 0 */
if (!String.prototype.startsWith) {
String.prototype.startsWith = function (search, pos) {
if (pos === undefined) {
pos = 0;
}
return this.substring(pos, search.length) === search;
};
String.prototype.startsWith = function (search, pos) {
if (pos === undefined) {
pos = 0
}
return this.substring(pos, search.length) === search
}
}

if (!String.prototype.endsWith) {
String.prototype.endsWith = function (search, this_len) {
if (this_len === undefined || this_len > this.length) {
this_len = this.length;
}
return this.substring(this_len - search.length, this_len) === search;
};
String.prototype.endsWith = function (search, len) {
if (len === undefined || len > this.length) {
len = this.length
}
return this.substring(len - search.length, len) === search
}
}

if (!String.prototype.includes) {
String.prototype.includes = function (search, pos) {
return this.indexOf(search, pos) !== -1;
};
String.prototype.includes = function (search, pos) {
return this.indexOf(search, pos) !== -1
}
}

if (!ArrayBuffer.isView) {
var typedArrays = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
];
const typedArrays = [
Int8Array,
Uint8Array,
Uint8ClampedArray,
Int16Array,
Uint16Array,
Int32Array,
Uint32Array,
Float32Array,
Float64Array
]

ArrayBuffer.isView = function (obj) {
return obj && obj.constructor && typedArrays.indexOf(obj.constructor) !== -1;
};
ArrayBuffer.isView = function (obj) {
return obj && obj.constructor && typedArrays.indexOf(obj.constructor) !== -1
}
}

if (!Int8Array.prototype.slice) {
Object.defineProperty(Int8Array.prototype, 'slice', {
value: function (begin, end)
{
return new Int8Array(this.subarray(begin, end));
}
});
Object.defineProperty(Int8Array.prototype, 'slice', {
value: function (begin, end) {
return new Int8Array(this.subarray(begin, end))
}
})
}

if (!Uint8Array.prototype.slice) {
Object.defineProperty(Uint8Array.prototype, 'slice', {
value: function (begin, end)
{
return new Uint8Array(this.subarray(begin, end));
}
});
Object.defineProperty(Uint8Array.prototype, 'slice', {
value: function (begin, end) {
return new Uint8Array(this.subarray(begin, end))
}
})
}

if (!Int16Array.from) {
// Doesn't work for String
Int16Array.from = function (source) {
var arr = new Int16Array(source.length);
arr.set(source, 0);
return arr;
};
// Doesn't work for String
Int16Array.from = function (source) {
const arr = new Int16Array(source.length)
arr.set(source, 0)
return arr
}
}

if (!Int32Array.from) {
// Doesn't work for String
Int32Array.from = function (source) {
var arr = new Int32Array(source.length);
arr.set(source, 0);
return arr;
};
// Doesn't work for String
Int32Array.from = function (source) {
const arr = new Int32Array(source.length)
arr.set(source, 0)
return arr
}
}

// performance.now() polyfill
if ("performance" in self === false) {
self.performance = {};
}
Date.now = (Date.now || function () {
return new Date().getTime();
});
if ("now" in self.performance === false) {
var nowOffset = Date.now();
if (performance.timing && performance.timing.navigationStart) {
nowOffset = performance.timing.navigationStart
}
self.performance.now = function now() {
return Date.now() - nowOffset;
}
}
return new Date().getTime()
})
Loading