- Commander.js ```javascript import {Command} from ‘commander’;
const program = new Command()
program
.version(‘0.0.1’)
.name(‘fy’)
.usage(‘
program.parse(process.argv)
2. HTTPS 模块
```javascript
import * as https from 'https'
const options = {
// hostname: 'fanyi-api.baidu.com',
hostname: 'api.fanyi.baidu.com',
port: 443,
path: '/api/trans/vip/translate?' + query,
method: 'GET'
};
const request = https.request(options, (response) => {
const chunks:Buffer[] = [];
response.on('data', (chunk) => {
chunks.push(chunk);
});
response.on('end', () => {
const string = Buffer.concat(chunks).toString();
type BaiduResult = {
error_msg?: string;
error_code?: string;
from: string;
to: string;
trans_result: { src: string; dst: string }[]
}
const obj: BaiduResult = JSON.parse(string);
if (obj.error_code) {
console.error(errorMap[obj.error_code] || obj.error_msg);
process.exit(2);
} else {
obj.trans_result.map((obj)=>{console.log(obj.dst);})
process.exit(0);
}
});
});
request.on('error', (e) => {
console.error(e);
});
request.end();
};
- querystring 查询字符串
```querystring.stringify(obj[, sep[, eq[, options]]])
->
querystring.stringify({ foo: 'bar', baz: ['qux', 'quux'], corge: '' });
// 返回 'foo=bar&baz=qux&baz=quux&corge='
Language files blank comment code
Perl 628 33435 28224 2106458 C++ 2373 202313 171993 1644594 JavaScript 16157 198335 219483 1337991 Assembly 408 65948 9513 716931 C 1970 97894 86608 614690 C/C++ Header 3197 112342 233488 521333 Python 685 17294 24420 187441 Markdown 484 49946 3 179208 JSON 557 14 0 74211 HTML 397 4154 1278 57598 Bourne Shell 111 8578 8264 43129 m4 35 2447 1429 21485 TypeScript 96 1165 2008 9174 YAML 71 735 151 6105 IDL 12 757 0 4023 Starlark 2 102 113 3239 make 27 554 411 2641 CSS 9 388 9 2165 CMake 14 361 347 1574 diff 11 114 543 1526 Bazel 5 106 56 1359 DOS Batch 33 172 56 1329 XHTML 4 101 36 829 D 3 100 292 698 reStructuredText 33 2011 2996 664 Windows Module Definition 8 84 7 548 XML 12 8 21 418 WiX source 1 55 7 378 PowerShell 15 15 75 330 CSV 5 0 0 314 Lisp 4 46 77 293 Bourne Again Shell 9 64 38 259 R 4 49 49 245 Scheme 1 13 51 222 Windows Resource File 4 49 94 209 SVG 4 1 9 193 C# 1 55 9 186 vim script 3 28 30 147 WebAssembly 15 19 8 135 PHP 1 13 19 124 WiX string localization 4 45 12 103 MSBuild script 1 0 16 93 Visual Studio Solution 1 1 1 44 awk 1 1 8 18 CoffeeScript 1 7 8 14 INI 1 5 1 13 Ruby 1 4 5 13 JSX 1 1 0 11 Dockerfile 1 3 0 10
sed 1 0 0 6
SUM: 27422 799932 792266 7544721
```