-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathhjson-js.javascript_cli.txt
72 lines (63 loc) · 4.04 KB
/
hjson-js.javascript_cli.txt
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
69
70
71
72
┏━━━━━━━━━━━━━━┓
┃ HJSON-JS ┃
┗━━━━━━━━━━━━━━┛
VERSION ==> #3.2.2
#Parse|serialize HJSON
#Browser, node.js, CLI
┌──────────┐
│ MAIN │
└──────────┘
HJSON.parse(STR[, OPTS])->VAL #OPTS:
# - dsf DSF_ARR
# - keepWsc BOOL (def: false): keep comments and blank lines
HJSON.stringify(VAL[, OPTS])->STR #OPTS:
# - dsf DSF_ARR
# - bracesSameLine BOOL (def: false): make opening brace of OBJ on same line as VAR
# - emitRootBraces BOOL (def: true): use root braces
# - separator BOOL (def: false): use commas
# - quotes STR:
# - "min" (def): avoid quotes when possible
# - "keys": quotes on VAR
# - "strings": quotes on STR
# - "all": quotes on VAR|STR
# - multiline STR: use ''' strings if:
# - "std" (def): contains newline
# - "no-tabs": contains newline but no tabs
# - "off": never
# - colors BOOL (def: false)
# - space NUM|STR (def: 2): indentation
# - keepWsc BOOL (def: false)
# - eol STR: EOL char (def: CR or CRLF)
# - condense NUM (def: 0, i.e. off): git object/arrays onto one line
# - sortProps BOOL (def: false)
DSF #Extension. Can create custom ones
DSF.name #STR
DSF.parse(STR)->VAL #Called on HJSON.parse(STR)
#Only called on (what could be interpreted as) unquoted STR
#Must return undefined if wants to skip
DSF.stringify(VAL)->STR #Called on HJSON.stringify(VAL)
#Called on each value, including OBJ|ARR and root|parents
#Must return undefined if wants to skip
#STR cannot be "", start with " or contain , [ ] { }
HJSON.dsf.math|hex|date() #Standard DSF (see HJSON format)
┌─────────┐
│ CLI │
└─────────┘
hjson [FILE] #Does HJSON.parse() + HJSON.stringify()
#I.e. can be used to convert JSON->HJSON, or reformat HJSON
#Def FILE: stdin
#Prints to stdout
+math|hex|date
-sl
-js
-quote=STR
-nocol
-rt
-cond=NUM #Like OPTS.dsf|bracesSameLine|separator|quotes|colors|keepWsc|condense
-j|c[=compact] #Does HJSON.parse() + JSON.stringify() instead
#I.e. can be used to convert HJSON->JSON
#Note that if HJSON contains DSF extensions:
# - one should do HJSON.parse() + HJSON.stringify() + JSON.stringify() instead,
# i.e. hjson +EXT | hjson -j|c
# - JSON will encode value as quoted STR, i.e. cannot be parsed back as DSF extension
#With 2|no-spaces indentation