Skip to content

Commit

Permalink
Add docs to types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 7, 2022
1 parent f5c6a99 commit e0a607c
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 44 deletions.
3 changes: 3 additions & 0 deletions ar-latn.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of Arabic (Latin) profane words to a rating of sureness.
*/
export const cuss = {
"'attaï": 2,
'2adeeb': 2,
Expand Down
102 changes: 58 additions & 44 deletions build.js
Original file line number Diff line number Diff line change
@@ -1,48 +1,62 @@
import fs from 'node:fs'
/**
* @typedef {import('type-fest').PackageJson} PackageJson
*/

import assert from 'node:assert/strict'
import fs from 'node:fs/promises'
import path from 'node:path'

/** @type {{files: string[]}} */
const pkg = JSON.parse(String(fs.readFileSync('package.json')))

main()

async function main() {
const files = fs
.readdirSync('.')
.filter(
(fp) =>
path.extname(fp) === '.js' &&
path.basename(fp) !== 'build.js' &&
path.basename(fp) !== 'test.js'
)

let index = -1

while (++index < files.length) {
const fp = files[index]

if (!pkg.files.includes(fp)) {
throw new Error(fp + ' should be in `package.json`’s files')
}

/** @type {{cuss: Record<string, number>}} */
// eslint-disable-next-line no-await-in-loop
const mod = await import('./' + fp)
const input = mod.cuss
const keys = Object.keys(input).sort()
/** @type {Record<string, number>} */
const output = {}
let offset = -1

while (++offset < keys.length) {
output[keys[offset]] = input[keys[offset]]
}

fs.writeFileSync(
fp,
'export const cuss = ' + JSON.stringify(output, null, 2) + '\n'
)

console.log('✓ ' + fp + ' (' + keys.length + ')')
const languageNames = new Intl.DisplayNames(['en'], {type: 'language'})

const pkgUrl = new URL('package.json', import.meta.url)
/** @type {PackageJson} */
const pkg = JSON.parse(String(await fs.readFile(pkgUrl)))
assert('files' in pkg, 'expected `files` in `package.json`')

const files = await fs.readdir(new URL('./', import.meta.url))
const datasets = files.filter(
(fp) =>
path.extname(fp) === '.js' &&
path.basename(fp) !== 'build.js' &&
path.basename(fp) !== 'test.js'
)

let index = -1

/* eslint-disable no-await-in-loop */
while (++index < datasets.length) {
const basename = datasets[index]

if (!pkg.files.includes(basename)) {
throw new Error(basename + ' should be in `package.json`’s files')
}

const modUrl = new URL(basename, import.meta.url)
/** @type {{cuss: Record<string, number>}} */
const mod = await import(modUrl.href)
const input = mod.cuss
const keys = Object.keys(input).sort()
/** @type {Record<string, number>} */
const cuss = {}
let offset = -1

while (++offset < keys.length) {
cuss[keys[offset]] = input[keys[offset]]
}

const stem = path.basename(basename, path.extname(basename))
const code = stem === 'index' ? 'en' : stem
const language = languageNames.of(code)

await fs.writeFile(
basename,
'/**\n * Map of ' +
language +
' profane words to a rating of sureness.\n */\nexport const cuss = ' +
JSON.stringify(cuss, null, 2) +
'\n'
)

console.log('✓ ' + basename + ' (' + language + '; ' + keys.length + ')')
}
/* eslint-enable no-await-in-loop */
3 changes: 3 additions & 0 deletions es.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of Spanish profane words to a rating of sureness.
*/
export const cuss = {
abanto: 2,
abrazafarolas: 2,
Expand Down
3 changes: 3 additions & 0 deletions fr.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of French profane words to a rating of sureness.
*/
export const cuss = {
BLC: 2,
Bitembois: 2,
Expand Down
3 changes: 3 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of English profane words to a rating of sureness.
*/
export const cuss = {
abbo: 1,
abeed: 2,
Expand Down
3 changes: 3 additions & 0 deletions it.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of Italian profane words to a rating of sureness.
*/
export const cuss = {
allupare: 1,
allupata: 1,
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"remark-cli": "^11.0.0",
"remark-preset-wooorm": "^9.0.0",
"type-coverage": "^2.0.0",
"type-fest": "^3.0.0",
"typescript": "^4.0.0",
"xo": "^0.52.0"
},
Expand Down
3 changes: 3 additions & 0 deletions pt-pt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of European Portuguese profane words to a rating of sureness.
*/
export const cuss = {
anus: 1,
badalhoca: 2,
Expand Down
3 changes: 3 additions & 0 deletions pt.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
/**
* Map of Portuguese profane words to a rating of sureness.
*/
export const cuss = {
'Filha da puta': 2,
'Filho da puta': 2,
Expand Down

0 comments on commit e0a607c

Please sign in to comment.