-
Notifications
You must be signed in to change notification settings - Fork 291
Expand file tree
/
Copy pathdrpy-core.js
More file actions
77 lines (69 loc) · 1.83 KB
/
drpy-core.js
File metadata and controls
77 lines (69 loc) · 1.83 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// drpy-core.js
import cheerio from './libs/cheerio.min.js';
import template from './libs/模板.js'; // 使用英文名导入
// 导入所有依赖库
import './libs/gb18030.min.js';
import './libs/crypto-js.min.js';
import './libs/jsencrypt.min.js';
import './libs/node-rsa.min.js';
import './libs/pako.min.js';
import './libs/json5.min.js';
import './libs/jsonpathplus.min.js';
import './libs/jinja.min.js';
import './libs/polywasm.min.js';
import './libs/encoding.min.js'
import './libs/xxhash-wasm.min.js';
// 确保全局依赖可用
const gbkTool = globalThis.gbkTool;
const CryptoJS = globalThis.CryptoJS;
const JSEncrypt = globalThis.JSEncrypt;
const NODERSA = globalThis.NODERSA;
const pako = globalThis.pako;
const JSON5 = globalThis.JSON5;
const JSONPath = globalThis.JSONPath;
const jinja = globalThis.jinja;
const WebAssembly = globalThis.WebAssembly;
const TextEncoder = globalThis.TextEncoder;
const TextDecoder = globalThis.TextDecoder;
// const cheerio = {
// jinja2(template, obj) {
// return jinja.render(template, obj);
// },
// jp(path, json) {
// return JSONPath.JSONPath({
// path,
// json
// })[0];
// }
// }
const _jinja2 = cheerio.jinja2;
cheerio.jinja2 = function (template, obj) {
try {
return jinja.render(template, obj);
} catch (e) {
console.log('新的jinja2库渲染失败,换回原始cheerio:' + e.message);
return _jinja2(template, obj)
}
};
cheerio.jp = function (path, json) {
return JSONPath.JSONPath({
path,
json
})[0];
};
// 导出所有需要暴露的内容
export {
cheerio,
template as 模板, // 使用别名导出中文标识符
gbkTool,
CryptoJS,
JSEncrypt,
NODERSA,
pako,
JSON5,
JSONPath,
jinja,
WebAssembly,
TextEncoder,
TextDecoder,
};