Skip to content

Commit

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

Reviewed-by: Christian Murphy <christian.murphy.42@gmail.com>
Reviewed-by: Titus Wormer <tituswormer@gmail.com>
  • Loading branch information
shanehandley authored and wooorm committed Nov 2, 2019
1 parent ff7d8bd commit 3c4d4a1
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 2 deletions.
9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,18 @@
"Titus Wormer <tituswormer@gmail.com> (https://wooorm.com)"
],
"files": [
"index.js"
"index.js",
"types/index.d.ts"
],
"types": "types/index.d.ts",
"dependencies": {
"is-empty": "^1.0.0"
},
"devDependencies": {
"@types/unist": "^2.0.3",
"browserify": "^16.0.0",
"chalk": "^2.3.0",
"dtslint": "^1.0.2",
"nyc": "^14.0.0",
"prettier": "^1.0.0",
"remark-cli": "^6.0.0",
Expand All @@ -41,7 +45,8 @@
"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": "npm run format && npm run build && npm run test-coverage",
"dtslint": "dtslint types"
},
"prettier": {
"tabWidth": 2,
Expand Down
27 changes: 27 additions & 0 deletions types/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// TypeScript Version: 3.0
import { Node } from 'unist';

export = inpect;

/*
* Unist utility to inspect the details of a Unist Node
*
* @param node Node to inspect
*/
declare function inpect(node: Node): string;

declare namespace inpect {
/**
* Inspect the given Node and include colors from the results
*
* @param node Node to inspect
*/
function color(node: Node): string;

/**
* Inspect the given Node and exclude colors from the results
*
* @param node Node to inspect
*/
function noColor(node: Node): string;
}
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": {
"unist-util-inspect": ["index.d.ts"]
}
}
}
3 changes: 3 additions & 0 deletions types/tslint.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "dtslint/dtslint.json"
}
30 changes: 30 additions & 0 deletions types/unist-util-inspect-tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import * as inspect from 'unist-util-inspect';

const node = {
type: 'node',
data: {
string: 'string',
number: 1,
object: {
key: 'value'
},
array: [],
boolean: true,
null: null
},
position: {
start: {
line: 1,
column: 1,
offset: 0
},
end: {
line: 1,
column: 4,
offset: 0
},
indent: [1]
}
};

const result: string = inspect(node);

0 comments on commit 3c4d4a1

Please sign in to comment.