Skip to content

Commit

Permalink
Add strict types
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Nov 2, 2022
1 parent 3c81095 commit 245062c
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import fs from 'node:fs'
import process from 'node:process'
import {lancasterStemmer} from './index.js'

/** @type {Object.<string, unknown>} */
/** @type {Record<string, unknown>} */
const pack = JSON.parse(
String(fs.readFileSync(new URL('package.json', import.meta.url)))
)
Expand Down
3 changes: 2 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const vowels = /[aeiouy]/
* @property {number} type
*/

/** @type {Record<string, Array<RuleSet>>} */
const rules = {
a: [
{match: 'ia', replacement: '', type: intact},
Expand Down Expand Up @@ -184,7 +185,7 @@ export function lancasterStemmer(value) {
* @returns {string}
*/
function applyRules(value, isIntact) {
/** @type {Array.<RuleSet>} */
/** @type {Array<RuleSet>} */
const ruleset = rules[value.charAt(value.length - 1)]
let index = -1

Expand Down
4 changes: 3 additions & 1 deletion test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import assert from 'node:assert/strict'
import {exec} from 'node:child_process'
import fs from 'node:fs'
import {URL} from 'node:url'
import {PassThrough} from 'node:stream'
import test from 'tape'
import {lancasterStemmer as m} from './index.js'

/** @type {Object.<string, unknown>} */
/** @type {Record<string, unknown>} */
const pack = JSON.parse(
String(fs.readFileSync(new URL('package.json', import.meta.url)))
)
Expand Down Expand Up @@ -277,6 +278,7 @@ test('cli', function (t) {
t.deepEqual([error, stdout, stderr], [null, 'detest vil\n', ''], 'stdin')
})

assert(subprocess.stdin, 'expected `stdin` on child process')
input.pipe(subprocess.stdin)
input.write('detestable')
setImmediate(function () {
Expand Down
18 changes: 10 additions & 8 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
{
"include": ["*.js"],
"include": ["**/**.js"],
"exclude": ["coverage", "node_modules"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
"exactOptionalPropertyTypes": true,
"forceConsistentCasingInFileNames": true,
"lib": ["es2020"],
"module": "node16",
"newLine": "lf",
"skipLibCheck": true,
"strict": true,
"target": "es2020"
}
}

0 comments on commit 245062c

Please sign in to comment.