mirror of
https://github.com/zhigang1992/DefinitelyTyped.git
synced 2026-04-22 20:39:17 +08:00
Add structured-source definitions
This commit is contained in:
29
types/structured-source/index.d.ts
vendored
Normal file
29
types/structured-source/index.d.ts
vendored
Normal 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;
|
||||
15
types/structured-source/structured-source-tests.ts
Normal file
15
types/structured-source/structured-source-tests.ts
Normal 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 }
|
||||
});
|
||||
23
types/structured-source/tsconfig.json
Normal file
23
types/structured-source/tsconfig.json
Normal 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"
|
||||
]
|
||||
}
|
||||
1
types/structured-source/tslint.json
Normal file
1
types/structured-source/tslint.json
Normal file
@@ -0,0 +1 @@
|
||||
{ "extends": "dtslint/dt.json" }
|
||||
Reference in New Issue
Block a user