forked from codesandbox/codesandbox-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathonigLibs.ts
More file actions
58 lines (52 loc) · 1.53 KB
/
onigLibs.ts
File metadata and controls
58 lines (52 loc) · 1.53 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
48
49
50
51
52
53
54
55
56
57
58
/*---------------------------------------------------------
* Copyright (C) Microsoft Corporation. All rights reserved.
*--------------------------------------------------------*/
'use strict';
import { IOnigLib } from './types';
import { Thenable } from './main';
let onigasmLib: Thenable<IOnigLib> = null;
let onigurumaLib: Thenable<IOnigLib> = null;
export function getOnigasm(): Thenable<IOnigLib> {
if (!onigasmLib) {
let onigasmModule = require('onigasm');
const wasmBin = '/public/onigasm/2.2.1/onigasm.wasm';
onigasmLib = onigasmModule.loadWASM(wasmBin).then((_: any) => {
return {
createOnigScanner(patterns: string[]) { return new onigasmModule.OnigScanner(patterns); },
createOnigString(s: string) {
const r = new onigasmModule.OnigString(s);
(<any>r).$str = s;
return r;
}
};
});
}
return onigasmLib;
}
export function getOniguruma(): Thenable<IOnigLib> {
if (!onigurumaLib) {
let getOnigModule : any = (function () {
var onigurumaModule: any = null;
return function () {
if (!onigurumaModule) {
// CODESANDBOX EDIT
onigurumaModule = {};
}
return onigurumaModule;
};
})();
onigurumaLib = Promise.resolve({
createOnigScanner(patterns: string[]) {
let onigurumaModule = getOnigModule();
return new onigurumaModule.OnigScanner(patterns);
},
createOnigString(s: string) {
let onigurumaModule = getOnigModule();
let string = new onigurumaModule.OnigString(s);
string.content = s;
return string;
}
});
}
return onigurumaLib;
}