dictionary-en
Advanced tools
Comparing version 3.2.0 to 4.0.0
@@ -1,28 +0,17 @@ | ||
declare namespace load { | ||
/** | ||
* Object representing a hunspell dictionary, with `aff` and `dic` fields. | ||
*/ | ||
interface Dictionary { | ||
export default dictionary; | ||
/** | ||
* Hunspell dictionary. | ||
*/ | ||
export type Dictionary = { | ||
/** | ||
* Buffer in UTF-8 for the affix file (defines the language, keyboard, flags, and more). | ||
* Data for the affix file (defines the language, keyboard, flags, and more). | ||
*/ | ||
aff: Buffer | ||
aff: Uint8Array; | ||
/** | ||
* Buffer in UTF-8 for the dictionary file (contains words and flags applying to those words). | ||
* Data for the dictionary file (contains words and flags applying to those words). | ||
*/ | ||
dic: Buffer | ||
} | ||
/** | ||
* Callback called when dictionary is loaded. | ||
*/ | ||
type Callback = ( | ||
error: NodeJS.ErrnoException | undefined, | ||
result: Dictionary | ||
) => void | ||
} | ||
declare const load: (callback: load.Callback) => void | ||
export = load | ||
dic: Uint8Array; | ||
}; | ||
/** @type {Dictionary} */ | ||
declare const dictionary: Dictionary; | ||
//# sourceMappingURL=index.d.ts.map |
37
index.js
@@ -1,27 +0,18 @@ | ||
const fs = require('fs') | ||
const path = require('path') | ||
/** | ||
* @typedef Dictionary | ||
* Hunspell dictionary. | ||
* @property {Uint8Array} aff | ||
* Data for the affix file (defines the language, keyboard, flags, and more). | ||
* @property {Uint8Array} dic | ||
* Data for the dictionary file (contains words and flags applying to those words). | ||
*/ | ||
module.exports = load | ||
import fs from 'node:fs/promises' | ||
function load(callback) { | ||
let result = {} | ||
let pos = -1 | ||
let exception | ||
const aff = await fs.readFile(new URL('index.aff', import.meta.url)) | ||
const dic = await fs.readFile(new URL('index.dic', import.meta.url)) | ||
one('aff') | ||
one('dic') | ||
/** @type {Dictionary} */ | ||
const dictionary = {aff, dic} | ||
function one(name) { | ||
fs.readFile(path.join(__dirname, 'index.' + name), (error, doc) => { | ||
pos++ | ||
exception = exception || error | ||
result[name] = doc | ||
if (pos) { | ||
callback(exception, exception ? undefined : result) | ||
exception = undefined | ||
result = undefined | ||
} | ||
}) | ||
} | ||
} | ||
export default dictionary |
{ | ||
"name": "dictionary-en", | ||
"version": "3.2.0", | ||
"version": "4.0.0", | ||
"description": "English spelling dictionary", | ||
"license": "(MIT AND BSD)", | ||
"keywords": [ | ||
"spelling", | ||
"myspell", | ||
"hunspell", | ||
"dictionary", | ||
"en", | ||
"english" | ||
"english", | ||
"hunspell", | ||
"myspell", | ||
"spelling" | ||
], | ||
@@ -25,8 +25,11 @@ "repository": "https://github.com/wooorm/dictionaries/tree/main/dictionaries/en", | ||
], | ||
"type": "module", | ||
"exports": "./index.js", | ||
"files": [ | ||
"index.js", | ||
"index.aff", | ||
"index.d.ts", | ||
"index.dic", | ||
"index.d.ts" | ||
"index.js", | ||
"index.map" | ||
] | ||
} |
102
readme.md
@@ -5,6 +5,20 @@ # dictionary-en | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`Dictionary`](#dictionary) | ||
* [Examples](#examples) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This is a English dictionary, | ||
generated by [`wooorm/dictionaries`][dictionaries] from | ||
generated by [`wooorm/dictionaries`][github-dictionaries] from | ||
[`wordlist.aspell.net`][source], | ||
@@ -17,7 +31,10 @@ normalized and packaged so that it can be installed and used like other | ||
You can use this package when integrating with tools that perform spell checking | ||
(such as [`nodehun`][nodehun], [`nspell`][nspell]) or when making such tools. | ||
(such as [`nodehun`][github-nodehun] or [`nspell`][github-nspell]) or when | ||
making such tools. | ||
## Install | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
This package is [ESM only][github-gist-esm]. | ||
In Node.js (version 16+), | ||
install with [npm][npm-install]: | ||
@@ -31,9 +48,6 @@ ```sh | ||
```js | ||
import dictionaryEn from 'dictionary-en' | ||
import en from 'dictionary-en' | ||
dictionaryEn(function (error, en) { | ||
if (error) throw error | ||
console.log(en) | ||
// To do: use `en` somehow | ||
}) | ||
console.log(en) | ||
// To do: use `en` somehow | ||
``` | ||
@@ -44,48 +58,78 @@ | ||
```js | ||
{dic: <Buffer>, aff: <Buffer>} | ||
{aff: <Buffer>, dic: <Buffer>} | ||
``` | ||
Where `dic` and `aff` are [`Buffer`][buffer]s for `index.dic` and `index.aff` | ||
respectively. | ||
## API | ||
This package exports no identifiers. | ||
The default export is a [`Dictionary`][api-dictionary]. | ||
It exports the [TypeScript][] type | ||
[`Dictionary`][api-dictionary]. | ||
### `Dictionary` | ||
[Hunspell][] dictionary. | ||
###### Fields | ||
* `aff` ([`Buffer`][node-buffer]) | ||
— data for the affix file (defines the language, keyboard, flags, and more) | ||
* `dic` ([`Buffer`][node-buffer]) | ||
— data for the dictionary file (contains words and flags applying to those | ||
words) | ||
## Examples | ||
See the [monorepo readme][dictionaries] for examples. | ||
See the [monorepo readme][github-dictionaries] for examples. | ||
## Types | ||
## Compatibility | ||
This package is typed with [TypeScript][]. | ||
This projects is compatible with maintained versions of Node.js. | ||
When we cut a new major release, | ||
we drop support for unmaintained versions of Node. | ||
This means we try to keep the current release line, | ||
compatible with Node.js 12. | ||
## Security | ||
This package is safe. | ||
## Contribute | ||
See the [monorepo readme][dictionaries] for how to contribute. | ||
See the [monorepo readme][github-dictionaries] for how to contribute. | ||
> 👉 **Note**: dictionaries are not maintained here. | ||
> Report spelling problems upstream ([`wordlist.aspell.net`][source]). | ||
> Report spelling problems upstream | ||
> ([`wordlist.aspell.net`][source]). | ||
## License | ||
Dictionary and affix file: [(MIT AND BSD)](https://github.com/wooorm/dictionaries/blob/main/dictionaries/en/license). | ||
Rest: [MIT][] © [Titus Wormer][home]. | ||
Dictionary and affix file: | ||
[(MIT AND BSD)](https://github.com/wooorm/dictionaries/blob/main/dictionaries/en/license). | ||
Rest: [MIT][file-license] © [Titus Wormer][wooorm]. | ||
[hunspell]: https://hunspell.github.io | ||
[api-dictionary]: #dictionary | ||
[nodehun]: https://github.com/nathanjsweet/nodehun | ||
[file-license]: https://github.com/wooorm/dictionaries/blob/main/license | ||
[nspell]: https://github.com/wooorm/nspell | ||
[github-dictionaries]: https://github.com/wooorm/dictionaries | ||
[macos]: https://github.com/wooorm/dictionaries#example-use-with-macos | ||
[github-gist-esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[source]: http://wordlist.aspell.net/dicts/ | ||
[github-nodehun]: https://github.com/nathanjsweet/nodehun | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[github-nspell]: https://github.com/wooorm/nspell | ||
[dictionaries]: https://github.com/wooorm/dictionaries | ||
[hunspell]: https://hunspell.github.io | ||
[mit]: https://github.com/wooorm/dictionaries/blob/main/license | ||
[node-buffer]: https://nodejs.org/api/buffer.html#buffer_buffer | ||
[buffer]: https://nodejs.org/api/buffer.html#buffer_buffer | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[home]: https://wooorm.com | ||
[source]: http://wordlist.aspell.net/dicts/ | ||
[typescript]: https://www.typescriptlang.org | ||
[wooorm]: https://wooorm.com |
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
575389
132
1
Yes
30