baidu-fanyi
Advanced tools
Comparing version 0.0.1 to 0.0.2
@@ -7,3 +7,3 @@ declare type Lang = 'zh' | 'en'; | ||
}; | ||
declare class Translater { | ||
export declare class Translater { | ||
private appid; | ||
@@ -10,0 +10,0 @@ private key; |
@@ -42,2 +42,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.Translater = void 0; | ||
var crypto_1 = require("crypto"); | ||
@@ -84,2 +85,4 @@ var axios_1 = __importDefault(require("axios")); | ||
}()); | ||
exports.Translater = Translater; | ||
exports.default = Translater; | ||
exports = Translater; |
{ | ||
"name": "baidu-fanyi", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"description": "baidu fanyi api on node.js", | ||
@@ -5,0 +5,0 @@ "main": "dist/index.js", |
# baidu-fanyi | ||
baidu fanyi api on node.js | ||
## Usage | ||
```typescript | ||
import Translater from 'baidu-fanyi' | ||
const trans = new Translater('Your Appid', 'Your Key') | ||
trans.translate('hello world', { to: 'zh' }) | ||
.then(data => { | ||
console.log(data) // output: '你好,世界' | ||
}) | ||
``` |
@@ -30,7 +30,7 @@ import { createHash } from 'crypto' | ||
class Translater { | ||
export class Translater { | ||
constructor(private appid: string, private key: string) { | ||
} | ||
async translate(q: string, options?: TranslateOption) { | ||
async translate(q: string, options?: TranslateOption): Promise<string> { | ||
const { from = 'auto', to = 'en' } = options ?? {} | ||
@@ -58,1 +58,3 @@ const req: TranslateReq = { | ||
export default Translater | ||
exports = Translater |
{ | ||
"compilerOptions": { | ||
"moduleResolution": "node", | ||
"target": "es5", | ||
@@ -9,3 +10,3 @@ "module": "commonjs", | ||
"strict": true, | ||
"esModuleInterop": true | ||
"esModuleInterop": true, | ||
}, | ||
@@ -12,0 +13,0 @@ "exclude": [ |
8310
186
15