Comparing version 1.2.0 to 1.3.0
@@ -8,3 +8,3 @@ "use strict"; | ||
exports.default = (function (input) { return tslib_1.__awaiter(void 0, void 0, void 0, function () { | ||
var sourceLanguage, targetLanguage, term, url, body, translations, _a, translationsLeft, translationsRight, data, error_1; | ||
var sourceLanguage, targetLanguage, term, url, body, translations, translationsIds, _a, translationsLeft, translationsRight, audioUrls, data, error_1; | ||
return tslib_1.__generator(this, function (_b) { | ||
@@ -29,2 +29,3 @@ switch (_b.label) { | ||
translations = (0, parser_1.getTranslationsArray)(body); | ||
translationsIds = (0, parser_1.getTranslationsIds)(body); | ||
if (!translations[0] || !translations[1]) { | ||
@@ -38,8 +39,9 @@ return [2, { | ||
_a = (0, parser_1.getTranslationsColumns)(body), translationsLeft = _a.translationsLeft, translationsRight = _a.translationsRight; | ||
audioUrls = (0, parser_1.getTranslationsAudioUrls)(translationsIds, sourceLanguage, targetLanguage); | ||
data = void 0; | ||
if (translations[0].includes(term)) { | ||
data = (0, utils_1.prepareData)(translationsRight, translationsLeft); | ||
data = (0, utils_1.prepareData)(translationsRight, translationsLeft, audioUrls); | ||
} | ||
else { | ||
data = (0, utils_1.prepareData)(translationsLeft, translationsRight); | ||
data = (0, utils_1.prepareData)(translationsLeft, translationsRight, audioUrls); | ||
} | ||
@@ -46,0 +48,0 @@ return [2, { |
@@ -5,2 +5,3 @@ import { Translation, TranslationInput } from './types'; | ||
export declare const getTranslationsArray: (html: string) => (string[] | undefined)[]; | ||
export declare const getTranslationsIds: (html: string) => string[]; | ||
export declare const getTranslationsColumns: (html: string) => { | ||
@@ -10,1 +11,2 @@ translationsLeft: Translation[]; | ||
}; | ||
export declare const getTranslationsAudioUrls: (translationsIds: string[], sourceLanguage: string, targetLanguage: string) => string[]; |
"use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.getTranslationsColumns = exports.getTranslationsArray = exports.getHtmlString = exports.createDictccUrl = void 0; | ||
exports.getTranslationsAudioUrls = exports.getTranslationsColumns = exports.getTranslationsIds = exports.getTranslationsArray = exports.getHtmlString = exports.createDictccUrl = void 0; | ||
var tslib_1 = require("tslib"); | ||
@@ -26,2 +26,7 @@ var cheerio_1 = tslib_1.__importDefault(require("cheerio")); | ||
exports.getTranslationsArray = getTranslationsArray; | ||
var getTranslationsIds = function (html) { | ||
var _a; | ||
return ((_a = Array.from(html.matchAll(/var idArr = new Array\((.*)\);/g), function (m) { return m[1]; }).map(function (translationId) { return JSON.parse("[".concat(translationId.replaceAll("\\'", "'"), "]")); })[0]) !== null && _a !== void 0 ? _a : []).slice(1); | ||
}; | ||
exports.getTranslationsIds = getTranslationsIds; | ||
var getTranslationsColumns = function (html) { | ||
@@ -53,1 +58,7 @@ var $ = cheerio_1.default.load(html); | ||
exports.getTranslationsColumns = getTranslationsColumns; | ||
var getTranslationsAudioUrls = function (translationsIds, sourceLanguage, targetLanguage) { | ||
return translationsIds.map(function (translationId) { | ||
return "https://audio.dict.cc/speak.audio.v2.php?type=mp3&id=".concat(translationId, "&lang=").concat(targetLanguage, "_rec_ip&lp=").concat(sourceLanguage.toUpperCase()).concat(targetLanguage.toUpperCase()); | ||
}); | ||
}; | ||
exports.getTranslationsAudioUrls = getTranslationsAudioUrls; |
@@ -20,2 +20,3 @@ import { Languages } from './languages'; | ||
targetTranslation: Translation; | ||
targetTranslationAudioUrl: string; | ||
}; | ||
@@ -22,0 +23,0 @@ export declare type TranslationResult = { |
import { TextMetaResult, Translation, Translations } from './types'; | ||
export declare const getTextMeta: (text: string) => TextMetaResult; | ||
export declare const getTranslatedText: (text: string) => string; | ||
export declare const prepareData: (from: Translation[], to: Translation[]) => Translations[]; | ||
export declare const prepareData: (from: Translation[], to: Translation[], audioUrls: string[]) => Translations[]; |
@@ -18,8 +18,9 @@ "use strict"; | ||
exports.getTranslatedText = getTranslatedText; | ||
var prepareData = function (from, to) { | ||
var prepareData = function (from, to, audioUrls) { | ||
return from.map(function (element, index) { return ({ | ||
sourceTranslation: element, | ||
targetTranslation: to[index], | ||
targetTranslationAudioUrl: audioUrls[index], | ||
}); }); | ||
}; | ||
exports.prepareData = prepareData; |
import { __awaiter, __generator } from "tslib"; | ||
import { Languages } from './languages'; | ||
import { getHtmlString, getTranslationsColumns, getTranslationsArray, createDictccUrl, } from './parser'; | ||
import { getHtmlString, getTranslationsColumns, getTranslationsArray, getTranslationsIds, getTranslationsAudioUrls, createDictccUrl, } from './parser'; | ||
import { prepareData } from './utils'; | ||
export default (function (input) { return __awaiter(void 0, void 0, void 0, function () { | ||
var sourceLanguage, targetLanguage, term, url, body, translations, _a, translationsLeft, translationsRight, data, error_1; | ||
var sourceLanguage, targetLanguage, term, url, body, translations, translationsIds, _a, translationsLeft, translationsRight, audioUrls, data, error_1; | ||
return __generator(this, function (_b) { | ||
@@ -26,2 +26,3 @@ switch (_b.label) { | ||
translations = getTranslationsArray(body); | ||
translationsIds = getTranslationsIds(body); | ||
if (!translations[0] || !translations[1]) { | ||
@@ -35,8 +36,9 @@ return [2, { | ||
_a = getTranslationsColumns(body), translationsLeft = _a.translationsLeft, translationsRight = _a.translationsRight; | ||
audioUrls = getTranslationsAudioUrls(translationsIds, sourceLanguage, targetLanguage); | ||
data = void 0; | ||
if (translations[0].includes(term)) { | ||
data = prepareData(translationsRight, translationsLeft); | ||
data = prepareData(translationsRight, translationsLeft, audioUrls); | ||
} | ||
else { | ||
data = prepareData(translationsLeft, translationsRight); | ||
data = prepareData(translationsLeft, translationsRight, audioUrls); | ||
} | ||
@@ -43,0 +45,0 @@ return [2, { |
@@ -5,2 +5,3 @@ import { Translation, TranslationInput } from './types'; | ||
export declare const getTranslationsArray: (html: string) => (string[] | undefined)[]; | ||
export declare const getTranslationsIds: (html: string) => string[]; | ||
export declare const getTranslationsColumns: (html: string) => { | ||
@@ -10,1 +11,2 @@ translationsLeft: Translation[]; | ||
}; | ||
export declare const getTranslationsAudioUrls: (translationsIds: string[], sourceLanguage: string, targetLanguage: string) => string[]; |
@@ -20,2 +20,6 @@ import { __awaiter, __generator } from "tslib"; | ||
}; | ||
export var getTranslationsIds = function (html) { | ||
var _a; | ||
return ((_a = Array.from(html.matchAll(/var idArr = new Array\((.*)\);/g), function (m) { return m[1]; }).map(function (translationId) { return JSON.parse("[".concat(translationId.replaceAll("\\'", "'"), "]")); })[0]) !== null && _a !== void 0 ? _a : []).slice(1); | ||
}; | ||
export var getTranslationsColumns = function (html) { | ||
@@ -46,1 +50,6 @@ var $ = cheerio.load(html); | ||
}; | ||
export var getTranslationsAudioUrls = function (translationsIds, sourceLanguage, targetLanguage) { | ||
return translationsIds.map(function (translationId) { | ||
return "https://audio.dict.cc/speak.audio.v2.php?type=mp3&id=".concat(translationId, "&lang=").concat(targetLanguage, "_rec_ip&lp=").concat(sourceLanguage.toUpperCase()).concat(targetLanguage.toUpperCase()); | ||
}); | ||
}; |
@@ -20,2 +20,3 @@ import { Languages } from './languages'; | ||
targetTranslation: Translation; | ||
targetTranslationAudioUrl: string; | ||
}; | ||
@@ -22,0 +23,0 @@ export declare type TranslationResult = { |
import { TextMetaResult, Translation, Translations } from './types'; | ||
export declare const getTextMeta: (text: string) => TextMetaResult; | ||
export declare const getTranslatedText: (text: string) => string; | ||
export declare const prepareData: (from: Translation[], to: Translation[]) => Translations[]; | ||
export declare const prepareData: (from: Translation[], to: Translation[], audioUrls: string[]) => Translations[]; |
@@ -13,7 +13,8 @@ export var getTextMeta = function (text) { | ||
}; | ||
export var prepareData = function (from, to) { | ||
export var prepareData = function (from, to, audioUrls) { | ||
return from.map(function (element, index) { return ({ | ||
sourceTranslation: element, | ||
targetTranslation: to[index], | ||
targetTranslationAudioUrl: audioUrls[index], | ||
}); }); | ||
}; |
{ | ||
"name": "dictcc", | ||
"version": "1.2.0", | ||
"version": "1.3.0", | ||
"description": "Unofficial dict.cc translation client", | ||
@@ -36,36 +36,29 @@ "author": "Stefan Natter (https://natterstefan.me/)", | ||
"dependencies": { | ||
"cheerio": "^1.0.0-rc.10", | ||
"node-fetch": "^3.2.3", | ||
"cheerio": "1.0.0-rc.12", | ||
"node-fetch": "^3.2.10", | ||
"request": "^2.88.2" | ||
}, | ||
"devDependencies": { | ||
"@commitlint/cli": "^16.2.3", | ||
"@commitlint/config-conventional": "^16.2.1", | ||
"@commitlint/cli": "^17.2.0", | ||
"@commitlint/config-conventional": "^17.2.0", | ||
"@semantic-release/changelog": "^6.0.1", | ||
"@semantic-release/commit-analyzer": "^9.0.2", | ||
"@semantic-release/git": "^10.0.1", | ||
"@semantic-release/github": "^8.0.4", | ||
"@semantic-release/github": "^8.0.6", | ||
"@semantic-release/npm": "^9.0.1", | ||
"@semantic-release/release-notes-generator": "^10.0.3", | ||
"@types/eslint": "^8.4.1", | ||
"@types/jest": "^27.4.1", | ||
"all-contributors-cli": "^6.20.0", | ||
"conventional-changelog-conventionalcommits": "^4.6.3", | ||
"eslint": "^8.12.0", | ||
"eslint-config-airbnb": "^19.0.4", | ||
"eslint-config-ns": "^3.0.0", | ||
"eslint-config-ns-ts-base": "3.0.0", | ||
"eslint-config-prettier": "^8.5.0", | ||
"eslint-plugin-import": "^2.26.0", | ||
"eslint-plugin-jest": "^26.1.3", | ||
"eslint-plugin-jsx-a11y": "^6.5.1", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"eslint-plugin-react": "^7.29.4", | ||
"husky": "^7.0.4", | ||
"@types/eslint": "^8.4.9", | ||
"@types/jest": "^29.2.1", | ||
"all-contributors-cli": "^6.24.0", | ||
"conventional-changelog-conventionalcommits": "^5.0.0", | ||
"eslint": "^8.26.0", | ||
"eslint-config-ns": "^3.5.0", | ||
"eslint-config-ns-ts-base": "^3.5.0", | ||
"husky": "^8.0.1", | ||
"is-ci": "^3.0.1", | ||
"jest": "^27.5.1", | ||
"jest-preset-ns": "^1.1.0", | ||
"prettier": "^2.6.2", | ||
"jest": "^29.2.2", | ||
"jest-preset-ns": "^2.2.0", | ||
"prettier": "^2.7.1", | ||
"rimraf": "^3.0.2", | ||
"semantic-release": "^19.0.2" | ||
"semantic-release": "^19.0.5" | ||
}, | ||
@@ -72,0 +65,0 @@ "repository": { |
@@ -34,3 +34,3 @@ # dictcc | ||
const getTranslation = async () => { | ||
const { data, error } = await translate({ | ||
const { data, error, url } = await translate({ | ||
sourceLanguage: Languages.en, | ||
@@ -50,3 +50,3 @@ targetLanguage: Languages.de, | ||
{ | ||
"translateFrom": { | ||
"sourceTranslation": { | ||
"text": "home", | ||
@@ -60,3 +60,3 @@ "meta": { | ||
}, | ||
"translateTo": { | ||
"targetTranslation": { | ||
"text": "daheim", | ||
@@ -69,3 +69,4 @@ "meta": { | ||
} | ||
} | ||
}, | ||
"targetTranslationAudioUrl": "https://www.example.com/audio/daheim.mp3" | ||
} | ||
@@ -88,5 +89,8 @@ ] | ||
<table> | ||
<tr> | ||
<td align="center"><a href="https://natterstefan.me/"><img src="https://avatars.githubusercontent.com/u/1043668?v=4?s=100" width="100px;" alt=""/><br /><sub><b>Stefan Natter</b></sub></a><br /><a href="#ideas-natterstefan" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/natterstefan/dictcc/commits?author=natterstefan" title="Code">💻</a></td> | ||
</tr> | ||
<tbody> | ||
<tr> | ||
<td align="center" valign="top" width="14.28%"><a href="https://natterstefan.me/"><img src="https://avatars.githubusercontent.com/u/1043668?v=4?s=100" width="100px;" alt="Stefan Natter"/><br /><sub><b>Stefan Natter</b></sub></a><br /><a href="#ideas-natterstefan" title="Ideas, Planning, & Feedback">🤔</a> <a href="https://github.com/natterstefan/dictcc/commits?author=natterstefan" title="Code">💻</a></td> | ||
<td align="center" valign="top" width="14.28%"><a href="http://sjdonado.github.io/"><img src="https://avatars.githubusercontent.com/u/27580836?v=4?s=100" width="100px;" alt="Juan Rodriguez"/><br /><sub><b>Juan Rodriguez</b></sub></a><br /><a href="https://github.com/natterstefan/dictcc/commits?author=sjdonado" title="Code">💻</a></td> | ||
</tr> | ||
</tbody> | ||
</table> | ||
@@ -93,0 +97,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
27548
22
519
101
+ Addedcheerio@1.0.0-rc.12(transitive)
+ Addedhtmlparser2@8.0.2(transitive)
- Removedcheerio@1.0.0(transitive)
- Removedencoding-sniffer@0.2.0(transitive)
- Removedhtmlparser2@9.1.0(transitive)
- Removediconv-lite@0.6.3(transitive)
- Removedparse5-parser-stream@7.1.2(transitive)
- Removedundici@6.21.0(transitive)
- Removedwhatwg-encoding@3.1.1(transitive)
- Removedwhatwg-mimetype@4.0.0(transitive)
Updatedcheerio@1.0.0-rc.12
Updatednode-fetch@^3.2.10