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 Apr 5, 2021
1 parent 01000eb commit 465e20b
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 4 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.DS_Store
*.d.ts
*.log
coverage/
node_modules/
Expand Down
21 changes: 19 additions & 2 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ var found = false

https.get(endpoint, onresult)

/**
* @param {import('http').IncomingMessage} response
*/
function onresult(response) {
response
.pipe(fs.createWriteStream('archive.zip'))
Expand All @@ -23,6 +26,10 @@ function onclose() {
yauzl.open('archive.zip', {lazyEntries: true}, onopen)
}

/**
* @param {Error?} error
* @param {import('yauzl').ZipFile?} archive
*/
function onopen(error, archive) {
bail(error)

Expand All @@ -31,6 +38,9 @@ function onopen(error, archive) {
archive.on('entry', onentry)
archive.on('end', onend)

/**
* @param {import('yauzl').Entry} entry
*/
function onentry(entry) {
if (path.basename(entry.fileName) !== 'AFINN-111.txt') {
return read()
Expand All @@ -40,15 +50,22 @@ function onopen(error, archive) {
archive.openReadStream(entry, onreadstream)
}

/**
* @param {Error?} error
* @param {import('stream').Readable?} rs
*/
function onreadstream(error, rs) {
bail(error)
rs.pipe(concat(onconcat))
rs.on('end', read)
}

function onconcat(x) {
/**
* @param {Buffer} buf
*/
function onconcat(buf) {
var data = {}
var rows = dsv.tsvParse('key\tvalue\n' + String(x))
var rows = dsv.tsvParse('key\tvalue\n' + String(buf))
var index = -1

while (++index < rows.length) {
Expand Down
21 changes: 19 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,39 @@
"sideEffects": false,
"type": "module",
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.d.ts",
"index.js"
],
"devDependencies": {
"@types/concat-stream": "^1.6.0",
"@types/d3-dsv": "^2.0.1",
"@types/node": "^14.14.37",
"@types/tape": "^4.0.0",
"@types/yauzl": "^2.9.1",
"bail": "^2.0.0",
"c8": "^7.0.0",
"concat-stream": "^1.0.0",
"concat-stream": "^2.0.0",
"d3-dsv": "^2.0.0",
"prettier": "^2.0.0",
"remark-cli": "^9.0.0",
"remark-preset-wooorm": "^8.0.0",
"rimraf": "^3.0.0",
"tape": "^5.0.0",
"type-coverage": "^2.0.0",
"typescript": "^4.0.0",
"xo": "^0.38.0",
"yauzl": "^2.0.0"
},
"scripts": {
"prepack": "npm run build && npm run format",
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
"generate": "node build",
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
"test-api": "node test.js",
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
"test": "npm run format && npm run test-coverage"
"test": "npm run build && npm run format && npm run test-coverage"
},
"prettier": {
"tabWidth": 2,
Expand All @@ -70,5 +82,10 @@
"plugins": [
"preset-wooorm"
]
},
"typeCoverage": {
"atLeast": 100,
"detail": true,
"strict": true
}
}
15 changes: 15 additions & 0 deletions tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"include": ["*.js"],
"compilerOptions": {
"target": "ES2020",
"lib": ["ES2020"],
"module": "ES2020",
"moduleResolution": "node",
"allowJs": true,
"checkJs": true,
"declaration": true,
"emitDeclarationOnly": true,
"allowSyntheticDefaultImports": true,
"skipLibCheck": true
}
}

0 comments on commit 465e20b

Please sign in to comment.