diff --git a/types/lucene/index.d.ts b/types/lucene/index.d.ts new file mode 100644 index 0000000000..120530f1b2 --- /dev/null +++ b/types/lucene/index.d.ts @@ -0,0 +1,49 @@ +// Type definitions for lucene 2.1 +// Project: https://github.com/bripkens/lucene#readme +// Definitions by: Ben Grynhaus +// Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped + +export interface TermLocation { + column: number; + line: number; + offset: number; +} + +export interface Node { + boost: null | number; + field: string | ''; + fieldLocation: null; + prefix: null | string; + quoted: boolean; + regex: boolean; + similarity: null; + term: string; + termLocation: TermLocation; +} + +export type Operator = '' | '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; diff --git a/types/lucene/lucene-tests.ts b/types/lucene/lucene-tests.ts new file mode 100644 index 0000000000..ef5a6d8c4d --- /dev/null +++ b/types/lucene/lucene-tests.ts @@ -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 diff --git a/types/lucene/tsconfig.json b/types/lucene/tsconfig.json new file mode 100644 index 0000000000..95695a086f --- /dev/null +++ b/types/lucene/tsconfig.json @@ -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"] +} diff --git a/types/lucene/tslint.json b/types/lucene/tslint.json new file mode 100644 index 0000000000..3db14f85ea --- /dev/null +++ b/types/lucene/tslint.json @@ -0,0 +1 @@ +{ "extends": "dtslint/dt.json" }