Skip to content

Commit

Permalink
Add JSDoc based types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Aug 14, 2021
1 parent 5ae9a9f commit e00a876
Show file tree
Hide file tree
Showing 24 changed files with 495 additions and 218 deletions.
5 changes: 3 additions & 2 deletions .gitignore
@@ -1,7 +1,8 @@
.DS_Store
*.log
coverage/
node_modules/
packages/franc-all/index.js
packages/franc-min/index.js
.DS_Store
*.d.ts
*.log
yarn.lock
22 changes: 19 additions & 3 deletions package.json
Expand Up @@ -8,6 +8,10 @@
"author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)",
"type": "module",
"devDependencies": {
"@types/mdast": "^3.0.7",
"@types/parse-author": "^2.0.1",
"@types/tape": "^4.13.2",
"@unicode/unicode-14.0.0": "^1.0.0",
"alpha-sort": "^5.0.0",
"c8": "^7.0.0",
"hast-util-select": "^5.0.0",
Expand All @@ -25,21 +29,27 @@
"remark-lint-table-pipe-alignment": "^3.0.0",
"remark-preset-wooorm": "^9.0.0",
"remark-stringify": "^10.0.0",
"rimraf": "^3.0.2",
"speakers": "^2.0.0",
"tape": "^5.0.0",
"trigrams": "^5.0.0",
"type-coverage": "^2.18.0",
"type-fest": "^2.0.0",
"typescript": "^4.3.5",
"udhr": "^5.0.0",
"@unicode/unicode-14.0.0": "^1.0.0",
"unified": "^10.0.0",
"xo": "^0.39.0"
},
"scripts": {
"postinstall": "lerna bootstrap --no-ci",
"generate": "node script/build",
"build-packages": "node script/build.js",
"build-workspace": "lerna run build",
"build-monorepo": "rimraf \"script/**/*.d.ts\" \"test/**/*.d.ts\" && tsc && type-coverage",
"build": "npm run build-packages && npm run build-workspace && npm run build-monorepo",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node --conditions development test/index.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api",
"test": "npm run generate && npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand Down Expand Up @@ -79,5 +89,11 @@
false
]
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
1 change: 1 addition & 0 deletions packages/franc-all/data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/franc-all/expressions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions packages/franc-all/package.json
Expand Up @@ -12,17 +12,6 @@
"detect",
"guess"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"data.js",
"expressions.js",
"index.js"
],
"dependencies": {
"trigram-utils": "^2.0.0"
},
"repository": "https://github.com/wooorm/franc/tree/main/packages/franc-all",
"bugs": "https://github.com/wooorm/franc/issues",
"funding": {
Expand All @@ -37,5 +26,29 @@
"Dmitriy Sobolev <disobolev@icloud.com>",
"Jeff Huijsmans <jeffhuys@gmail.com>"
],
"xo": false
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"data.d.ts",
"data.js",
"expressions.d.ts",
"expressions.js",
"index.d.ts",
"index.js"
],
"dependencies": {
"trigram-utils": "^2.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/franc-all/tsconfig.json
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
34 changes: 21 additions & 13 deletions packages/franc-cli/index.js
@@ -1,4 +1,8 @@
#!/usr/bin/env node
/**
* @typedef {import('franc').Options} Options
*/

import {createRequire} from 'node:module'
import meow from 'meow'
import {franc, francAll} from 'franc'
Expand Down Expand Up @@ -49,30 +53,30 @@ const cli = meow(help(), {
const value = cli.input.join(' ').trim()
const flags = cli.flags

flags.minLength = Number(flags.minLength) || null

flags.whitelist = list(flags.whitelist)
flags.blacklist = list(flags.blacklist)
flags.only = flags.whitelist.concat(list(flags.only))
flags.ignore = flags.blacklist.concat(list(flags.ignore))
/** @type {Options} */
const options = {
minLength: Number(flags.minLength) || undefined,
// @ts-expect-error: legacy.
whitelist: list(flags.whitelist),
blacklist: list(flags.blacklist),
only: list(flags.only),
ignore: list(flags.ignore)
}

if (cli.input.length === 0) {
process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', (data) => {
detect(data.trim())
detect(String(data).trim())
})
} else {
detect(value)
}

/**
* @param {string} value
*/
function detect(value) {
const options = {
minLength: flags.minLength,
only: flags.only,
ignore: flags.ignore
}

if (flags.all) {
const results = francAll(value, options)
let index = -1
Expand Down Expand Up @@ -117,6 +121,10 @@ function help() {
].join('\n')
}

/**
* @param {string|undefined} value
* @returns {string[]}
*/
function list(value) {
return value ? String(value).split(',') : []
}
35 changes: 22 additions & 13 deletions packages/franc-cli/package.json
Expand Up @@ -13,18 +13,6 @@
"cli",
"bin"
],
"type": "module",
"main": "index.js",
"bin": {
"franc": "index.js"
},
"files": [
"index.js"
],
"dependencies": {
"franc": "^5.0.0",
"meow": "^10.0.0"
},
"repository": "https://github.com/wooorm/franc/tree/main/packages/franc-cli",
"bugs": "https://github.com/wooorm/franc/issues",
"funding": {
Expand All @@ -39,5 +27,26 @@
"Dmitriy Sobolev <disobolev@icloud.com>",
"Jeff Huijsmans <jeffhuys@gmail.com>"
],
"xo": false
"type": "module",
"main": "index.js",
"bin": {
"franc": "index.js"
},
"files": [
"index.js"
],
"dependencies": {
"franc": "^5.0.0",
"meow": "^10.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/franc-cli/tsconfig.json
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
1 change: 1 addition & 0 deletions packages/franc-min/data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/franc-min/expressions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

37 changes: 25 additions & 12 deletions packages/franc-min/package.json
Expand Up @@ -12,17 +12,6 @@
"detect",
"guess"
],
"sideEffects": false,
"type": "module",
"main": "index.js",
"files": [
"data.js",
"expressions.js",
"index.js"
],
"dependencies": {
"trigram-utils": "^2.0.0"
},
"repository": "https://github.com/wooorm/franc/tree/main/packages/franc-min",
"bugs": "https://github.com/wooorm/franc/issues",
"funding": {
Expand All @@ -37,5 +26,29 @@
"Dmitriy Sobolev <disobolev@icloud.com>",
"Jeff Huijsmans <jeffhuys@gmail.com>"
],
"xo": false
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"data.d.ts",
"data.js",
"expressions.d.ts",
"expressions.js",
"index.d.ts",
"index.js"
],
"dependencies": {
"trigram-utils": "^2.0.0"
},
"scripts": {
"build": "rimraf \"*.d.ts\" && tsc && type-coverage"
},
"xo": false,
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true,
"ignoreCatch": true
}
}
4 changes: 4 additions & 0 deletions packages/franc-min/tsconfig.json
@@ -0,0 +1,4 @@
{
"extends": "../../tsconfig.json",
"include": ["*.js"]
}
1 change: 1 addition & 0 deletions packages/franc/data.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/franc/expressions.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit e00a876

Please sign in to comment.