mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-01 12:42:58 +08:00
feat(vfile-location): initial commit (#23088)
* feat(vfile-location): initial commit * fix: strings are allowed * docs: add descriptions
This commit is contained in:
25
types/vfile-location/index.d.ts
vendored
Normal file
25
types/vfile-location/index.d.ts
vendored
Normal 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;
|
||||
16
types/vfile-location/tsconfig.json
Normal file
16
types/vfile-location/tsconfig.json
Normal 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"]
|
||||
}
|
||||
3
types/vfile-location/tslint.json
Normal file
3
types/vfile-location/tslint.json
Normal file
@@ -0,0 +1,3 @@
|
||||
{
|
||||
"extends": "dtslint/dt.json"
|
||||
}
|
||||
7
types/vfile-location/vfile-location-tests.ts
Normal file
7
types/vfile-location/vfile-location-tests.ts
Normal 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);
|
||||
Reference in New Issue
Block a user