boma 2.0.0 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/readme.md +37 -3
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# Boma JSON helper
|
|
2
2
|
Super-simple helper for working with JSON
|
|
3
3
|
|
|
4
|
-
Work only in synchronous mode.
|
|
4
|
+
Work only in synchronous mode for now.
|
|
5
5
|
|
|
6
6
|
# Usage
|
|
7
7
|
|
|
@@ -14,10 +14,44 @@ logs = {
|
|
|
14
14
|
}
|
|
15
15
|
*/
|
|
16
16
|
|
|
17
|
-
saveJSON(filePath:
|
|
17
|
+
saveJSON({ filePath: '/test.json', objToSave: { any: {}, key: {} }, format: true, logSaving: false }); // Format for save line break's
|
|
18
|
+
/* Will save:
|
|
19
|
+
{
|
|
20
|
+
"any": {}, // saved line break's
|
|
21
|
+
"key": {}
|
|
22
|
+
}
|
|
23
|
+
*/
|
|
18
24
|
|
|
19
|
-
addToJSON('/support.log', { 6sdf89g7dghg: { any: "data" } });
|
|
25
|
+
addToJSON({ filePath: '/support.log', dataToAdd: { 6sdf89g7dghg: { any: "data" }}, format: false, logSaving: false });
|
|
20
26
|
/* Will save:
|
|
21
27
|
"{ "any": {}, "key": {}, "6sdf89g7dghg": { "any": "data" } }"
|
|
22
28
|
*/
|
|
23
29
|
```
|
|
30
|
+
|
|
31
|
+
## Types
|
|
32
|
+
```typescript
|
|
33
|
+
export type SerializablePrimitive = string | number | boolean | null;
|
|
34
|
+
export type SerializableArray = Serializable[];
|
|
35
|
+
export type SerializableObject = { [key: string]: Serializable };
|
|
36
|
+
export type Serializable = SerializablePrimitive | SerializableArray | SerializableObject;
|
|
37
|
+
|
|
38
|
+
export interface ReadJSONProps {
|
|
39
|
+
filePath: string;
|
|
40
|
+
parseJSON?: boolean;
|
|
41
|
+
createIfNotFound?: boolean | SerializableObject | SerializableArray; // Файл с чем создать, если не создан
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
export interface SaveJSONProps {
|
|
45
|
+
filePath: string;
|
|
46
|
+
objToSave: Serializable;
|
|
47
|
+
format?: boolean
|
|
48
|
+
logSaving?: boolean;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
export interface addToJSONProps {
|
|
52
|
+
filePath: string;
|
|
53
|
+
dataToAdd: SerializableObject | SerializableArray;
|
|
54
|
+
format?: boolean
|
|
55
|
+
logSaving?: boolean;
|
|
56
|
+
}
|
|
57
|
+
```
|