From e203822585d4d703a2ec382293292ea0b0118250 Mon Sep 17 00:00:00 2001 From: Titus Wormer Date: Mon, 19 Jul 2021 12:09:59 +0200 Subject: [PATCH] Use ESM --- ar-latn.js | 10 ++++------ en.js | 14 ++++++++------ es.js | 10 ++++------ factory.js | 18 +++++++----------- fr.js | 10 ++++------ index.js | 4 ++-- it.js | 10 ++++------ package.json | 14 +++++++++----- pt-br.js | 10 ++++------ script/build-table.js | 18 ++++++++---------- test.js | 10 ++++------ 11 files changed, 58 insertions(+), 70 deletions(-) diff --git a/ar-latn.js b/ar-latn.js index d5fcdcf..399bdcf 100644 --- a/ar-latn.js +++ b/ar-latn.js @@ -1,8 +1,6 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss/ar-latn.js' -var factory = require('./factory') +const retextProfanitiesArLatn = factory({lang: 'ar-latn', cuss}) -module.exports = factory({ - lang: 'ar-latn', - cuss: require('cuss/ar-latn') -}) +export default retextProfanitiesArLatn diff --git a/en.js b/en.js index 6c2c05e..1206e76 100644 --- a/en.js +++ b/en.js @@ -1,11 +1,11 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss' +import pluralize from 'pluralize' -var factory = require('./factory') - -module.exports = factory({ +const retextProfanitiesEn = factory({ lang: 'en', - cuss: require('cuss'), - pluralize: require('pluralize'), + cuss, + pluralize, // Misclassified singulars and plurals. ignorePluralize: [ 'children', @@ -18,3 +18,5 @@ module.exports = factory({ // List of values not to normalize. regular: ['hell'] }) + +export default retextProfanitiesEn diff --git a/es.js b/es.js index a4f3bb6..b7c911c 100644 --- a/es.js +++ b/es.js @@ -1,8 +1,6 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss/es.js' -var factory = require('./factory') +const retextProfanitiesEs = factory({lang: 'es', cuss}) -module.exports = factory({ - lang: 'es', - cuss: require('cuss/es') -}) +export default retextProfanitiesEs diff --git a/factory.js b/factory.js index ca81055..bec0718 100644 --- a/factory.js +++ b/factory.js @@ -1,11 +1,9 @@ -'use strict' - -var keys = require('object-keys') -var difference = require('lodash.difference') -var intersection = require('lodash.intersection') -var nlcstToString = require('nlcst-to-string') -var quotation = require('quotation') -var search = require('nlcst-search') +import keys from 'object-keys' +import difference from 'lodash.difference' +import intersection from 'lodash.intersection' +import nlcstToString from 'nlcst-to-string' +import quotation from 'quotation' +import search from 'nlcst-search' // Map of `cuss` ratings to prefixes. var prefixes = ['Be careful with', 'Reconsider using', 'Don’t use'] @@ -24,9 +22,7 @@ var comma = ',' var word = /\W+/g var dashLetter = /-([a-z])/g -module.exports = factory - -function factory(config) { +export function factory(config) { var lang = config.lang var regular = config.regular var pluralize = config.pluralize diff --git a/fr.js b/fr.js index e290655..0e17551 100644 --- a/fr.js +++ b/fr.js @@ -1,8 +1,6 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss/fr.js' -var factory = require('./factory') +const retextProfanitiesFr = factory({lang: 'fr', cuss}) -module.exports = factory({ - lang: 'fr', - cuss: require('cuss/fr') -}) +export default retextProfanitiesFr diff --git a/index.js b/index.js index 1ce65f7..7d967a3 100644 --- a/index.js +++ b/index.js @@ -1,3 +1,3 @@ -'use strict' +import retextProfanitiesEn from './en.js' -module.exports = require('./en') +export default retextProfanitiesEn diff --git a/it.js b/it.js index 7d92945..78b0731 100644 --- a/it.js +++ b/it.js @@ -1,8 +1,6 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss/it.js' -var factory = require('./factory') +const retextProfanitiesIt = factory({lang: 'it', cuss}) -module.exports = factory({ - lang: 'it', - cuss: require('cuss/it') -}) +export default retextProfanitiesIt diff --git a/package.json b/package.json index 33144df..0b5be0a 100644 --- a/package.json +++ b/package.json @@ -28,18 +28,21 @@ "Mathieu Jolivet", "Otacilio Saraiva Maia Neto " ], + "sideEffects": false, + "type": "module", + "main": "index.js", "files": [ - "index.js", - "factory.js", "ar-latn.js", "en.js", "es.js", + "factory.js", "fr.js", + "index.js", "it.js", "pt-br.js" ], "dependencies": { - "cuss": "^1.15.0", + "cuss": "^2.0.0", "lodash.difference": "^4.5.0", "lodash.intersection": "^4.4.0", "nlcst-search": "^2.0.0", @@ -57,7 +60,7 @@ "retext": "^7.0.0", "tape": "^5.0.0", "unist-builder": "^2.0.0", - "xo": "^0.37.0" + "xo": "^0.39.0" }, "scripts": { "format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", @@ -75,8 +78,9 @@ }, "xo": { "prettier": true, - "esnext": false, "rules": { + "no-var": "off", + "prefer-arrow-callback": "off", "unicorn/no-array-callback-reference": "off", "unicorn/prefer-includes": "off", "guard-for-in": "off" diff --git a/pt-br.js b/pt-br.js index 6524078..b84c15d 100644 --- a/pt-br.js +++ b/pt-br.js @@ -1,8 +1,6 @@ -'use strict' +import {factory} from './factory.js' +import {cuss} from 'cuss/pt-br.js' -var factory = require('./factory') +const retextProfanitiesPtBr = factory({lang: 'pt-br', cuss}) -module.exports = factory({ - lang: 'pt-br', - cuss: require('cuss/pt-br') -}) +export default retextProfanitiesPtBr diff --git a/script/build-table.js b/script/build-table.js index c5566b8..99c38fb 100644 --- a/script/build-table.js +++ b/script/build-table.js @@ -1,12 +1,8 @@ -'use strict' +import range from 'mdast-util-heading-range' +import u from 'unist-builder' +import {cuss} from 'cuss' -var range = require('mdast-util-heading-range') -var u = require('unist-builder') -var cuss = require('cuss') - -module.exports = table - -function table() { +export default function table() { return transformer } @@ -19,14 +15,16 @@ function transformer(tree) { ]) ] - Object.keys(cuss).forEach(function (phrase) { + let phrase + + for (phrase in cuss) { rows.push( u('tableRow', [ u('tableCell', [u('inlineCode', id(phrase))]), u('tableCell', [u('inlineCode', phrase)]) ]) ) - }) + } return [start].concat(u('table', rows), end) }) diff --git a/test.js b/test.js index 5ef5d8e..74daef6 100644 --- a/test.js +++ b/test.js @@ -1,9 +1,7 @@ -'use strict' - -var test = require('tape') -var retext = require('retext') -var french = require('./fr') -var english = require('.') +import test from 'tape' +import retext from 'retext' +import french from './fr.js' +import english from './index.js' test('profanities', function (t) { retext()