FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JSONFile/JSONFile.js at main · XTP3/JSONFile · GitHub
XTP3
/
JSONFile
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
0
Pull requests
0
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
JSONFile
/
JSONFile.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
28 lines (22 loc) · 864 Bytes
Breadcrumbs
JSONFile
/
JSONFile.js
Copy path
File metadata and controls
28 lines (22 loc) · 864 Bytes
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
const
fs
=
require
(
'fs'
)
.
promises
;
module
.
exports
=
class
JSONFile
{
constructor
(
path
,
jsonData
=
null
)
{
this
.
path
=
path
;
this
.
jsonData
=
jsonData
;
this
.
createFileIfNotExists
(
)
.
then
(
(
)
=>
{
console
.
log
(
`JSON file '
${
this
.
path
}
' is ready to use`
)
;
}
)
.
catch
(
(
err
)
=>
{
console
.
error
(
`Error creating JSON file '
${
this
.
path
}
':
${
err
}
`
)
;
}
)
;
}
async
createFileIfNotExists
(
)
{
try
{
await
fs
.
access
(
this
.
path
,
fs
.
constants
.
F_OK
)
;
}
catch
(
err
)
{
await
this
.
write
(
this
.
jsonData
||
{
}
)
;
}
}
read
=
async
(
)
=>
JSON
.
parse
(
await
fs
.
readFile
(
this
.
path
,
'utf8'
)
)
;
write
=
async
data
=>
fs
.
writeFile
(
this
.
path
,
JSON
.
stringify
(
data
,
null
,
2
)
)
;
modify
=
async
jsonData
=>
this
.
write
(
{
...
await
this
.
read
(
)
,
...
jsonData
}
)
;
}
Back
|
FazBrowse Home
|
New Git URL