@yxw007/translate 0.0.3 → 0.0.4

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/dist/index.d.ts CHANGED
@@ -412,7 +412,7 @@ declare const _default$1: {
412
412
  type Language = Reverse<typeof _default$2> | Reverse<typeof _default$1>;
413
413
 
414
414
  interface TranslateOptions {
415
- from: Language;
415
+ from?: Language;
416
416
  to: Language;
417
417
  engine?: string;
418
418
  /**
@@ -1,4 +1,4 @@
1
- // translate v0.0.3 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
1
+ // translate v0.0.4 Copyright (c) 2024 Potter<aa4790139@gmail.com> and contributors
2
2
  'use strict';
3
3
 
4
4
  Object.defineProperty(exports, '__esModule', { value: true });
@@ -23,7 +23,7 @@ function google(options) {
23
23
  return {
24
24
  name: "google",
25
25
  async translate(text, opts) {
26
- const { from, to } = opts;
26
+ const { from = "auto", to } = opts;
27
27
  if (!Array.isArray(text)) {
28
28
  text = [text];
29
29
  }
@@ -57,7 +57,7 @@ function azure(options) {
57
57
  name: "azure",
58
58
  async translate(text, opts) {
59
59
  const { from, to } = opts;
60
- const url = `${base}&from=${from}&to=${to}`;
60
+ const url = `${base}&to=${to}${from ? `&from=${from}` : ""}`;
61
61
  if (!Array.isArray(text)) {
62
62
  text = [text];
63
63
  }
@@ -8278,7 +8278,7 @@ function amazon(options) {
8278
8278
  return {
8279
8279
  name: "amazon",
8280
8280
  async translate(text, opts) {
8281
- const { from, to } = opts;
8281
+ const { from = "auto", to } = opts;
8282
8282
  const translateClient = new TranslateClient({ region: region, credentials: { accessKeyId, secretAccessKey } });
8283
8283
  if (!Array.isArray(text)) {
8284
8284
  text = [text];
@@ -9388,7 +9388,7 @@ function baidu(options) {
9388
9388
  return {
9389
9389
  name: "baidu",
9390
9390
  async translate(text, opts) {
9391
- const { to, from, domain = "it" } = opts;
9391
+ const { to, from = "auto", domain = "it" } = opts;
9392
9392
  if (!Array.isArray(text)) {
9393
9393
  text = [text];
9394
9394
  }
@@ -9728,9 +9728,6 @@ class Translator {
9728
9728
  throw new Error(`Engine ${engine} not found`);
9729
9729
  }
9730
9730
  //2. Check if language exists
9731
- if (!language(from)) {
9732
- throw new Error(`Language ${from} not found`);
9733
- }
9734
9731
  if (!language(to)) {
9735
9732
  throw new Error(`Language ${to} not found`);
9736
9733
  }