-
Notifications
You must be signed in to change notification settings - Fork 0
/
demo.js
65 lines (50 loc) · 1.55 KB
/
demo.js
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
const JsonPointerError = require('./json-pointer-error')
const fs = require('fs')
const demoJSONPath = `${__dirname}/demo.json`
const demoJsonString = fs.readFileSync(demoJSONPath).toString()
new JsonPointerError().displayJsonParsingError(
'Found some error in file:',
demoJSONPath
)
const errorSource = new JsonPointerError().setSource(demoJsonString)
errorSource.displayErrorAtPointer(
'this is not pointer at all',
'Invalid JSON pointer'
)
errorSource.displayErrorAtPointer(
'/0/balance',
'Pointing at property "balance"'
)
errorSource.displayErrorAtPointer(
'/2/about',
'Pointing at property "about" - shortening output'
)
errorSource.displayWarningAtPointer(
'/2/about',
'Pointing at property "about" - shortening output'
)
errorSource.displayErrorAtPointer(
'/1/friends/2/name',
'Pointing at deep property "name"'
)
errorSource.displayErrorAtPointer(
'/4',
'Pointing at whole root level object - shortening output'
)
errorSource.displayWarningAtPointer(
'/4',
'Pointing at whole root level object - shortening output'
)
errorSource.displayErrorAtPointer(
'/3/friends/2',
'Pointing at whole sub-object'
)
errorSource
.setPlainConsole()
.displayErrorAtPointer('/3/friends/2', 'Disabled colour output')
let myOutput = []
errorSource
.setOutputHandler(line => myOutput.push(line))
.displayErrorAtPointer('/3/friends/2', 'Custom output handler')
console.log(`Intercepted ${myOutput.length} lines of error log`)
console.log('==== ' + myOutput.join('\n==== '))