Socket
Socket
Sign inDemoInstall

sdapi

Package Overview
Dependencies
8
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.1.1 to 0.2.0

dist/sdapi.dictionary.qml.js

6

lib/conjugation.d.ts
import { Person, CNumber, Tense, Mood, Form } from './constants';
interface ConjugationResult {
export interface ConjugationResult {
person?: Person;

@@ -12,4 +12,2 @@ number?: CNumber;

declare function extract(html: string): Array<ConjugationResult>;
declare function query(verb: string): Promise<Array<ConjugationResult>>;
export { extract, query };
export default query;
export default extract;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_fetch_1 = require("node-fetch");
const constants_1 = require("./constants");

@@ -133,11 +132,2 @@ const util_1 = require("./util");

}
exports.extract = extract;
async function query(verb) {
if (!verb.length) {
return Promise.reject(new Error('Zero-length word'));
}
const res = await node_fetch_1.default(`https://www.spanishdict.com/conjugate/${verb}`);
return extract(await res.text());
}
exports.query = query;
exports.default = query;
exports.default = extract;
import { Gender, Language } from './constants';
interface Example {
export interface Example {
original: string;
translated: string;
}
interface WordResult {
export interface WordResult {
lang: Language;

@@ -18,4 +18,2 @@ word: string;

declare function extract(html: string): Array<WordResult>;
declare function query(word: string): Promise<Array<WordResult>>;
export { extract, query };
export default query;
export default extract;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const node_fetch_1 = require("node-fetch");
const constants_1 = require("./constants");

@@ -24,35 +23,28 @@ const util_1 = require("./util");

function convertSense(sense, lang) {
const translation = sense.translations[0];
return {
word: sense.subheadword,
lang: lang,
gender: sense.gender ? convertGender(sense.gender) : undefined,
context: sense.context,
meaning: translation.translation,
part: sense.partOfSpeech.nameEn,
examples: translation.examples.map((eg) => convertExample(eg, lang)),
regions: sense.regions.map((region) => region.nameEn)
};
return sense.translations.map((translation) => {
var _a;
return ({
word: sense.subheadword,
lang: lang,
gender: sense.gender ? convertGender(sense.gender) : undefined,
context: sense.context + (((_a = translation.contextEn) === null || _a === void 0 ? void 0 : _a.length) ? `, ${translation.contextEn}` : ''),
meaning: translation.translation,
part: sense.partOfSpeech.nameEn,
examples: translation.examples.map((eg) => convertExample(eg, lang)),
regions: sense.regions.concat(translation.regions).map((region) => region.nameEn)
});
});
}
function extract(html) {
var _a, _b;
var _a, _b, _c;
const resultsProps = util_1.extractComponentData(html).sdDictionaryResultsProps;
const neodict = (_b = (_a = resultsProps) === null || _a === void 0 ? void 0 : _a.entry) === null || _b === void 0 ? void 0 : _b.neodict;
if (!neodict || !neodict.length) {
if (!((_c = neodict) === null || _c === void 0 ? void 0 : _c.length)) {
throw new Error('Cannot find neodict. SpanishDict API might have changed');
}
return neodict
.map((nd) => nd.posGroups).flat()
.map((posGroup) => posGroup.senses).flat()
.map((sense) => convertSense(sense, resultsProps.entryLang));
.map((nd) => nd.posGroups).reduce((acc, val) => acc.concat(val), [])
.map((posGroup) => posGroup.senses).reduce((acc, val) => acc.concat(val), [])
.reduce((acc, val) => acc.concat(convertSense(val, resultsProps.entryLang)), []);
}
exports.extract = extract;
async function query(word) {
if (!word.length) {
return Promise.reject(new Error('Zero-length word'));
}
const res = await node_fetch_1.default(`https://www.spanishdict.com/translate/${word}`);
return extract(await res.text());
}
exports.query = query;
exports.default = query;
exports.default = extract;

@@ -1,7 +0,5 @@

import dict from './dictionary';
import conju from './conjugation';
declare const _default: {
translate: typeof dict;
conjugate: typeof conju;
translate: (word: string) => Promise<import("./dictionary").WordResult[]>;
conjugate: (verb: string) => Promise<import("./conjugation").ConjugationResult[]>;
};
export default _default;

@@ -5,5 +5,6 @@ "use strict";

const conjugation_1 = require("./conjugation");
const request_1 = require("./request");
exports.default = {
translate: dictionary_1.default,
conjugate: conjugation_1.default
translate: async (word) => dictionary_1.default(await request_1.default.translate(word)),
conjugate: async (verb) => conjugation_1.default(await request_1.default.conjugate(verb))
};
{
"name": "sdapi",
"version": "0.1.1",
"version": "0.2.0",
"description": "Unofficial APIs of SpanishDict.com",

@@ -13,2 +13,4 @@ "main": "lib/index.js",

"build": "tsc",
"rollup": "rollup -c rollup.config.js",
"rollup:qml": "rollup -c rollup.qml.config.js",
"lint": "eslint src/*.{ts,js} src/test/*.{ts,js}",

@@ -38,4 +40,9 @@ "test": "jest --collect-coverage"

"@types/node": "latest",
"@types/node-fetch": "latest"
"@types/node-fetch": "latest",
"rollup": "^2.6.0",
"@rollup/plugin-node-resolve": "^7.1.1",
"@rollup/plugin-typescript": "^4.0.0",
"@rollup/plugin-commonjs": "^11.0.2",
"stream-browserify": "^2.0.2"
}
}

Sorry, the diff of this file is not supported yet

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc