forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.ts
More file actions
47 lines (44 loc) · 1.42 KB
/
index.ts
File metadata and controls
47 lines (44 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/**
* BrowserFS's main entry point.
* It installs all of the needed polyfills, and requires() the main module.
*/
// IE substr does not support negative indices
if ('ab'.substr(-1) !== 'b') {
String.prototype.substr = function(substr: (start: number, length?: number) => string) {
return function(this: string, start: number, length?: number): string {
// did we get a negative start, calculate how much it is from the
// beginning of the string
if (start < 0) {
start = this.length + start;
}
// call the original function
return substr.call(this, start, length);
};
}(String.prototype.substr);
}
// Polyfill for Uint8Array.prototype.slice.
// Safari and some other browsers do not define it.
if (typeof(ArrayBuffer) !== 'undefined' && typeof(Uint8Array) !== 'undefined') {
if (!Uint8Array.prototype['slice']) {
Uint8Array.prototype.slice = function(this: Uint8Array, start: number = 0, end: number = this.length): Uint8Array {
const self: Uint8Array = this;
if (start < 0) {
start = this.length + start;
if (start < 0) {
start = 0;
}
}
if (end < 0) {
end = this.length + end;
if (end < 0) {
end = 0;
}
}
if (end < start) {
end = start;
}
return new Uint8Array(self.buffer, self.byteOffset + start, end - start);
};
}
}
export * from './core/browserfs';