diff --git a/package.json b/package.json index 1cc25fc..fb77ed8 100644 --- a/package.json +++ b/package.json @@ -16,14 +16,18 @@ "Titus Wormer (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", @@ -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, diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..b7f2d5d --- /dev/null +++ b/types/index.d.ts @@ -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; +} diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..b04789a --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,10 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "baseUrl": ".", + "paths": { + "unist-util-inspect": ["index.d.ts"] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..6490e53 --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dtslint.json" +} diff --git a/types/unist-util-inspect-tests.ts b/types/unist-util-inspect-tests.ts new file mode 100644 index 0000000..355ed27 --- /dev/null +++ b/types/unist-util-inspect-tests.ts @@ -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);