diff --git a/package.json b/package.json index adeb0c5..8979471 100644 --- a/package.json +++ b/package.json @@ -20,28 +20,35 @@ "contributors": [ "Titus Wormer (https://wooorm.com)" ], + "types": "types/index.d.ts", "files": [ + "types/index.d.ts", "index.js" ], - "dependencies": {}, + "dependencies": { + "@types/unist": "^2.0.2" + }, "devDependencies": { "browserify": "^16.0.0", + "dtslint": "^0.4.2", "nyc": "^13.0.0", "prettier": "^1.12.1", "remark-cli": "^6.0.0", "remark-preset-wooorm": "^4.0.0", "tape": "^4.5.1", "tinyify": "^2.4.3", + "typescript": "^3.2.2", "xo": "^0.23.0" }, "scripts": { - "format": "remark . -qfo && prettier --write '**/*.js' && xo --fix", + "format": "remark . -qfo && prettier --write '**/*.{js,ts}' && xo --fix", "build-bundle": "browserify . -s unistUtilStringifyPosition > unist-util-stringify-position.js", "build-mangle": "browserify . -s unistUtilStringifyPosition -p tinyify > unist-util-stringify-position.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, diff --git a/types/index.d.ts b/types/index.d.ts new file mode 100644 index 0000000..8f31bc0 --- /dev/null +++ b/types/index.d.ts @@ -0,0 +1,9 @@ +// TypeScript Version: 3.0 + +import * as Unist from 'unist' + +declare function unistUtilStringifyPosition( + value: Unist.Node | Unist.Position | Unist.Point +): string + +export = unistUtilStringifyPosition diff --git a/types/tsconfig.json b/types/tsconfig.json new file mode 100644 index 0000000..7135808 --- /dev/null +++ b/types/tsconfig.json @@ -0,0 +1,14 @@ +{ + "compilerOptions": { + "lib": ["es2015"], + "strict": true, + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": ".", + "paths": { + "unist-util-stringify-position": ["index.d.ts"] + } + } +} diff --git a/types/tslint.json b/types/tslint.json new file mode 100644 index 0000000..22174ee --- /dev/null +++ b/types/tslint.json @@ -0,0 +1,14 @@ +{ + "extends": "dtslint/dtslint.json", + "rules": { + "callable-types": false, + "max-line-length": false, + "no-redundant-jsdoc": false, + "no-void-expression": false, + "only-arrow-functions": false, + "semicolon": false, + "unified-signatures": false, + "whitespace": false, + "interface-over-type-literal": false + } +} diff --git a/types/unist-util-stringify-position-tests.ts b/types/unist-util-stringify-position-tests.ts new file mode 100644 index 0000000..f4d2a36 --- /dev/null +++ b/types/unist-util-stringify-position-tests.ts @@ -0,0 +1,20 @@ +import stringify = require('unist-util-stringify-position') + +// Point +const stringValue: string = stringify({line: 2, column: 3}) // => '2:3' + +// Position +const stringValue2: string = stringify({ + start: {line: 2, column: 1}, + end: {line: 3, column: 1} +}) // => '2:1-3:1' + +// Node +const stringValue3: string = stringify({ + type: 'text', + value: '!', + position: { + start: {line: 5, column: 11}, + end: {line: 5, column: 12} + } +}) // => '5:11-5:12'