diff --git a/types/vfile-location/index.d.ts b/types/vfile-location/index.d.ts new file mode 100644 index 0000000000..e8ad37bc32 --- /dev/null +++ b/types/vfile-location/index.d.ts @@ -0,0 +1,25 @@ +// Type definitions for vfile-location 2.0 +// Project: https://github.com/vfile/vfile-location +// Definitions by: Ika +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped +// TypeScript Version: 2.4 + +import * as VFile from "vfile"; + +declare function vfileLocation(vfile: string | VFile.VFile<{}>): vfileLocation.Location; + +declare namespace vfileLocation { + interface Location { + /** + * Get the `offset` (`number`) for a line and column-based `position` in the bound file. + * Returns `-1` when given invalid or out of bounds input. + */ + toOffset(position: { line: number; column: number }): number; + /** + * Get the line and column-based `position` for `offset` in the bound file. + */ + toPosition(offset: number): { line: number; column: number; offset: number }; + } +} + +export = vfileLocation; diff --git a/types/vfile-location/tsconfig.json b/types/vfile-location/tsconfig.json new file mode 100644 index 0000000000..92cec7ddc0 --- /dev/null +++ b/types/vfile-location/tsconfig.json @@ -0,0 +1,16 @@ +{ + "compilerOptions": { + "module": "commonjs", + "lib": ["es6"], + "noImplicitAny": true, + "noImplicitThis": true, + "strictNullChecks": true, + "strictFunctionTypes": true, + "baseUrl": "../", + "typeRoots": ["../"], + "types": [], + "noEmit": true, + "forceConsistentCasingInFileNames": true + }, + "files": ["index.d.ts", "vfile-location-tests.ts"] +} diff --git a/types/vfile-location/tslint.json b/types/vfile-location/tslint.json new file mode 100644 index 0000000000..f93cf8562a --- /dev/null +++ b/types/vfile-location/tslint.json @@ -0,0 +1,3 @@ +{ + "extends": "dtslint/dt.json" +} diff --git a/types/vfile-location/vfile-location-tests.ts b/types/vfile-location/vfile-location-tests.ts new file mode 100644 index 0000000000..7419cbf069 --- /dev/null +++ b/types/vfile-location/vfile-location-tests.ts @@ -0,0 +1,7 @@ +import vfile = require("vfile"); +import vfileLocation = require("vfile-location"); + +const location = vfileLocation(vfile("foo\nbar\nbaz")); + +const position = location.toPosition(10); +const offset: number = location.toOffset(position);