-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.d.ts
70 lines (70 loc) · 2.6 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
/**
* A library for creating, updating, reading, and deleting key-value pairs for NodeJs
*
* Author: Kishan Nareshpal Jadav | https://kishannareshpal.github.io
*/
export default class Pairs {
private pairsFilePath;
/**
* Initializes setttings.
* Optional configurations on where to save and what the PairsJS file should be called, are all available.
*
* @param dir_path the directory where the settings file should be stored. (@default ./ root dir)
* @param name the name of the settings file. (@default pairs.json)
*/
constructor(dir_path?: string, name?: string);
/**
* Returns the settings as a json.
*/
toJSON(): JSON;
/**
* Add a new pair.
*
* @param key
* @param value
* @param allowsOverwrite @default true overwrites the value of an existing pair with the same key, if found, ofc.
* @throws if found a pair with the same key, and, allowsOverwrite is set to false.
*
*/
add(key: string, value: any, allowsOverwrite?: boolean): void;
/**
* Removes a pair, by the key.
*
* @param key the key of the pair you want to remove
* @returns true if succesfull, false if it could not be deleted.
* @throws if no pair matching the the provided key was found.
*/
remove(key: string): boolean;
/**
* Updates the value of a pair, by the key.
*
* @param key the key of the pair you want the value to be updated.
* @param newValue the new value for that pair
* @param allowsAdding allows the creation of a new pair if no pair found with the provided key.
* @throws if no pair with the provided key is found and the allowsAdding option is set to false.
*/
updateValue(key: string, newValue: any, allowsAdding?: boolean): boolean;
/**
* Renames a key of an existing pair without modifying its value.
*
* @param key the key you want to rename
* @throws if no pair is found with the provided key.
*/
renameKey(key: string, renamedKey: string): void;
/**
* Checks if a pair with the key exists.
*
* @param key the key of the pair.
* @returns true if found, otherwise false.
*/
has(key: string): boolean;
/**
* Get the value of a pair by it's key.
*
* @param key the key of the pair of which you want the value.
* @returns the value of the pair found.
* the defaultValue (if provided), when no pair is found.
* undefined if no pair is found and no defaultValue is provided.
*/
get(key: string, callbackFn: (value: any) => any, defaultValue?: any): any;
}