add types for lucene (#40074)

This commit is contained in:
Ben Grynhaus
2019-11-05 10:52:08 -08:00
committed by Nathan Shively-Sanders
parent b09b89241b
commit 2f8b27fdb0
4 changed files with 78 additions and 0 deletions
+49
View File
@@ -0,0 +1,49 @@
// Type definitions for lucene 2.1
// Project: https://github.com/bripkens/lucene#readme
// Definitions by: Ben Grynhaus <https://github.com/bengry>
// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
export interface TermLocation {
column: number;
line: number;
offset: number;
}
export interface Node {
boost: null | number;
field: string | '<implicit>';
fieldLocation: null;
prefix: null | string;
quoted: boolean;
regex: boolean;
similarity: null;
term: string;
termLocation: TermLocation;
}
export type Operator = '<implicit>' | 'NOT' | 'OR' | 'AND' | 'AND NOT' | 'OR NOT';
export interface LeftOnlyAST {
left: Node;
start?: Operator;
}
export interface BinaryAST {
left: AST | Node;
operator: Operator;
right: AST | Node;
}
export type AST = LeftOnlyAST | BinaryAST;
export function parse(query: string): AST;
export function toString(ast: AST): string;
export interface Parser {
escape(str: string): string;
unescape(str: string): string;
}
export const term: Parser;
export const phrase: Parser;
+12
View File
@@ -0,0 +1,12 @@
import * as lucene from 'lucene';
const ast = lucene.parse('query'); // $ExpectType AST
lucene.parse(1); // $ExpectError
lucene.toString(ast); // $ExpectType string
lucene.phrase.escape(''); // $ExpectType string
lucene.phrase.escape(1); // $ExpectError
lucene.phrase.unescape(''); // $ExpectType string
lucene.phrase.unescape(1); // $ExpectError
+16
View File
@@ -0,0 +1,16 @@
{
"compilerOptions": {
"module": "commonjs",
"lib": ["es6"],
"noImplicitAny": true,
"noImplicitThis": true,
"strictFunctionTypes": true,
"strictNullChecks": true,
"baseUrl": "../",
"typeRoots": ["../"],
"types": [],
"noEmit": true,
"forceConsistentCasingInFileNames": true
},
"files": ["index.d.ts", "lucene-tests.ts"]
}
+1
View File
@@ -0,0 +1 @@
{ "extends": "dtslint/dt.json" }