xshell 0.0.15 → 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/chalk.browser.d.ts +2 -0
- package/chalk.browser.js +21 -0
- package/chalk.browser.js.map +1 -0
- package/file.js +1 -2
- package/file.js.map +1 -1
- package/i18n/README.md +283 -0
- package/i18n/dict.d.ts +30 -0
- package/i18n/dict.js +34 -0
- package/i18n/dict.js.map +1 -0
- package/i18n/i18n-scan.d.ts +2 -0
- package/i18n/i18n-scan.js +21 -0
- package/i18n/i18n-scan.js.map +1 -0
- package/i18n/i18n.ico +0 -0
- package/i18n/index.d.ts +65 -0
- package/i18n/index.js +118 -0
- package/i18n/index.js.map +1 -0
- package/i18n/rwdict.d.ts +42 -0
- package/i18n/rwdict.js +110 -0
- package/i18n/rwdict.js.map +1 -0
- package/i18n/scanner/checker.d.ts +5 -0
- package/i18n/scanner/checker.js +73 -0
- package/i18n/scanner/checker.js.map +1 -0
- package/i18n/scanner/index.d.ts +52 -0
- package/i18n/scanner/index.js +319 -0
- package/i18n/scanner/index.js.map +1 -0
- package/i18n/scanner/parser.d.ts +3 -0
- package/i18n/scanner/parser.js +154 -0
- package/i18n/scanner/parser.js.map +1 -0
- package/i18n/utils.d.ts +1 -0
- package/i18n/utils.js +14 -0
- package/i18n/utils.js.map +1 -0
- package/myfont.sass +11 -0
- package/net.browser.d.ts +23 -0
- package/net.browser.js +70 -0
- package/net.browser.js.map +1 -0
- package/net.js +2 -4
- package/net.js.map +1 -1
- package/package.json +36 -7
- package/prototype.browser.d.ts +130 -0
- package/prototype.browser.js +421 -0
- package/prototype.browser.js.map +1 -0
- package/repl.js +4 -8
- package/repl.js.map +1 -1
- package/scroll-bar.sass +35 -0
- package/server.d.ts +1 -0
- package/server.js +2 -3
- package/server.js.map +1 -1
- package/toaster.browser.d.ts +9 -0
- package/toaster.browser.js +45 -0
- package/toaster.browser.js.map +1 -0
- package/toaster.sass +22 -0
- package/ufs.js +3 -3
- package/ufs.js.map +1 -1
- package/utils.browser.d.ts +3 -0
- package/utils.browser.js +27 -0
- package/utils.browser.js.map +1 -0
- package/extension.d.ts +0 -3
- package/extension.js +0 -68
- package/extension.js.map +0 -1
- package/net.browser.ts +0 -141
- package/prototype.browser.ts +0 -728
- package/tsconfig.json +0 -73
- package/utils.browser.ts +0 -25
package/net.browser.js
ADDED
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.request_json = exports.request = void 0;
|
|
4
|
+
async function request(url, { method, queries, headers, body, type = 'application/json', cors, by = window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch', raw, } = {}) {
|
|
5
|
+
url = new URL(url, location.href);
|
|
6
|
+
if (queries)
|
|
7
|
+
for (const key in queries) {
|
|
8
|
+
let value = queries[key];
|
|
9
|
+
if (typeof value === 'boolean')
|
|
10
|
+
value = value ? '1' : '0';
|
|
11
|
+
url.searchParams.append(key, value);
|
|
12
|
+
}
|
|
13
|
+
if (body && !method)
|
|
14
|
+
method = 'post';
|
|
15
|
+
if (type === 'application/json' && typeof body !== 'undefined' && typeof body !== 'string')
|
|
16
|
+
body = JSON.stringify(body);
|
|
17
|
+
url = url.toString();
|
|
18
|
+
if (by === 'fetch') {
|
|
19
|
+
const options = {
|
|
20
|
+
...method ? { method: method.toUpperCase() } : {},
|
|
21
|
+
...cors ? { mode: 'cors' } : {},
|
|
22
|
+
credentials: 'include',
|
|
23
|
+
headers: {
|
|
24
|
+
...body ? { 'content-type': type } : {},
|
|
25
|
+
...headers,
|
|
26
|
+
},
|
|
27
|
+
...body ? { body: body } : {},
|
|
28
|
+
};
|
|
29
|
+
const response = await fetch(url, options);
|
|
30
|
+
if (!response.ok)
|
|
31
|
+
throw Object.assign(new Error(`StatusCodeError: ${response.status}`), { url, response, ...options });
|
|
32
|
+
if (raw)
|
|
33
|
+
return response;
|
|
34
|
+
return response.text();
|
|
35
|
+
}
|
|
36
|
+
return new Promise((resolve, reject) => {
|
|
37
|
+
GM_xmlhttpRequest({
|
|
38
|
+
...method ? { method: method.toUpperCase() } : {},
|
|
39
|
+
url: url,
|
|
40
|
+
headers: {
|
|
41
|
+
...body ? { 'content-type': type } : {},
|
|
42
|
+
...headers,
|
|
43
|
+
},
|
|
44
|
+
...body ? { data: body, } : {},
|
|
45
|
+
onload(response) {
|
|
46
|
+
if (!(200 <= response.status && response.status <= 299)) {
|
|
47
|
+
reject(Object.assign(new Error(`StatusCodeError: ${response.status}`), { url, queries, method, headers, body, response }));
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
50
|
+
resolve(response.responseText);
|
|
51
|
+
}
|
|
52
|
+
});
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
exports.request = request;
|
|
56
|
+
/** 发起 http 请求并将响应体作为 json 解析 */
|
|
57
|
+
async function request_json(url, options) {
|
|
58
|
+
const resp = await request(url, options);
|
|
59
|
+
if (!resp)
|
|
60
|
+
return;
|
|
61
|
+
try {
|
|
62
|
+
return JSON.parse(resp);
|
|
63
|
+
}
|
|
64
|
+
catch (error) {
|
|
65
|
+
console.error(resp);
|
|
66
|
+
throw error;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
exports.request_json = request_json;
|
|
70
|
+
//# sourceMappingURL=net.browser.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"net.browser.js","sourceRoot":"","sources":["net.browser.ts"],"names":[],"mappings":";;;AA6BO,KAAK,UAAU,OAAO,CAAE,GAAiB,EAAE,EAC9C,MAAM,EAEN,OAAO,EAEP,OAAO,EAEP,IAAI,EAEJ,IAAI,GAAG,kBAAkB,EAEzB,IAAI,EAEJ,EAAE,GAAG,MAAM,CAAC,iBAAiB,CAAC,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,OAAO,EAE7D,GAAG,MACiC,EAAG;IACvC,GAAG,GAAG,IAAI,GAAG,CAAC,G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,CAAY,GAAW,EAAE,OAAwB;IAC/E,MAAM,IAAI,GAAG,MAAM,OAAO,CAAC,GAAG,EAAE,OAAO,CAAC,CAAA;IACxC,IAAI,CAAC,IAAI;QAAE,OAAM;IACjB,IAAI;QACA,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;KAC1B;IAAC,OAAO,KAAK,EAAE;QACZ,OAAO,CAAC,KAAK,CAAC,IAAI,CAAC,CAAA;QACnB,MAAM,KAAK,CAAA;KACd;AACL,CAAC;AATD,oCASC","sourcesContent":["export interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | object | HTMLFormElement\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n cors?: boolean\n \n by?: 'fetch' | 'GM_xmlhttpRequest'\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/**\n - url: 可以只有 pathname 部分\n - options:\n - type: `'application/json'` 请求的 content-type 头 (如果有 body)\n - by: `window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch'` 发起请求所使用的底层方法\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<Response>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n method,\n \n queries,\n \n headers,\n \n body,\n \n type = 'application/json',\n \n cors,\n \n by = window.GM_xmlhttpRequest ? 'GM_xmlhttpRequest' : 'fetch',\n \n raw,\n}: RequestOptions & { raw?: boolean } = { }) {\n url = new URL(url, location.href)\n \n if (queries)\n for (const key in queries) {\n let value = queries[key]\n if (typeof value === 'boolean')\n value = value ? '1' : '0'\n url.searchParams.append(key, value)\n }\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && typeof body !== 'string')\n body = JSON.stringify(body)\n \n url = url.toString()\n \n if (by === 'fetch') {\n const options: RequestInit = {\n ... method ? { method: method.toUpperCase() } : { },\n \n ... cors ? { mode: 'cors' } : { },\n \n credentials: 'include',\n \n headers: {\n ... body ? { 'content-type': type } : { },\n ... headers,\n },\n \n ... body ? { body: body as string } : { },\n }\n \n const response = await fetch(\n url,\n options\n )\n \n if (!response.ok)\n throw Object.assign(\n new Error(`StatusCodeError: ${response.status}`),\n { url, response, ...options }\n )\n \n if (raw)\n return response\n \n return response.text()\n }\n \n \n return new Promise((resolve, reject) => {\n GM_xmlhttpRequest({\n ... method ? { method: (method as any).toUpperCase() } : { },\n \n url: url as string,\n \n headers: {\n ... body ? { 'content-type': type } : { },\n ... headers,\n },\n \n ... body ? { data: body as string, } : { },\n \n onload (response) {\n if (!(200 <= response.status && response.status <= 299)) {\n reject(\n Object.assign(\n new Error(`StatusCodeError: ${response.status}`), \n { url, queries, method, headers, body, response }\n )\n )\n return\n }\n \n resolve(response.responseText)\n }\n })\n })\n}\n\n\n/** 发起 http 请求并将响应体作为 json 解析 */\nexport async function request_json <T = any> (url: string, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.error(resp)\n throw error\n }\n}\n\n"]}
|
package/net.js
CHANGED
|
@@ -51,12 +51,11 @@ async function request_retry(retries, request_options) {
|
|
|
51
51
|
maxTimeout: Infinity,
|
|
52
52
|
factor: 2
|
|
53
53
|
}, async (retry, count) => {
|
|
54
|
-
var _a;
|
|
55
54
|
try {
|
|
56
55
|
return await (0, exports._request)(request_options);
|
|
57
56
|
}
|
|
58
57
|
catch (error) {
|
|
59
|
-
if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(
|
|
58
|
+
if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code))
|
|
60
59
|
throw error;
|
|
61
60
|
if (count <= retries)
|
|
62
61
|
console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`);
|
|
@@ -66,7 +65,6 @@ async function request_retry(retries, request_options) {
|
|
|
66
65
|
}
|
|
67
66
|
exports.request_retry = request_retry;
|
|
68
67
|
async function request(url, { queries, body, type = 'application/json', proxy, method, headers, encoding, raw = false, retries, timeout = 20 * 1000, auth, gzip, cookies, } = {}) {
|
|
69
|
-
var _a;
|
|
70
68
|
url = url.toString();
|
|
71
69
|
if (!url.startsWith('http'))
|
|
72
70
|
url = 'http://' + url;
|
|
@@ -167,7 +165,7 @@ async function request(url, { queries, body, type = 'application/json', proxy, m
|
|
|
167
165
|
// --- decode body
|
|
168
166
|
if (encoding === 'binary')
|
|
169
167
|
return resp.body;
|
|
170
|
-
encoding || (encoding =
|
|
168
|
+
encoding || (encoding = /charset=(.*)/.exec(resp.headers['content-type'])?.[1] || 'utf-8');
|
|
171
169
|
if (/utf-?8/i.test(encoding))
|
|
172
170
|
return resp.body.toString('utf-8');
|
|
173
171
|
return iconv_lite_1.default.decode(resp.body, encoding);
|
package/net.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,iGAAoD;AAEpD,0DAA6E;AAE7E,+EAAyC;AAEzC,yEAA8B;AAC9B,mEAA6B;AAC7B,yDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qBAAM,OA2CA;AAlCf,uBAAoB;AAEpB,mCAA+C;AAE/C,IAAY,OAGX;AAHD,WAAY,OAAO;IACf,4CAAiC,CAAA;IACjC,4CAAiC,CAAA;AACrC,CAAC,EAHW,OAAO,GAAP,eAAO,KAAP,eAAO,QAGlB;AAGD,sDAAsD;AACtD,MAAM,YAAY,GAAG,IAAI,gCAAiB,EAAE,CAAA;AAE/B,QAAA,OAAO,GAAG;IACnB,KAAK,EAAE,YAAY;IAEnB,GAAG,EAAE,gCAAe,CAAC,GAAG,CAAC,YAAY,CAAC;IAEtC,GAAG,CAAE,aAAqB,EAAE,GAAG,GAA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+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import request_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect, output_width } from './utils'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
|
1
|
+
{"version":3,"file":"net.js","sourceRoot":"","sources":["net.ts"],"names":[],"mappings":";;;;AAGA,iGAAoD;AAEpD,0DAA6E;AAE7E,+EAAyC;AAEzC,yEAA8B;AAC9B,mEAA6B;AAC7B,yDAAmB;AACnB,+CAAwD;AA2C/C,uFA3CA,qB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KAAK,CAAC,6BAA6B,CAAC,CAAA;IAEzD,OAAO,YAAY,CAAC,GAAG,EAAE;QACrB,IAAI,EAAE;YACF,IAAI;YACJ,IAAI;YACJ,KAAK,EAAE,MAAM;YACb,MAAM;SACT;KACJ,CAAC,CAAA;AACN,CAAC;AAfD,kBAeC;AAGD,SAAgB,QAAQ,CAAE,IAAY,EAAE,IAAW;IAC/C,MAAM,GAAG,GAAG,IAAI,CAAC,IAAI,CAAE,GAAG,CAAC,EAAE,CAAC,OAAO,GAAG,KAAK,QAAQ,CAAC,CAAC,CAAC;QAChD,OAAO,CAAC,+BAA+B,EAAE,EAAE,IAAI,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC;QACtE,CAAC;YACG,OAAO,CAAC,+BAA+B,EAAE,EAAE,OAAO,EAAE,EAAE,IAAI,EAAE,IAAI,EAAE,EAAE,CAAC,CAAA;IAC7E,OAAO,GAAG,CAAA;AACd,CAAC;AAND,4BAMC","sourcesContent":["import request_lib from 'request'\nimport type { OptionsWithUri, OptionsWithUrl } from 'request'\n\nimport request_promise from 'request-promise-native'\nimport type { FullResponse } from 'request-promise-native'\nimport { RequestError, StatusCodeError } from 'request-promise-native/errors'\n\nimport promise_retry from 'promise-retry'\n\nimport iconv from 'iconv-lite'\nimport cheerio from 'cheerio'\nimport qs from 'qs'\nimport { Cookie, MemoryCookieStore } from 'tough-cookie'\n\ndeclare module 'tough-cookie' {\n interface MemoryCookieStore {\n idx: Record<string, any>\n }\n}\n\n\nimport './prototype'\nimport type { Encoding } from './file'\nimport { inspect, output_width } from './utils'\n\nexport enum MyProxy {\n socks5 = 'http://localhost:10080',\n whistle = 'http://localhost:8899',\n}\n\n\n// ------------------------------------ Fetch, Request\nconst cookie_store = new MemoryCookieStore()\n\nexport const cookies = {\n store: cookie_store,\n \n jar: request_promise.jar(cookie_store),\n \n get (domain_or_url: string, str = false) {\n if (domain_or_url.startsWith('http'))\n if (str)\n return this.jar.getCookieString(domain_or_url)\n else\n return this.jar.getCookies(domain_or_url)\n \n let cookies: Cookie[]\n this.store.findCookies(domain_or_url, null, true, (error, _cookies) => {\n if (error) throw error\n cookies = _cookies\n })\n return cookies\n },\n}\n\nexport { Cookie }\n\n\nexport const _request = request_promise.defaults({\n rejectUnauthorized: false,\n gzip: true,\n /** prevent 302 redirect cause error, which is a boolean to set whether status codes other than 2xx should also reject the promise */\n simple: false,\n \n jar: cookies.jar\n})\n\n\nexport async function request_retry (retries: number, request_options: request_promise.OptionsWithUrl) {\n return promise_retry<FullResponse>({\n retries,\n minTimeout: 1000,\n maxTimeout: Infinity,\n factor: 2\n }, async (retry, count) => {\n try {\n return await _request(request_options)\n } catch (error) {\n if (!['ECONNRESET', 'ETIMEDOUT', 'ESOCKETTIMEDOUT'].includes(error.cause?.code)) throw error\n if (count <= retries)\n console.log(`${`retry (${count}) …`.yellow} ${request_options.url.toString().blue.underline}`)\n return retry(error)\n }\n })\n}\n\n\nexport interface RequestOptions {\n method?: 'get' | 'post' | 'put' | 'head' | 'delete' | 'patch'\n \n queries?: Record<string, any>\n \n headers?: Record<string, string>\n \n body?: string | Record<string, any>\n \n type?: 'application/json' | 'application/x-www-form-urlencoded' | 'multipart/form-data'\n \n \n proxy?: boolean | MyProxy | string\n \n encoding?: Encoding\n \n retries?: true | number\n \n timeout?: number\n \n auth?: {\n username: string\n password: string\n }\n \n gzip?: boolean\n \n cookies?: Record<string, string>\n}\n\nexport interface RequestRawOptions extends RequestOptions {\n raw: true\n}\n\n/** \n - url: must be full url\n - options:\n - raw: `false` 传入后返回整个 response\n - encoding: `(response content-type: charset=gb18030) || 'utf-8'` when 'binary' then return buffer\n - type: `'application/json'` request content-type header (if has body)\n - proxy: `false` proxy === true then use MyProxy.whistle\n - retries: `false` could be true (default 3 times) or retry times\n - timeout: `20 * 1000`\n - gzip: `raw -> false; else -> true`\n*/\nexport async function request (url: string | URL): Promise<string>\nexport async function request (url: string | URL, options: RequestRawOptions): Promise<request_lib.Response>\nexport async function request (url: string | URL, options: RequestOptions & { encoding: 'binary' }): Promise<Buffer>\nexport async function request (url: string | URL, options: RequestOptions): Promise<string>\nexport async function request (url: string | URL, {\n queries,\n \n body,\n \n type = 'application/json',\n \n proxy,\n \n method,\n \n headers,\n \n encoding,\n \n raw = false,\n \n retries,\n \n timeout = 20 * 1000,\n \n auth,\n \n gzip,\n \n cookies,\n \n}: RequestOptions & { raw?: boolean } = { }) {\n url = url.toString()\n \n if (!url.startsWith('http'))\n url = 'http://' + url\n \n const _body = body // for error log\n \n if (body && !method)\n method = 'post'\n \n if (type === 'application/json' && typeof body !== 'undefined' && (typeof body !== 'string' && !Buffer.isBuffer(body)))\n body = JSON.stringify(body)\n \n // --- proxy\n if (proxy) {\n if (proxy === true)\n proxy = MyProxy.whistle\n } else\n proxy = false\n \n // --- gzip\n if (gzip === undefined)\n gzip = !raw\n \n \n const options: request_lib.Options & { resolveWithFullResponse: boolean } = {\n url,\n \n ... method ? { method: method.toUpperCase() } : { },\n \n proxy,\n \n gzip,\n \n encoding: null,\n \n resolveWithFullResponse: true,\n \n headers: {\n 'accept-language': 'zh-CN,zh;q=0.9,en-US;q=0.8,en;q=0.7,ja-JP;q=0.6,ja;q=0.5',\n 'user-agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.82 Safari/537.36',\n ... body ? { 'content-type': type } : { }, \n ... cookies ? {\n cookie: Object.entries(cookies)\n .map(([key, value]) => \n `${encodeURIComponent(key)}=${encodeURIComponent(value)}`\n ).join('; ')\n } : { },\n ... headers\n },\n \n ... queries ? { qs: queries } : { },\n \n // --- body\n ... (() => {\n if (!body) return { }\n if (type === 'application/x-www-form-urlencoded') return { form: body }\n if (type === 'multipart/form-data') return { formData: body as Record<string, any> }\n return { body }\n })(),\n \n ... timeout ? { timeout } : { },\n \n ... auth ? { auth } : { },\n }\n \n let resp: request_lib.Response\n \n try {\n if (retries) {\n if (retries === true)\n retries = 3\n \n resp = await request_retry(retries, options)\n } else\n resp = await _request(options)\n \n if (!(200 <= resp.statusCode && resp.statusCode <= 299))\n throw new StatusCodeError(resp.statusCode, resp.body, options, resp)\n \n } catch (error) {\n const {\n name, \n options: { method, url, uri, qs }, \n response,\n }: {\n options: OptionsWithUri & OptionsWithUrl\n response: FullResponse\n } & Error = error\n \n error[inspect.custom] = () => {\n let s = '─'.repeat(output_width / 2) + '\\n' +\n `${(method || 'get').toLowerCase().red} ${String(url || uri).blue.underline}\\n`\n \n if (qs)\n s += `\\n${'request.query:'.blue}\\n` +\n inspect(qs) + '\\n'\n \n if (_body)\n s += `\\n${'request.body:'.blue}\\n` +\n inspect(body) + '\\n'\n \n if (name === 'StatusCodeError')\n s += `\\n${'response.status:'.yellow} ${String(error.statusCode).red}\\n`\n else if (error instanceof RequestError)\n s += `\\n${'response.cause:'.yellow}\\n` +\n `${inspect(error.cause)}\\n`\n else\n s += `\\n${inspect(error)}\\n`\n \n if (response) {\n s += `\\n${'response.headers:'.yellow}\\n` + \n `${inspect(response.headers)}\\n`\n \n if (response.body)\n s += `\\n${'response.body:'.yellow}\\n` +\n `${inspect(response.body.toString())}\\n`\n }\n \n s += `\\n${'stack:'.yellow}\\n` +\n `${new Error().stack}\\n` +\n '─'.repeat(output_width / 2)\n \n return s\n }\n \n throw error\n }\n \n if (raw)\n return resp\n \n if (!resp.body)\n return resp.body\n \n // --- decode body\n if (encoding === 'binary')\n return resp.body\n \n encoding ||= /charset=(.*)/.exec(resp.headers['content-type'])?.[1] as Encoding || 'utf-8'\n \n if (/utf-?8/i.test(encoding))\n return (resp.body as Buffer).toString('utf-8')\n \n return iconv.decode((resp.body as Buffer), encoding)\n}\n\n\n/** make http request and parse body as json */\nexport async function request_json <T = any> (url: string | URL, options?: RequestOptions): Promise<T> {\n const resp = await request(url, options)\n if (!resp) return\n try {\n return JSON.parse(resp)\n } catch (error) {\n console.log(resp)\n throw error\n }\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport function parse_html (html: string) {\n let $ = cheerio.load(html, { decodeEntities: false })\n \n Object.defineProperty($, inspect.custom, {\n configurable: true,\n enumerable: false,\n value () {\n return this.html()\n }\n })\n \n Object.defineProperty($.prototype, inspect.custom, {\n configurable: true,\n enumerable: false,\n value (this: cheerio.Cheerio) {\n if (this.length > 1)\n return this.map((index, element) => {\n if (typeof element === 'string') return element\n return $.html(element)\n }).get().join_lines()\n \n return this.toString()\n }\n })\n \n return $\n}\n\n\n/** use $.html(cheerio_element) to get outer html */\nexport async function request_page (url: string | URL, options?: RequestOptions) {\n return parse_html(\n await request(url, options)\n )\n}\n\n\nexport function to_curl (url: string | URL, { queries, headers, method, body, proxy, exe = true }: RequestOptions & { exe?: boolean } = { }) {\n if (proxy === true)\n proxy = process.env.http_proxy\n \n url = url.toString()\n \n if (!url.startsWith('http'))\n url = `http://${url}`\n \n return (exe ? 'curl.exe' : 'curl') + \n ' ' + ( url + (queries ? '?' : '') + qs.stringify(queries) ).quote() +\n // ( typeof proxy === 'undefined' ?\n // ''\n // :\n // ( proxy ? ' --proxy ' + proxy.quote() : ' --noproxy ' + '*'.quote())\n // ) +\n ( proxy ? ` --proxy ${proxy.quote()}` : '' ) +\n ( method && method !== 'get' ? ` -X ${method}` : '' ) +\n ( headers ? Object.entries(headers).map( ([key, value]) => ' -H ' + `${key}: ${value}`.quote() ).join('') : '' ) +\n ( body ? ' -H ' + 'content-type: application/json'.quote() : '') +\n ( body ? ' --data ' + JSON.stringify(body).quote() : '')\n}\n\n\n\n\n// ------------------------------------ rpc client\n/** post json to http://localhost:8421/api/rpc\n - func: function name\n - args?: argument array\n - options?:\n - ignore?: `false` wait for execution but do not serialize result to response\n - async?: `false` do not wait for exec\n*/\nexport async function rpc (\n func: string, \n args?: any[], \n { url = 'http://localhost:8421/api/rpc', async: _async = false, ignore = false }: { url?: string, async?: boolean, ignore?: boolean } = { }\n) {\n if (!func) throw new Error('rpc argument error: no func')\n \n return request_json(url, {\n body: {\n func,\n args,\n async: _async,\n ignore,\n }\n })\n}\n\n\nexport function rpc_curl (func: string, args: any[]) {\n const cmd = args.find( arg => typeof arg === 'object') ?\n to_curl('http://localhost:8421/api/rpc', { body: { func, args } })\n :\n to_curl('http://localhost:8421/api/rpc', { queries: { func, args } })\n return cmd\n}\n\n"]}
|
package/package.json
CHANGED
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "xshell",
|
|
3
|
-
"version": "0.0.
|
|
3
|
+
"version": "0.0.20",
|
|
4
4
|
"main": "./index.js",
|
|
5
5
|
"bin": {
|
|
6
|
-
"xshell": "./xshell.js"
|
|
6
|
+
"xshell": "./xshell.js",
|
|
7
|
+
"i18n-scan": "./i18n/i18n-scan.js"
|
|
7
8
|
},
|
|
8
9
|
"description": "xshell is a shell designed to provide a brand new human-computer interaction experience.",
|
|
9
10
|
"keywords": [
|
|
10
11
|
"shell",
|
|
11
12
|
"node",
|
|
12
13
|
"repl",
|
|
14
|
+
"i18n",
|
|
13
15
|
"interactive programming"
|
|
14
16
|
],
|
|
15
17
|
"type": "commonjs",
|
|
@@ -63,25 +65,42 @@
|
|
|
63
65
|
]
|
|
64
66
|
},
|
|
65
67
|
"dependencies": {
|
|
68
|
+
"@babel/core": "^7.15.0",
|
|
69
|
+
"@babel/parser": "^7.15.3",
|
|
70
|
+
"@babel/traverse": "^7.15.0",
|
|
66
71
|
"@koa/cors": "^3.1.0",
|
|
67
72
|
"byte-size": "^8.1.0",
|
|
68
73
|
"chalk": "^4.1.2",
|
|
69
74
|
"chardet": "^1.4.0",
|
|
70
75
|
"cheerio": "^1.0.0-rc.10",
|
|
76
|
+
"cli-table3": "^0.6.0",
|
|
77
|
+
"cli-truncate": "=2.1.0",
|
|
78
|
+
"colors": "^1.4.0",
|
|
79
|
+
"commander": "^8.1.0",
|
|
80
|
+
"ejs": "^3.1.6",
|
|
71
81
|
"emoji-regex": "^10.0.0",
|
|
72
82
|
"fs-extra": "^10.0.0",
|
|
73
83
|
"fs-monkey": "^1.0.3",
|
|
84
|
+
"gulp-sort": "^2.0.0",
|
|
85
|
+
"hash-string": "^1.0.0",
|
|
86
|
+
"i18next-scanner": "^3.0.0",
|
|
87
|
+
"i18next": "^20.5.0",
|
|
74
88
|
"iconv-lite": "^0.6.3",
|
|
75
|
-
"
|
|
89
|
+
"js-cookie": "^3.0.0",
|
|
76
90
|
"koa-compress": "^5.1.0",
|
|
77
91
|
"koa-useragent": "^4.0.0",
|
|
92
|
+
"koa": "^2.13.4",
|
|
78
93
|
"lodash": "^4.17.21",
|
|
94
|
+
"map-stream": "0.0.7",
|
|
79
95
|
"memfs": "^3.4.0",
|
|
96
|
+
"ora": "=5.4.1",
|
|
80
97
|
"promise-retry": "^2.0.1",
|
|
81
98
|
"qs": "^6.10.1",
|
|
99
|
+
"react-i18next": "^11.11.4",
|
|
100
|
+
"react": "^17.0.2",
|
|
82
101
|
"readdir-enhanced": "^6.0.4",
|
|
83
|
-
"request": "^2.88.2",
|
|
84
102
|
"request-promise-native": "^1.0.9",
|
|
103
|
+
"request": "^2.88.2",
|
|
85
104
|
"resolve-path": "^1.4.0",
|
|
86
105
|
"rimraf": "^3.0.2",
|
|
87
106
|
"stream-buffers": "^3.0.2",
|
|
@@ -89,23 +108,33 @@
|
|
|
89
108
|
"tough-cookie": "^4.0.0",
|
|
90
109
|
"tslib": "^2.3.1",
|
|
91
110
|
"typescript": "^4.5.2",
|
|
92
|
-
"upath": "^2.0.1"
|
|
111
|
+
"upath": "^2.0.1",
|
|
112
|
+
"vinyl-fs": "^3.0.3",
|
|
113
|
+
"vinyl": "^2.2.1"
|
|
93
114
|
},
|
|
94
115
|
"devDependencies": {
|
|
116
|
+
"@babel/types": "^7.15.0",
|
|
117
|
+
"@types/babel__traverse": "^7.14.2",
|
|
95
118
|
"@types/chardet": "^0.8.1",
|
|
96
119
|
"@types/cheerio": "^0.22.30",
|
|
120
|
+
"@types/ejs": "^3.1.0",
|
|
121
|
+
"@types/express": "^4.17.13",
|
|
97
122
|
"@types/fs-extra": "^9.0.13",
|
|
98
|
-
"@types/
|
|
123
|
+
"@types/gulp-sort": "0.0.33",
|
|
124
|
+
"@types/js-cookie": "^2.2.7",
|
|
99
125
|
"@types/koa-compress": "^4.0.3",
|
|
126
|
+
"@types/koa": "^2.13.4",
|
|
100
127
|
"@types/lodash": "^4.14.177",
|
|
101
128
|
"@types/node": "^16.11.10",
|
|
102
129
|
"@types/promise-retry": "^1.1.3",
|
|
103
130
|
"@types/qs": "^6.9.7",
|
|
104
|
-
"@types/
|
|
131
|
+
"@types/react": "^17.0.19",
|
|
105
132
|
"@types/request-promise-native": "^1.0.18",
|
|
133
|
+
"@types/request": "^2.48.7",
|
|
106
134
|
"@types/rimraf": "^3.0.2",
|
|
107
135
|
"@types/stream-buffers": "^3.0.4",
|
|
108
136
|
"@types/tampermonkey": "^4.0.5",
|
|
137
|
+
"@types/vinyl-fs": "^2.4.12",
|
|
109
138
|
"@types/vscode": "^1.62.0"
|
|
110
139
|
}
|
|
111
140
|
}
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
/** 在浏览器端修改 prototype,需要更加小心 */
|
|
2
|
+
declare global {
|
|
3
|
+
interface String {
|
|
4
|
+
readonly width: number;
|
|
5
|
+
/** 截取字符串不超过 width 显示宽度的部分,并保留颜色
|
|
6
|
+
找到并记录能容纳 字符串 + … 的最后一个字符的位置 i_fitted
|
|
7
|
+
若完整的字符串长度超过 width,返回 slice(0, i_fitted + 1) + …
|
|
8
|
+
否则 返回 this
|
|
9
|
+
*/
|
|
10
|
+
truncate(this: string, width: number): string;
|
|
11
|
+
pad(this: string, width: number, { character, position }?: {
|
|
12
|
+
character?: string;
|
|
13
|
+
position?: 'left' | 'right';
|
|
14
|
+
}): string;
|
|
15
|
+
limit(this: string, width: number, { character, position }?: {
|
|
16
|
+
character?: string;
|
|
17
|
+
position?: 'left' | 'right';
|
|
18
|
+
}): string;
|
|
19
|
+
to_regx(this: string, preservations?: string, flags?: string): RegExp;
|
|
20
|
+
/** ```ts
|
|
21
|
+
'g:/acgn/海贼王/[Skytree][海贼王][One_Piece][893][GB_BIG5_JP][X264_AAC][1080P][CRRIP][天空树双语字幕组].mkv'.refmt(
|
|
22
|
+
'{dirp}/[Skytree][海贼王][{ en_name: \\w+ }][{ episode: \\d+ }][GB_BIG5_JP][{encoding}_AAC][1080P][CRRIP][天空树双语字幕组].{format}',
|
|
23
|
+
'g:/acgn/海贼王/{episode} {encoding}.{format}',
|
|
24
|
+
'\\+',
|
|
25
|
+
'i',
|
|
26
|
+
(name, value) => name === 'episode' ? String(+value + 1) : value.toLowerCase()
|
|
27
|
+
)
|
|
28
|
+
```
|
|
29
|
+
*/
|
|
30
|
+
refmt(this: string, pattern: string, pattern_: string,
|
|
31
|
+
/** `''` 保留的正则表达式字符 */
|
|
32
|
+
preservations?: string,
|
|
33
|
+
/** `''` 正则匹配选项 */
|
|
34
|
+
flags?: string,
|
|
35
|
+
/** `(name, matched) => matched || ''` placeholder transformer */
|
|
36
|
+
transformer?: (name: string, value: string, placeholders: {
|
|
37
|
+
[name: string]: string;
|
|
38
|
+
}) => string,
|
|
39
|
+
/** `/\{.*?\}/g` */
|
|
40
|
+
pattern_placeholder?: RegExp): string;
|
|
41
|
+
/** 字符串模式搜索
|
|
42
|
+
```ts
|
|
43
|
+
'git+https://github.com/tamino-martinius/node-ts-dedent-123.git'.find(
|
|
44
|
+
'^{protocol:[\\w+]+}://{hostname:[\\w\\.]+}/{username}/{project}-{index:\\d+}.{suffix}', '^', 'i'
|
|
45
|
+
)
|
|
46
|
+
{
|
|
47
|
+
protocol: 'git+https',
|
|
48
|
+
hostname: 'github.com',
|
|
49
|
+
...
|
|
50
|
+
}
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
- preservations?: `''` 保留的正则表达式字符
|
|
54
|
+
- flags?: `''` 正则匹配选项
|
|
55
|
+
- pattern_placeholder?: `/\{.*?\}/g`
|
|
56
|
+
*/
|
|
57
|
+
find(this: string, pattern: string, preservations?: string, flags?: string, pattern_placeholder?: RegExp): {
|
|
58
|
+
[name: string]: string;
|
|
59
|
+
};
|
|
60
|
+
/** - type?: `'single'` */
|
|
61
|
+
quote(this: string, type?: keyof typeof quotes | 'psh'): string;
|
|
62
|
+
/** - shape?: `'parenthesis'` */
|
|
63
|
+
bracket(this: string, shape?: keyof typeof brackets): string;
|
|
64
|
+
surround(this: string, left: string, right?: string): string;
|
|
65
|
+
surround_tag(this: string, tag_name: string): string;
|
|
66
|
+
to_lf(this: string): string;
|
|
67
|
+
to_crlf(this: string): string;
|
|
68
|
+
/** 'xxx'.replace(/pattern/g, '')
|
|
69
|
+
如果 pattern 是 string 则在创建 RegExp 时自动加上 flags (默认 'g'), 否则忽略 flags
|
|
70
|
+
*/
|
|
71
|
+
rm(this: string, pattern: string | RegExp, flags?: string): string;
|
|
72
|
+
split_lines(this: string): string[];
|
|
73
|
+
trim_doc_comment(this: string): string;
|
|
74
|
+
split_indent(this: string): {
|
|
75
|
+
indent: number;
|
|
76
|
+
text: string;
|
|
77
|
+
};
|
|
78
|
+
space(this: string): string;
|
|
79
|
+
to_slash(this: string): string;
|
|
80
|
+
to_backslash(this: string): string;
|
|
81
|
+
}
|
|
82
|
+
interface Date {
|
|
83
|
+
to_str(this: Date): string;
|
|
84
|
+
to_date_str(this: Date): string;
|
|
85
|
+
to_time_str(this: Date): string;
|
|
86
|
+
}
|
|
87
|
+
interface Number {
|
|
88
|
+
to_bin_str(this: number): string;
|
|
89
|
+
to_hex_str(this: number): string;
|
|
90
|
+
to_oct_str(this: number): string;
|
|
91
|
+
}
|
|
92
|
+
interface Array<T> {
|
|
93
|
+
indent(this: string[], width: number, c?: string): string[];
|
|
94
|
+
/**
|
|
95
|
+
- trim_line?: `true`
|
|
96
|
+
- rm_empty_lines?: `true`
|
|
97
|
+
- rm_last_empty_lines?: `false`
|
|
98
|
+
*/
|
|
99
|
+
trim_lines(this: string[], { trim_line, rm_empty_lines, rm_last_empty_lines }?: {
|
|
100
|
+
trim_line?: boolean;
|
|
101
|
+
rm_empty_lines?: boolean;
|
|
102
|
+
rm_last_empty_lines?: boolean;
|
|
103
|
+
}): string[];
|
|
104
|
+
join_lines(): string;
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
export declare const emoji_regex: RegExp;
|
|
108
|
+
export declare function to_method_property_descriptors(methods: {
|
|
109
|
+
[name: string]: Function;
|
|
110
|
+
}): PropertyDescriptorMap;
|
|
111
|
+
export declare function to_getter_property_descriptors(getters: {
|
|
112
|
+
[name: string]: Function;
|
|
113
|
+
}): PropertyDescriptorMap;
|
|
114
|
+
export declare const cjk = "([\u2E80-\u9FFF\uF900-\uFAFF])";
|
|
115
|
+
export declare const quotes: {
|
|
116
|
+
single: string;
|
|
117
|
+
double: string;
|
|
118
|
+
backtick: string;
|
|
119
|
+
};
|
|
120
|
+
export declare const brackets: {
|
|
121
|
+
readonly round: readonly ["(", ")"];
|
|
122
|
+
readonly square: readonly ["[", "]"];
|
|
123
|
+
readonly curly: readonly ["{", "}"];
|
|
124
|
+
readonly pointy: readonly ["<", ">"];
|
|
125
|
+
readonly corner: readonly ["「", "」"];
|
|
126
|
+
readonly fat: readonly ["【", "】"];
|
|
127
|
+
readonly tortoise_shell: readonly ["〔", "〕"];
|
|
128
|
+
};
|
|
129
|
+
export declare function to_json(object: any, replacer?: any): string;
|
|
130
|
+
export declare function is_codepoint_fullwidth(codepoint: number): boolean;
|