-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathdeno_printf.deno.txt
51 lines (42 loc) · 2.56 KB
/
deno_printf.deno.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
┏━━━━━━━━━━━━━━━━━┓
┃ DENO_PRINTF ┃
┗━━━━━━━━━━━━━━━━━┛
VERSION ==> #Part of Deno
#sprintf (not printf()) is browser compatible, except %i %I %#v
@std/fmt/printf
sprintf(STR, ARG...)->STR2 #Apply template
printf(STR, ARG...) #Like console.log(sprintf(...))
%% #Escape %
%s #STR
%t #BOOL
%b #INT, as base 2
%o #INT, as base 8
%x %X #INT, as base 16
%f %F #FLOAT, decimal notation
%e %E #FLOAT, exponent notation
%g %G #FLOAT, decimal|exponent notation depending on size
%c #String.fromCodePoint('CHAR')
%T #typeof ARG
%j #JSON.stringify(ARG)
%i #Deno.inspect(ARG, { colors: true, depth|iterableLimit: Infinity })
%I #Same with OPTS.compact true
%v #ARG.toString()
%[FLAGS][NUM][.NUM2]CHAR #Min length NUM, max precision NUM2
#NUM[2] can be * to use next ARG
#With Deno.inspect(), precision is OPTS.depth if using %#v
FLAGS ==> #
+ #Prepend + to positive NUM
- #Left padding
0 #Padding with 0
# #With:
# - %b: prefix with 0b
# - %o: prefix with 0
# - %x %X: prefix with 0x
# - %g %G: keep trailing zeros
# - %v: use Deno.inspect(ARG)
SPACE #Insert space:
# - %x %X: between bytes
# - positive NUM: at beginning, for padding with negative NUMs
< #Apply on ARR items
%[NUM]CHAR #Actual brackets. Use ARG number NUM instead of next one (1-based)
#Can also be used for min length and max precision, if followed by *