FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
JsObjects/JavaScript/Firebase/parse-json-func.js at master · charliecalvert/JsObjects · GitHub
charliecalvert
/
JsObjects
Public
Notifications
You must be signed in to change notification settings
Fork
53
Star
22
Code
Issues
1
Pull requests
1
Actions
Projects
Wiki
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security and quality
Insights
Expand file tree
Breadcrumbs
JsObjects
/
JavaScript
/
Firebase
/
parse-json-func.js
Copy path
More file actions
More file actions
Latest commit
History
History
History
executable file
·
68 lines (58 loc) · 2.12 KB
Breadcrumbs
JsObjects
/
JavaScript
/
Firebase
/
parse-json-func.js
Copy path
File metadata and controls
executable file
·
68 lines (58 loc) · 2.12 KB
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
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
#!/usr/bin/env node
const
{
log
}
=
require
(
'console'
)
;
const
{
existsSync
,
readFileSync
}
=
require
(
'fs'
)
;
const
useDebug
=
false
;
function
colorTrace
(
msg
,
color
)
{
console
.
log
(
'================='
,
color
)
;
console
.
log
(
`Current directory:
${
process
.
cwd
(
)
}
`
)
;
// pwd
console
.
log
(
msg
)
;
}
// We pass in the name of audit.json;
// usually ~/temp/audit.json
// This function reads the file and returns the parsed JSON
async
function
parseJson
(
filename
)
{
// const filePath = path.join(__dirname, filename);
// console.log("parseJson filename: " + filename);
if
(
existsSync
(
filename
)
)
{
const
fileContents
=
readFileSync
(
filename
,
'utf8'
)
;
if
(
useDebug
)
{
// console.log('fileContents:', fileContents);
log
(
'filename:'
,
filename
)
;
}
// if this fails it's because ~/temp/audit.json
// is not a valid JSON file
return
JSON
.
parse
(
fileContents
)
;
}
console
.
error
(
'File does not exist:'
,
filename
)
;
return
null
;
}
// getAudit();
// Print the total number of vulnerabilities from audit.json
function
getAudit
(
auditName
)
{
if
(
useDebug
)
{
log
(
'in getAudit'
)
;
log
(
'in getAudit auditName'
,
auditName
)
;
log
(
'in getAudit argv[0]'
,
process
.
argv
[
0
]
)
;
log
(
'in getAudit argv[1]'
,
process
.
argv
[
1
]
)
;
log
(
'in getAudit argv[2]'
,
process
.
argv
[
2
]
)
;
log
(
'in getAudit argv[3]'
,
process
.
argv
[
3
]
)
;
log
(
'in getAudit argv2'
,
process
.
argv
[
2
]
)
;
}
try
{
parseJson
(
auditName
)
.
then
(
(
data
)
=>
{
/* if (data.metadata &&
data.metadata.vulnerabilities &&
data.metadata.vulnerabilities.total > 0) {
} */
if
(
data
.
metadata
&&
data
.
metadata
.
vulnerabilities
&&
data
.
metadata
.
vulnerabilities
.
total
>
0
)
{
console
.
log
(
'getAudit data:'
,
data
)
;
colorTrace
(
`Total vulnerabilities:
${
data
.
metadata
.
vulnerabilities
.
total
}
`
,
'red'
)
;
}
}
)
;
}
catch
(
err
)
{
console
.
error
(
'Failed to parse JSON:'
,
err
)
;
}
}
module
.
exports
=
{
getAudit
,
parseJson
,
colorTrace
}
;
Back
|
FazBrowse Home
|
New Git URL