Add structured-source definitions

This commit is contained in:
azu
2018-02-24 14:56:21 +09:00
parent 4e51c4ba5f
commit 345f0b4e17
4 changed files with 68 additions and 0 deletions

29
types/structured-source/index.d.ts vendored Normal file
View File

@@ -0,0 +1,29 @@
// Type definitions for structured-source 3.0
// Project: https://github.com/Constellation/structured-source
// Definitions by: azu <https://github.com/azu>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
declare namespace StructuredSource {
interface SourcePosition {
// Line number starts with 1.
line: number;
// Column number starts with 0.
column: number;
}
interface SourceLocation {
start: SourcePosition;
end: SourcePosition;
}
}
declare class StructuredSource {
/**
* @param source - source code text.
*/
constructor(source: string);
locationToRange(loc: StructuredSource.SourceLocation): [number, number];
rangeToLocation(range: [number, number]): StructuredSource.SourceLocation;
positionToIndex(pos: StructuredSource.SourcePosition): number;
indexToPosition(index: number): StructuredSource.SourcePosition;
}
export = StructuredSource;

View File

@@ -0,0 +1,15 @@
import StructuredSource = require('structured-source');
const src = new StructuredSource('aaa\u2028aaaa\u2029aaaaa\n');
// positionToIndex({ line: number, column: number) -> number
src.positionToIndex({ line: 1, column: 2 });
// indexToPosition(number) -> { line: number, column: number }
src.indexToPosition(2);
// rangeToLocation([ number, number ]) -> { start: { line: number, column: number}, end: { line: number, column: number } }
src.rangeToLocation([0, 2]);
// locationToRange({ start: { line: number, column: number}, end: { line: number, column: number } }) -> [ number, number ]
src.locationToRange({
start: { line: 1, column: 0 },
end: { line: 1, column: 2 }
});

View File

@@ -0,0 +1,23 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": [
"es6"
],
"noImplicitAny": true,
"noImplicitThis": true,
"strictNullChecks": true,
"strictFunctionTypes": true,
"baseUrl": "../",
"typeRoots": [
"../"
],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": [
"index.d.ts",
"structured-source-tests.ts"
]
}

View File

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