forked from ehmicky/Notes
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpretty-format.javascript.txt
More file actions
78 lines (73 loc) · 5.23 KB
/
pretty-format.javascript.txt
File metadata and controls
78 lines (73 loc) · 5.23 KB
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
73
74
75
76
77
78
┏━━━━━━━━━━━━━━━━━━━┓
┃ PRETTY-FORMAT ┃
┗━━━━━━━━━━━━━━━━━━━┛
ALTERNATIVES ==> # - pretty-format (sometimes preferred)
# - util.inspect() (sometimes preferred)
# - concordance: Node.js only
# - jsfmt: not maintained
VERSION ==> #Same as Jest (monorepo)
format(VAL[, OPTS])->STR #Serializes JavaScript value.
#Output is human-friendly, not machine-friendly.
#As fast as JSON.stringify()
#Circular references -> [Circular]
#Handles most JavaScript types:
# - BOOL|NUM -> like JSON except:
# - -0 -> -0
# - BIGINT -> NUMn
# - SYM -> Symbol(STR)
# - undefined|null -> undefined|null
# - FUNC -> [Function NAME|anonymous]
# - DATE -> YYYY-MM-DDTHH:MM:SS.SSSZ or Date { NaN }
# - ERROR -> [NAME: MESSAGE]
# - REGEXP -> /REGEXP/FLAGS
# - ARR|ARRBUFFER|DATAVIEW|TYPED_ARR -> [VAL, ...]
# - OBJ -> CLASS {"KEY": VAL, ...}
# - own enumerable + SYMs
# - KEYs are sorted
# - MAP -> Map {KEY => VAL}
# - SET -> Set {VAL, ...}
# - WEAKMAP|WEAKSET -> WeakMap|WeakSet {}
#Also handles:
# - DOM types:
# - WINDOW -> 'Window'
# - DOM NODE (ELEM|TEXT|COMMENT_NODE|DOCUMENT_FRAGMENT) (requires PLUGIN plugins.DOMElement)
# - ELEM.dataset, ELEM.attributes, HTMLCOLL, NODELIST (requires PLUGIN plugins.DOMCollection)
# - React: RELEM (requires PLUGIN plugins.ReactElement)
# - Immutable: I* (requires PLUGIN plugins.Immutable)
# - Jest: custom MATCHER (requires PLUGIN plugins.AsymmetricMatcher)
#OPTS:
# - callToJSON BOOL (def: true): call OBJ.toJSON() if defined
# - escapeString BOOL (def: true): escape " \
# - escapeRegex BOOL (def: false)
# - indent NUM (def: 2)
# - maxDepth NUM (def: Infinity):
# - stops recursion at maxDepth
# - top level is depth 0, its children 1, etc.
# - maxWidth NUM (def: Infinity): max number of ARR elements
# - min BOOL (def: false):
# - no newlines nor indentation
# - no spaces around {} [] ,
# - does not print OBJ prototype name except for *Map|Set
# - compareKeys('KEY_A', 'KEY_B')->-1|0|1 (def: alphabetical)
# - returning 0 means keep same order
# - printBasicPrototype BOOL (def: false)
# - printFunctionName BOOL (def: true)
# - highlight BOOL (def: false):
# - color syntax highlighting
# - only with NODE|RELEM|TESTELEM
# - theme OBJ:
# - colors with highlight true
# - keys are: prop, value, content, comment, tag
# - values are CHALK 'STYLE' (see its doc)
# - default: { prop: 'yellow', value: 'green', content: 'reset', comment: 'gray', tag: 'cyan' }
# - plugins PLUGIN_ARR (def: [])
PLUGIN #Extend serialization for extra types
PLUGIN.test(VAL)->BOOL #If true, use that PLUGIN
PLUGIN.serialize(VAL, OPTS, STR, #Serialization logic:
NUM, ARR, FUNC)->STR # - STR is indentation
# - NUM is current depth
# - ARR are parents (for circular checks)
# - FUNC is like PRETTYFORMAT() for recursive printing
#OPTS also gets:
# - spaceInner|Outer STR: space outside|inside {} []
#Can throw