-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexample.js
More file actions
32 lines (23 loc) · 730 Bytes
/
Copy pathexample.js
File metadata and controls
32 lines (23 loc) · 730 Bytes
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
const lpadAlign = require('lpad-align')
const tokenize = require('./')
const chalk = require('chalk')
const obj = {
a: 12e5,
b: 'helloworld'
}
const tokens = tokenize(JSON.stringify(obj, null, 2))
const fmtPosition = (pos) => `${pos.lineno}:${pos.column}`
const types = tokenize.tokenizers.map((tokenizer) => chalk.yellow.bold(tokenizer.type))
console.log()
tokens.forEach((token) => {
const pos = token.position
const str = pos.start
? `L${fmtPosition(pos.start)}-${fmtPosition(pos.end)}`
: `L${fmtPosition(pos)}`
console.log(
lpadAlign(chalk.yellow.bold(token.type), types, 2) + lpadAlign(str, ['a'.repeat(9)], 2),
token.type === 'whitespace'
? ''
: chalk.blue(token.value)
)
})