From a8be580d4fb7f29f52001541aea71f1c4bd44e16 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Tue, 12 Sep 2023 11:26:13 +0200 Subject: [PATCH] Change to use export map * refactor to move code to `lib/` * remove extensions: `'retext-profanities/fr.js'` > `'retext-profanities/fr'` --- ar-latn.js | 10 ---------- es.js | 10 ---------- fr.js | 10 ---------- index.js | 5 ----- it.js | 10 ---------- lib/ar-latn.js | 10 ++++++++++ factory.js => lib/create-plugin.js | 2 +- en.js => lib/en.js | 6 +++--- lib/es.js | 10 ++++++++++ lib/fr.js | 10 ++++++++++ lib/it.js | 10 ++++++++++ lib/pt.js | 10 ++++++++++ package.json | 29 +++++++++++------------------ pt.js | 10 ---------- test.js | 6 +++--- 15 files changed, 68 insertions(+), 80 deletions(-) delete mode 100644 ar-latn.js delete mode 100644 es.js delete mode 100644 fr.js delete mode 100644 index.js delete mode 100644 it.js create mode 100644 lib/ar-latn.js rename factory.js => lib/create-plugin.js (99%) rename en.js => lib/en.js (76%) create mode 100644 lib/es.js create mode 100644 lib/fr.js create mode 100644 lib/it.js create mode 100644 lib/pt.js delete mode 100644 pt.js diff --git a/ar-latn.js b/ar-latn.js deleted file mode 100644 index 13093cc..0000000 --- a/ar-latn.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -import {cuss} from 'cuss/ar-latn.js' -import {factory} from './factory.js' - -const retextProfanitiesArLatn = factory({cuss, lang: 'ar-latn'}) - -export default retextProfanitiesArLatn diff --git a/es.js b/es.js deleted file mode 100644 index 945c1e8..0000000 --- a/es.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -import {cuss} from 'cuss/es.js' -import {factory} from './factory.js' - -const retextProfanitiesEs = factory({cuss, lang: 'es'}) - -export default retextProfanitiesEs diff --git a/fr.js b/fr.js deleted file mode 100644 index d790981..0000000 --- a/fr.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -import {cuss} from 'cuss/fr.js' -import {factory} from './factory.js' - -const retextProfanitiesFr = factory({cuss, lang: 'fr'}) - -export default retextProfanitiesFr diff --git a/index.js b/index.js deleted file mode 100644 index ea59973..0000000 --- a/index.js +++ /dev/null @@ -1,5 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -export {default} from './en.js' diff --git a/it.js b/it.js deleted file mode 100644 index 7e230b5..0000000 --- a/it.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -import {cuss} from 'cuss/it.js' -import {factory} from './factory.js' - -const retextProfanitiesIt = factory({lang: 'it', cuss}) - -export default retextProfanitiesIt diff --git a/lib/ar-latn.js b/lib/ar-latn.js new file mode 100644 index 0000000..055545d --- /dev/null +++ b/lib/ar-latn.js @@ -0,0 +1,10 @@ +/** + * @typedef {import('./create-plugin.js').Options} Options + */ + +import {cuss} from 'cuss/ar-latn.js' +import {createPlugin} from './create-plugin.js' + +const retextProfanitiesArLatn = createPlugin({cuss, lang: 'ar-latn'}) + +export default retextProfanitiesArLatn diff --git a/factory.js b/lib/create-plugin.js similarity index 99% rename from factory.js rename to lib/create-plugin.js index c831077..7e19ebd 100644 --- a/factory.js +++ b/lib/create-plugin.js @@ -58,7 +58,7 @@ const emptyList = [] * @returns * Plugin. */ -export function factory(config) { +export function createPlugin(config) { const regular = config.regular || emptyList const words = unpack() const source = diff --git a/en.js b/lib/en.js similarity index 76% rename from en.js rename to lib/en.js index 9d892d5..3b80d74 100644 --- a/en.js +++ b/lib/en.js @@ -1,12 +1,12 @@ /** - * @typedef {import('./factory.js').Options} Options + * @typedef {import('./create-plugin.js').Options} Options */ import {cuss} from 'cuss' import pluralize from 'pluralize' -import {factory} from './factory.js' +import {createPlugin} from './create-plugin.js' -const retextProfanitiesEn = factory({ +const retextProfanitiesEn = createPlugin({ cuss, // Misclassified singulars and plurals. ignorePluralize: [ diff --git a/lib/es.js b/lib/es.js new file mode 100644 index 0000000..c750bc0 --- /dev/null +++ b/lib/es.js @@ -0,0 +1,10 @@ +/** + * @typedef {import('./create-plugin.js').Options} Options + */ + +import {cuss} from 'cuss/es.js' +import {createPlugin} from './create-plugin.js' + +const retextProfanitiesEs = createPlugin({cuss, lang: 'es'}) + +export default retextProfanitiesEs diff --git a/lib/fr.js b/lib/fr.js new file mode 100644 index 0000000..9b9fb7b --- /dev/null +++ b/lib/fr.js @@ -0,0 +1,10 @@ +/** + * @typedef {import('./create-plugin.js').Options} Options + */ + +import {cuss} from 'cuss/fr.js' +import {createPlugin} from './create-plugin.js' + +const retextProfanitiesFr = createPlugin({cuss, lang: 'fr'}) + +export default retextProfanitiesFr diff --git a/lib/it.js b/lib/it.js new file mode 100644 index 0000000..0e97865 --- /dev/null +++ b/lib/it.js @@ -0,0 +1,10 @@ +/** + * @typedef {import('./create-plugin.js').Options} Options + */ + +import {cuss} from 'cuss/it.js' +import {createPlugin} from './create-plugin.js' + +const retextProfanitiesIt = createPlugin({lang: 'it', cuss}) + +export default retextProfanitiesIt diff --git a/lib/pt.js b/lib/pt.js new file mode 100644 index 0000000..f438ec8 --- /dev/null +++ b/lib/pt.js @@ -0,0 +1,10 @@ +/** + * @typedef {import('./create-plugin.js').Options} Options + */ + +import {cuss} from 'cuss/pt.js' +import {createPlugin} from './create-plugin.js' + +const retextProfanitiesPtBr = createPlugin({cuss, lang: 'pt'}) + +export default retextProfanitiesPtBr diff --git a/package.json b/package.json index ec9047f..1510a08 100644 --- a/package.json +++ b/package.json @@ -30,25 +30,17 @@ ], "sideEffects": false, "type": "module", - "main": "index.js", - "types": "index.d.ts", + "exports": { + "./ar-latn": "./lib/ar-latn.js", + "./en": "./lib/en.js", + "./es": "./lib/es.js", + "./fr": "./lib/fr.js", + "./it": "./lib/it.js", + "./pt": "./lib/pt.js", + ".": "./lib/en.js" + }, "files": [ - "ar-latn.d.ts", - "ar-latn.js", - "en.d.ts", - "en.js", - "es.d.ts", - "es.js", - "factory.d.ts", - "factory.js", - "fr.d.ts", - "fr.js", - "index.d.ts", - "index.js", - "it.d.ts", - "it.js", - "pt.d.ts", - "pt.js" + "lib/" ], "dependencies": { "@types/nlcst": "^2.0.0", @@ -116,6 +108,7 @@ "xo": { "prettier": true, "rules": { + "n/file-extension-in-import": "off", "unicorn/prefer-at": "off", "unicorn/prefer-string-replace-all": "off" } diff --git a/pt.js b/pt.js deleted file mode 100644 index 0f5415a..0000000 --- a/pt.js +++ /dev/null @@ -1,10 +0,0 @@ -/** - * @typedef {import('./factory.js').Options} Options - */ - -import {cuss} from 'cuss/pt.js' -import {factory} from './factory.js' - -const retextProfanitiesPtBr = factory({cuss, lang: 'pt'}) - -export default retextProfanitiesPtBr diff --git a/test.js b/test.js index 782495e..2ebb98c 100644 --- a/test.js +++ b/test.js @@ -1,12 +1,12 @@ import assert from 'node:assert/strict' import test from 'node:test' import {retext} from 'retext' -import retextProfanitiesFrench from './fr.js' -import retextProfanities from './index.js' +import retextProfanitiesFrench from 'retext-profanities/fr' +import retextProfanities from 'retext-profanities' test('profanities', async function (t) { await t.test('should expose the public api', async function () { - assert.deepEqual(Object.keys(await import('./index.js')).sort(), [ + assert.deepEqual(Object.keys(await import('retext-profanities')).sort(), [ 'default' ]) })