-
Notifications
You must be signed in to change notification settings - Fork 5
/
Token.ts
63 lines (55 loc) · 1.18 KB
/
Token.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
* Copyright (c) 2019, J2 Innovations. All Rights Reserved
*/
/**
* Base token definitions.
*
* @module
*/
import { TokenType } from './TokenType'
import { HaysonVal } from '../core/hayson'
/**
* A token created when parsing a string.
*/
export interface Token {
/**
* @returns The type of token.
*/
type: TokenType
/**
* Returns true if the type matches this token's type.
*
* @param type The token type.
* @return True if the type matches.
*/
is(type: TokenType): boolean
/**
* Returns true if the object matches this one.
*
* @param type The token type.
* @param text The text.
* @return True if the objects are equal.
*/
equals(token: Token): boolean
/**
* @returns A string representation of the token.
*/
toString(): string
/**
* Encodes to an encoded zinc value that can be used
* in a haystack filter string.
*
* The encoding for a haystack filter is mostly zinc but contains
* some exceptions.
*
* @returns The encoded value that can be used in a haystack filter.
*/
toFilter(): string
/**
* @returns A JSON representation of the token.
*/
toJSON(): {
type: string
[prop: string]: string | string[] | HaysonVal
}
}