You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While `join` merges the content of an object into a file, `merge`
merges the content of two files into a third, that can be a
different file or one of the given two
Closes#5
Writing functions (`overwrite`and `join`) asks for a third and optional `indentationLevel` parameter, whose value determines how much space is used for indentation when the file is formatted.
76
+
Writing functions (`overwrite`, `merge`and `join`) asks for an optional `indentationLevel` parameter, whose value determines how much space is used for indentation when the file is formatted.
76
77
`JSON.stringify` is responsible for the formatting, so a value less than 1 indicates that no formatting is applied, and a value greater than 10 is ignored.
77
78
78
79
### Error Handling
79
80
80
81
When the functions fails they return a rejected promise with an error that can either be an instance of `JSONFileHandlerError`, if the error was caused by a misuse of the library, or of `Error` (actually is of [`SystemError`](https://nodejs.org/api/errors.html#errors_class_systemerror), but Node does not exposes the class so it can not be checked using `instanceof` operator), if it was caused by violating an operating system constraint, like reading a file that does not exist, or trying to write to a read-only file.
81
82
82
-
Both types of errors contains a `code` property that can be used to handle them.
83
+
Both types of errors contain the properties `path` (useful when you want to know which file caused the error when you are merging two files or iterating) and `code`, that can be used to handle them.
83
84
Bellow are the error codes that should be checked for each function, classified by kind:
84
85
85
86
-`read`
@@ -98,14 +99,23 @@ Bellow are the error codes that should be checked for each function, classified
98
99
-`'EPERM'`
99
100
-`'EMFILE'`
100
101
-`'EISDIR'`
102
+
-`merge`
103
+
-`JSONFileHandlerError`
104
+
-`'EMPTY_FILE'`
105
+
-`'NOT_A_JSON'`
106
+
-`SystemError`
107
+
-`'ENOENT'`
108
+
-`'EPERM'`
109
+
-`'EMFILE'`
110
+
-`'EISDIR'`
101
111
102
112
The error codes of `JSONFileHandlerError` are self explanatory, a more detailed explanation of `SystemError` error codes can be found inside [Node documentation](https://nodejs.org/api/errors.html#errors_common_system_errors). Also in the [examples section](#Examples).
103
113
104
114
## Examples
105
115
106
-
Functions can be executed using async/await or promises. `read` example uses promises while `join`example uses async/await.
116
+
Functions can be used with async/await or promises. `read` example uses promises while `join`and `merge` examples use async/await.
API documentation can be read at [https://sebastian-altamirano.github.io/json-file-handler/](https://sebastian-altamirano.github.io/json-file-handler/).
0 commit comments