-
-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathindex.d.ts
104 lines (77 loc) · 2.92 KB
/
index.d.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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
declare module 'data-store' {
interface Options {
/**Disabled by default. Milliseconds to delay writing the JSON file to the file system. This can make the store more performant by preventing multiple subsequent writes after calling .set or setting/getting store.data, but comes with the potential side effect that (when accessing the object directly) the persisted file might be outdated during the timeout. To get around this, use data-store's API to (re-)load the file instead of directly reading the file (using fs.readFile for example). */
debounce?: number
/* The indent value to pass to JSON.stringify() when writing the file to the fs, or when .json() is called */
indent?: number | null
/* The name to use for the store file stem (name + '.json' is the store's file name) */
name?: string
/* An optional property name to nest all values under. */
namespace?: string
/* The root home directory to use */
home?: string
/* The directory to use for persisting data-store config files. This value is joined to home */
base?: string
/* ... */
path?: string
}
type DataObject = Record<string, any>;
/**
* Initialize a new Store with the given name, options and default data.
*/
class Store {
constructor (name?: string, options?: Options, defaults?: any)
constructor (options?: Options, defaults?: any)
readonly data: DataObject
/**
* Assign value to key and save to the file system.
* Can be a key-value pair, array of objects, or an object.
*/
set: (key: string, val: any) => this
/**
* Add the given value to the array at key. Creates a new
* array if one doesn't exist, and only adds unique values to the array.
*/
union: (key: string, val: any) => this
/**
* Get the stored value of key.
*/
get: (key: string, fallback?: any) => any
/**
* Returns true if the specified key has a value.
*/
has: (key: string) => boolean
/**
* Returns true if the specified key exists.
*/
hasOwn: (key: string) => boolean
/**
* Delete one or more properties from the store.
*/
del: (...keys: string[]) => void
/**
* Return a clone of the store.data object.
*/
clone: () => DataObject
/**
* Reset store.data to an empty object.
*/
clear: () => void
/**
* Stringify the store. Takes the same arguments as JSON.stringify.
*/
json: (replacer?: ((this: any, key: string, value: any) => any) | (number | string)[] | null,
space?: string | number) => string
/**
* Calls .writeFile() to persist the store to the file system, after
* an optional debounce period. This method should probably not be
* called directly as it's used internally by other methods.
*/
save: () => void
/**
* Delete the store from the file system.
*/
unlink: () => void
}
export = Store
}