Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update VFile #19583

Merged
merged 16 commits into from Sep 7, 2017
Merged
72 changes: 72 additions & 0 deletions types/vfile/index.d.ts
@@ -0,0 +1,72 @@
// Type definitions for vfile 2.2
// Project: https://github.com/vfile/vfile#readme
// Definitions by: Junyoung Choi <https://github.com/rokt33r>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped

/// <reference types="node" />

declare namespace vfile {
type Contents = string | Buffer;

interface Point {
line: number;
column: number;
}

interface Position {
start: Point;
end: Point;
}

interface VFileParams {
contents?: Contents;
path?: string;
basename?: string;
stem?: string;
extname?: string;
dirname?: string;
cwd?: string;
}

interface VFileError {
ruleId: string | null;
name: string;
file: string;
reason: string;
line: number | null;
column: number | null;
location: Position;
source: string | null;
fatal?: boolean | null;
}

type Message = (reason: string, position?: Point | Position, ruleId?: string) => VFileError;

type Fail = (reason?: string, position?: Point | Position, ruleId?: string) => void;

type Info = (reason?: string, position?: Point | Position, ruleId?: string) => void;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wooorm I've also found, position can be Point or Position. Do I understand right?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes! Or a Node!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed!


type ToString = (encoding?: BufferEncoding) => string;

interface VFile {
(input?: Contents | VFile | VFileParams): VFile;
message: Message;
fail: Fail;
info: Info;
history: string[];
data: {};
messages: VFileError[];
contents: Contents;
path?: string;
dirname?: string;
basename?: string;
stem?: string;
extname?: string;
cwd: string;
toString: ToString;
}
}

declare const vfile: vfile.VFile;

export = vfile;
23 changes: 23 additions & 0 deletions types/vfile/tsconfig.json
@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"target": "es2017",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"vfile-tests.ts"
]
}
1 change: 1 addition & 0 deletions types/vfile/tslint.json
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }
18 changes: 18 additions & 0 deletions types/vfile/vfile-tests.ts
@@ -0,0 +1,18 @@
import vfile = require("vfile");

const file = vfile({path: '~/example.txt', contents: 'Alpha *braavo* charlie.'});

file.path; // => '~/example.txt'
file.dirname; // => '~'

file.extname = '.md';

file.basename; // => 'example.md'

file.basename = 'index.text';

file.history; // => ['~/example.txt', '~/example.md', '~/index.text']

file.message('`braavo` is misspelt; did you mean `bravo`?', {line: 1, column: 8});

console.log(file.messages);