feat(vfile-location): initial commit (#23088)

* feat(vfile-location): initial commit

* fix: strings are allowed

* docs: add descriptions
This commit is contained in:
Ika
2018-01-24 02:27:49 +08:00
committed by Andy
parent e626e99df9
commit 09f0e72b83
4 changed files with 51 additions and 0 deletions

25
types/vfile-location/index.d.ts vendored Normal file
View File

@@ -0,0 +1,25 @@
// Type definitions for vfile-location 2.0
// Project: https://github.com/vfile/vfile-location
// Definitions by: Ika <https://github.com/ikatyang>
// 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;

View File

@@ -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"]
}

View File

@@ -0,0 +1,3 @@
{
"extends": "dtslint/dt.json"
}

View File

@@ -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);