Skip to content

Commit

Permalink
Add types
Browse files Browse the repository at this point in the history
Closes GH-9.

Reviewed-by: Christian Murphy <[email protected]>
Reviewed-by: Titus Wormer <[email protected]>
  • Loading branch information
remcohaszing authored Apr 29, 2020
1 parent 2ef53d3 commit c82fbed
Show file tree
Hide file tree
Showing 7 changed files with 146 additions and 6 deletions.
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
coverage/
rehype-document.js
rehype-document.min.js
*.md
14 changes: 10 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,21 @@
"Titus Wormer <[email protected]> (https://wooorm.com)"
],
"files": [
"index.js"
"index.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"@types/hast": "^2.3.0",
"doctype": "^2.0.0",
"hastscript": "^5.0.0",
"unist-builder": "^2.0.0"
},
"devDependencies": {
"browserify": "^16.0.0",
"dtslint": "^3.4.2",
"nyc": "^15.0.0",
"prettier": "^1.0.0",
"prettier": "^2.0.5",
"rehype": "^9.0.0",
"remark-cli": "^7.0.0",
"remark-preset-wooorm": "^6.0.0",
Expand All @@ -45,13 +49,14 @@
"xo": "^0.28.0"
},
"scripts": {
"format": "remark . -qfo && prettier --write \"**/*.js\" && xo --fix",
"format": "remark . -qfo && prettier --write . && xo --fix",
"build-bundle": "browserify index.js -s rehypeDocument > rehype-document.js",
"build-mangle": "browserify index.js -s rehypeDocument -p tinyify > rehype-document.min.js",
"build": "npm run build-bundle && npm run build-mangle",
"test-api": "node test",
"test-coverage": "nyc --reporter lcov tape test.js",
"test": "npm run format && npm run build && npm run test-coverage"
"test-types": "dtslint types",
"test": "npm run format && npm run build && npm run test-coverage && npm run test-types"
},
"nyc": {
"check-coverage": true,
Expand All @@ -71,6 +76,7 @@
"prettier": true,
"esnext": false,
"ignores": [
"**/*.ts",
"rehype-document.js"
]
},
Expand Down
4 changes: 2 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ var test = require('tape')
var rehype = require('rehype')
var document = require('.')

test('document()', function(t) {
test('document()', function (t) {
t.equal(
rehype()
.data('settings', {fragment: true})
Expand Down Expand Up @@ -514,7 +514,7 @@ test('document()', function(t) {

t.equal(
rehype()
.use(function() {
.use(function () {
this.Parser = parser
function parser() {
return {
Expand Down
95 changes: 95 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Minimum TypeScript Version: 3.2
import {Plugin} from 'unified'
import {Properties} from 'hast'

/**
* Wrap a document around a fragment.
*/
declare const document: Plugin<[document.Options?]>

declare namespace document {
interface Options {
/**
* Text to use as title
*
* default: name of file, if any
*/
title?: string

/**
* Natural language of document.
*
* should be a [BCP 47](https://tools.ietf.org/html/bcp47) language tag.
*
* @default 'en'
*/
language?: string

/**
* Whether to insert a `meta[viewport]`.
*
* @default true
*/
responsive?: boolean

/**
* [Doctype](https://github.com/wooorm/doctype) to use.
*
* @default '5'
*/
doctype?: string

/**
* CSS to include in `head` in `<style>` elements.
*
* @default []
*/
style?: string | string[]

/**
* Links to stylesheets to include in `head`
*
* @default []
*/
css?: string | string[]

/**
* Metadata to include in `head`.
*
* Each object is passed as
* [`properties`](https://github.com/syntax-tree/hastscript#hselector-properties-children)
* to [`hastscript`](https://github.com/syntax-tree/hastscript) with a
* `meta` element.
*
* @default []
*/
meta?: Properties | Properties[]

/**
* Link tags to include in `head`.
*
* Each object is passed as
* [`properties`](https://github.com/syntax-tree/hastscript#hselector-properties-children)
* to [`hastscript`](https://github.com/syntax-tree/hastscript) with a `link` element.
*
* @default []
*/
link?: Properties | Properties[]

/**
* Inline scripts to include at end of `body`.
*
* @default []
*/
script?: string | string[]

/**
* External scripts to include at end of `body`
*
* @default []
*/
js?: string | string[]
}
}

export = document
20 changes: 20 additions & 0 deletions types/rehype-document-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import unified = require('unified')
import document = require('rehype-document')

unified().use(document)
unified().use(document, {title: ''})
unified().use(document, {language: ''})
unified().use(document, {responsive: false})
unified().use(document, {doctype: ''})
unified().use(document, {style: ''})
unified().use(document, {style: ['']})
unified().use(document, {css: ''})
unified().use(document, {css: ['']})
unified().use(document, {meta: {name: '', content: ''}})
unified().use(document, {meta: [{name: '', content: ''}]})
unified().use(document, {link: {name: '', content: ''}})
unified().use(document, {link: [{name: '', content: ''}]})
unified().use(document, {script: ''})
unified().use(document, {script: ['']})
unified().use(document, {js: ''})
unified().use(document, {js: ['']})
10 changes: 10 additions & 0 deletions types/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"compilerOptions": {
"lib": ["es2015"],
"strict": true,
"baseUrl": ".",
"paths": {
"rehype-document": ["index.d.ts"]
}
}
}
8 changes: 8 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"extends": "dtslint/dtslint.json",
"rules": {
"no-redundant-jsdoc": false,
"semicolon": false,
"whitespace": false
}
}

0 comments on commit c82fbed

Please sign in to comment.