Skip to content

Commit 79ee1ad

Browse files
committed
Add JSDoc based types
1 parent a57fdd1 commit 79ee1ad

8 files changed

+52
-74
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
.DS_Store
2+
*.d.ts
23
*.log
34
coverage/
45
node_modules/

index.js

+20-4
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,26 @@
1+
/**
2+
* @typedef {import('vfile').VFile} VFile
3+
* @typedef {import('js-yaml').LoadOptions} LoadOptions
4+
*
5+
* @typedef Options VFile matter options
6+
* @property {boolean} [strip=false] Remove the YAML front matter from the file
7+
* @property {Omit<LoadOptions, 'filename'>} [yaml] Options for the YAML parser
8+
*/
9+
110
import buffer from 'is-buffer'
211
import {load} from 'js-yaml'
312

4-
export function matter(file, options) {
5-
var settings = options || {}
6-
var strip = settings.strip
7-
var yamlOptions = settings.yaml || {}
13+
/**
14+
* Parse the YAML front matter in a [`vfile`](https://github.com/vfile/vfile), and add it as `file.data.matter`.
15+
*
16+
* If no matter is found in the file, nothing happens, except that `file.data.matter` is set to an empty object (`{}`).
17+
* @param {VFile} file Virtual file
18+
* @param {Options} [options] Options
19+
* @returns The given `file`
20+
*/
21+
export function matter(file, options = {}) {
22+
var strip = options.strip
23+
var yamlOptions = options.yaml || {}
824
var doc = String(file)
925
var match = /^---(?:\r?\n|\r)(?:([\s\S]*)(?:\r?\n|\r))?---(?:\r?\n|\r|$)/.exec(
1026
doc

package.json

+16-8
Original file line numberDiff line numberDiff line change
@@ -27,31 +27,37 @@
2727
"sideEffects": false,
2828
"type": "module",
2929
"main": "index.js",
30-
"types": "types/index.d.ts",
30+
"types": "index.d.ts",
3131
"files": [
32-
"types/index.d.ts",
32+
"index.d.ts",
3333
"index.js"
3434
],
3535
"dependencies": {
36+
"@types/js-yaml": "^4.0.0",
3637
"is-buffer": "^2.0.0",
3738
"js-yaml": "^4.0.0"
3839
},
3940
"devDependencies": {
40-
"@types/js-yaml": "^4.0.0",
41+
"@types/tape": "^4.0.0",
4142
"c8": "^7.0.0",
4243
"prettier": "^2.0.0",
4344
"remark-cli": "^9.0.0",
4445
"remark-preset-wooorm": "^8.0.0",
46+
"rimraf": "^3.0.0",
4547
"tape": "^5.0.0",
4648
"to-vfile": "^7.0.0",
49+
"type-coverage": "^2.0.0",
50+
"typescript": "^4.0.0",
4751
"vfile": "^5.0.0",
4852
"xo": "^0.39.0"
4953
},
5054
"scripts": {
55+
"prepack": "npm run build && npm run format",
56+
"build": "rimraf \"*.d.ts\" && tsc && type-coverage",
5157
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix",
5258
"test-api": "node test.js",
5359
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js",
54-
"test": "npm run format && npm run test-coverage"
60+
"test": "npm run build && npm run format && npm run test-coverage"
5561
},
5662
"prettier": {
5763
"tabWidth": 2,
@@ -66,14 +72,16 @@
6672
"rules": {
6773
"no-var": "off",
6874
"prefer-arrow-callback": "off"
69-
},
70-
"ignores": [
71-
"types/"
72-
]
75+
}
7376
},
7477
"remarkConfig": {
7578
"plugins": [
7679
"preset-wooorm"
7780
]
81+
},
82+
"typeCoverage": {
83+
"atLeast": 100,
84+
"detail": true,
85+
"strict": true
7886
}
7987
}

tsconfig.json

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{
2+
"include": ["*.js"],
3+
"compilerOptions": {
4+
"target": "ES2020",
5+
"lib": ["ES2020"],
6+
"module": "ES2020",
7+
"moduleResolution": "node",
8+
"allowJs": true,
9+
"checkJs": true,
10+
"declaration": true,
11+
"emitDeclarationOnly": true,
12+
"allowSyntheticDefaultImports": true,
13+
"skipLibCheck": true
14+
}
15+
}

types/index.d.ts

-32
This file was deleted.

types/tsconfig.json

-10
This file was deleted.

types/tslint.json

-7
This file was deleted.

types/vfile-matter-tests.ts

-13
This file was deleted.

0 commit comments

Comments
 (0)