Skip to content

Commit

Permalink
Change to use export map
Browse files Browse the repository at this point in the history
* refactor to move code to `lib/`
* remove extensions: `'retext-profanities/fr.js'` > `'retext-profanities/fr'`
  • Loading branch information
wooorm committed Sep 12, 2023
1 parent f3edafa commit a8be580
Show file tree
Hide file tree
Showing 15 changed files with 68 additions and 80 deletions.
10 changes: 0 additions & 10 deletions ar-latn.js

This file was deleted.

10 changes: 0 additions & 10 deletions es.js

This file was deleted.

10 changes: 0 additions & 10 deletions fr.js

This file was deleted.

5 changes: 0 additions & 5 deletions index.js

This file was deleted.

10 changes: 0 additions & 10 deletions it.js

This file was deleted.

10 changes: 10 additions & 0 deletions lib/ar-latn.js
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion factory.js → lib/create-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
6 changes: 3 additions & 3 deletions en.js → lib/en.js
Original file line number Diff line number Diff line change
@@ -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: [
Expand Down
10 changes: 10 additions & 0 deletions lib/es.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/fr.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/it.js
Original file line number Diff line number Diff line change
@@ -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
10 changes: 10 additions & 0 deletions lib/pt.js
Original file line number Diff line number Diff line change
@@ -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
29 changes: 11 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -116,6 +108,7 @@
"xo": {
"prettier": true,
"rules": {
"n/file-extension-in-import": "off",
"unicorn/prefer-at": "off",
"unicorn/prefer-string-replace-all": "off"
}
Expand Down
10 changes: 0 additions & 10 deletions pt.js

This file was deleted.

6 changes: 3 additions & 3 deletions test.js
Original file line number Diff line number Diff line change
@@ -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'
])
})
Expand Down

0 comments on commit a8be580

Please sign in to comment.