diff --git a/CHANGELOG.md b/CHANGELOG.md index 61c14fc..39d2494 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.2.1 + +- Add documentation for the remaining, undocumented API members. +- Rename `MatchingModes` to `MatchingMode` as a union type. + ## 0.2.0 - Document all API members, export them as well. diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 6ac3d4e..d7aea5c 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -16,7 +16,7 @@ npm run setup Afterwards, just to ensure the setup ran smoothly and the repository is ready to go, run the test suite: ``` -npm run test +npm test ``` > Optional: If you are contributing to the original project, feel free to skip this step. diff --git a/jsr.json b/jsr.json index c3c47f1..bd50f8a 100644 --- a/jsr.json +++ b/jsr.json @@ -1,5 +1,5 @@ { "name": "@vxern/dexonline-scraper", - "version": "0.2.0", + "version": "0.2.1", "exports": "./src/index.ts" } \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 294384e..b1ca2b2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "dexonline-scraper", - "version": "0.1.2", + "version": "0.2.1", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "dexonline-scraper", - "version": "0.1.2", + "version": "0.2.1", "license": "MIT", "dependencies": { "cheerio": "^1.0.0-rc.12" diff --git a/package.json b/package.json index 2d17c49..2137f63 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "dexonline-scraper", "description": "A tiny, battle-tested, performant and documented scraper for dexonline.ro.", "license": "MIT", - "version": "0.2.0", + "version": "0.2.1", "type": "module", "main": "./dist/index.js", "types": "./dist/index.d.ts", @@ -39,7 +39,7 @@ "format": "biome check src/ --apply-unsafe --organize-imports-enabled true", "build": "tsc", "test": "mocha --no-warnings", - "publish": "npm run build && npm publish" + "prepublishOnly": "npm test && npm run build && jsr publish" }, "dependencies": { "cheerio": "^1.0.0-rc.12" diff --git a/src/constants/copyright.ts b/src/constants/copyright.ts index 0f19865..3d40819 100644 --- a/src/constants/copyright.ts +++ b/src/constants/copyright.ts @@ -1,11 +1,4 @@ -/** - * @remarks - * This is a list of dictionary identifiers that are under copyright, and cannot be queried without explicit permission. - * - * `dexonline-scraper` filters entries out from them by default, however this can be overriden in the case of - * having obtained explicit permission for a given dictionary. - */ -export default Object.freeze([ +const _copyright = [ "Petro-Sedim", "Legislație", "DLR", @@ -65,4 +58,14 @@ export default Object.freeze([ "DAN", "Șăineanu, ed. I", "DASLR", -] satisfies string[]); +]; + +/** + * This is a list of dictionary identifiers that are under copyright, and cannot be queried without explicit permission. + * + * `dexonline-scraper` filters entries out from them by default, however this can be overriden in the case of + * having obtained explicit permission for a given dictionary. + */ +const copyright: readonly string[] = Object.freeze(_copyright); + +export default copyright; diff --git a/src/constants/expressions.ts b/src/constants/expressions.ts index 7c3bae5..696e054 100644 --- a/src/constants/expressions.ts +++ b/src/constants/expressions.ts @@ -1,5 +1,13 @@ -export default Object.freeze({ +const _expressions = { treeType: /^type-(\w+)$/, relationType: /^me-(\d+)$/, tableLemmaWithIndex: /((?:[a-zA-ZăĂâÂîÎșȘțȚ-]+))((\d+)<\/sup>)?/, -} as const satisfies Record); +} as const; + +/** + * This is a collection of regular expressions used internally by `dexonline-scraper` for resolving + * dictionary entries. + */ +const expressions: typeof _expressions = Object.freeze(_expressions); + +export default expressions; diff --git a/src/constants/links.ts b/src/constants/links.ts index 072a162..6259b71 100644 --- a/src/constants/links.ts +++ b/src/constants/links.ts @@ -1,3 +1,8 @@ -export default Object.freeze({ +const _links = { definition: (word: string): string => `https://dexonline.ro/definitie/${word}`, -} as const satisfies Record); +} as const; + +/** This is a collection of links used internally by `dexonline-scraper` for resolving dictionary entries. */ +const links: typeof _links = Object.freeze(_links); + +export default links; diff --git a/src/constants/selectors.ts b/src/constants/selectors.ts index ee7991a..a4d8ce1 100644 --- a/src/constants/selectors.ts +++ b/src/constants/selectors.ts @@ -1,6 +1,6 @@ import { ContentTabs } from "../options.js"; -export default Object.freeze({ +const _selectors = { contentTab: (tab: ContentTabs): string => `#tab_${tab}`, contentTabs: { synthesis: { @@ -51,4 +51,12 @@ export default Object.freeze({ }, }, }, -} as const); +} as const; + +/** + * This is a collection of DOM selectors used internally by `dexonline-scraper` for locating different elements + * during scraping of dictionary entries. + */ +const selectors: typeof _selectors = Object.freeze(_selectors); + +export default selectors; diff --git a/src/index.ts b/src/index.ts index 58fdf09..0abcd0e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -3,8 +3,17 @@ import copyrightedDictionaries from "./constants/copyright.js"; import Expressions from "./constants/expressions.js"; import Links from "./constants/links.js"; import Selectors from "./constants/selectors.js"; -import { DictionaryFlags, MatchingModes, ParserOptions, SearchOptionsWithWord } from "./options.js"; +import { DictionaryFlags, MatchingMode, ParserOptions, SearchOptionsWithWord } from "./options.js"; + +/** + * A namespace containing functions to scrape inflection models from the inflection ("conjugări / declinări") + * tab on Dexonline. + */ import * as Inflection from "./tabs/inflection.js"; + +/** + * A namespace containing functions to scrape dictionary entries from the synthesis ("sinteză") tab on Dexonline. + */ import * as Synthesis from "./tabs/synthesis.js"; /** The default search options. */ @@ -22,7 +31,9 @@ const defaultSearchOptionsWithWord = Object.freeze({ /** Represents the results of a word search using `dexonline-scraper`. */ export interface Results { + /** A list of results from the synthesis tab. */ readonly synthesis: Synthesis.DictionaryEntry[]; + /** A list of results from the inflection tab. */ readonly inflection: Inflection.InflectionModel[]; } @@ -77,14 +88,5 @@ export function parse(contents: string, options: SearchOptionsWithWord = d return { synthesis, inflection }; } -export { - DictionaryFlags, - MatchingModes, - Synthesis, - Inflection, - Links, - Expressions, - Selectors, - copyrightedDictionaries, -}; +export { DictionaryFlags, MatchingMode, Synthesis, Inflection, Links, Expressions, Selectors, copyrightedDictionaries }; export type { ParserOptions }; diff --git a/src/options.ts b/src/options.ts index 60becde..131ca29 100644 --- a/src/options.ts +++ b/src/options.ts @@ -14,7 +14,7 @@ export enum ContentTabs { } /** Specifies the strictness of word matching. */ -export type MatchingModes = +export type MatchingMode = /** Consider only lemmas that match the search term exactly. */ | "strict" /** Consider all lemmas similar to the search term. */ @@ -27,7 +27,7 @@ export interface ParserOptions { * * @defaultValue `"lax"` */ - readonly mode: MatchingModes; + readonly mode: MatchingMode; /** * Specifies whether the parser should exclude copyrighted dictionaries. diff --git a/src/tabs/synthesis.ts b/src/tabs/synthesis.ts index c7065d7..b210a89 100644 --- a/src/tabs/synthesis.ts +++ b/src/tabs/synthesis.ts @@ -48,9 +48,13 @@ export type RelationType = "synonym" | "antonym" | "diminutive" | "augmentative" /** An object containing the relations between a given lemma and other lemmas. */ export interface Relations { + /** A list of synonyms of the given lemma. */ readonly synonyms: string[]; + /** A list of antonyms of the given lemma. */ readonly antonyms: string[]; + /** A list of diminutive forms of the given lemma. */ readonly diminutives: string[]; + /** A list of augmentative forms of the given lemma. */ readonly augmentatives: string[]; } @@ -59,16 +63,23 @@ export interface Example extends Row.Row {} /** A row containing a definition for a given lemma. */ export interface Definition extends Row.Row { + /** A list of sub-definitions. */ readonly definitions: Definition[]; + /** A list of examples for this definition. */ readonly examples: Example[]; + /** A list of expressions for this definition. */ readonly expressions: Expression[]; + /** A list of relations between the given lemma and other lemmas for this definition. */ readonly relations: Relations; } /** A row containing an expression featuring a given lemma. */ export interface Expression extends Row.Row { + /** A list of examples for this expression. */ readonly examples: Example[]; + /** A list of sub-expressions for this expression. */ readonly expressions: Expression[]; + /** A list of relations between the given lemma and other lemmas for this expression. */ readonly relations: Relations; } diff --git a/src/tabs/synthesis/row.ts b/src/tabs/synthesis/row.ts index 29b0e94..5f4af60 100644 --- a/src/tabs/synthesis/row.ts +++ b/src/tabs/synthesis/row.ts @@ -5,8 +5,11 @@ import { ParserOptions } from "../../options.js"; /** The contents of a row. */ interface Contents { + /** A list of tags or "labels" placed found beside a row. */ readonly tags: string[]; + /** A list of sources (dictionaries) for where a dictionary entry was sourced from. */ readonly sources: string[]; + /** The text in the row. */ readonly value: string; }