Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ node_modules
lib/
.nyc_output/
coverage/
tags
60 changes: 60 additions & 0 deletions src/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
declare module 'searchjs' {
interface Defaults {
negator?: boolean;
join?: string;
text?: boolean;
word?: boolean;
separator?: string;
propertySearch?: boolean;
propertySearchDepth?: number;
start?: boolean;
end?: boolean;
}

type SingleField = null | undefined | boolean | number | Date | string;
type Field = SingleField | SingleField[];

interface SearchPrimitiveRange {
from?: number | string;
gte?: number | string;
gt?: number | string;
to?: number | string;
lte?: number | string;
lt?: number | string;
}
type SearchPrimitiveValues = null | undefined | string | number | Date | boolean | SearchPrimitiveRange;

export type JoinValue = "OR" | "AND";

type SearchPrimitive = {
[key: string]: SearchPrimitiveValues | SearchPrimitiveValues[] | SearchPrimitive | SearchPrimitive[]
terms?: SearchPrimitive[];
_propertySearch?: boolean;
_propertySearchDepth?: number;
_not?: boolean | null;
_join?: JoinValue;
_text?: boolean;
_word?: boolean;
_start?: boolean;
_end?: boolean;
_separator?: string;
}

interface SearchObject {
[key: string]: Field | SearchObject
}

type SearchArray = SearchObject[] | undefined[];
type SearchData = SearchObject;

export function setDefaults(defaults: Defaults): void;
export function resetDefaults(): void;
export function singleMatch(field: Field,
s: SearchPrimitive,
text: Defaults["text"],
word: Defaults["word"],
start: Defaults["start"],
end: Defaults["end"]): boolean;
export function matchArray<T>(ary: T[], search: SearchPrimitive): T[];
export function matchObject<T>(object: T, search: SearchPrimitive): T;
}