-
Notifications
You must be signed in to change notification settings - Fork 474
Expand file tree
/
Copy pathstdlib-content.jsonnet
More file actions
1809 lines (1787 loc) · 59.3 KB
/
stdlib-content.jsonnet
File metadata and controls
1809 lines (1787 loc) · 59.3 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
local html = import 'html.libsonnet';
{
intro: html.paragraphs([
|||
This page describes the functions available in Jsonnet's standard library, i.e. the object
implicitly bound to the <code>std</code> variable. Some of the standard library functions
can be implemented in Jsonnet. Their code can be found in the <tt>std.jsonnet</tt> file.
The behavior of some of the other functions, i.e. the ones that expose extra functionality
not otherwise available to programmers, is described formally in the <a href="/language/spec.html">specification</a>.
|||,
|||
The standard library is implicitly added to all Jsonnet programs by enclosing them in a
local construct. For example, if the program given by the user is <code>{x: "foo"}</code>,
then the actual code executed would be <code>local std = { ... }; {x: "foo"}</code>. The
functions in the standard library are all hidden fields of the <code>std</code> object.
|||,
|||
Note: Some of these functions marked available since v0.10.0 were actually available earlier.
|||,
]),
prefix: 'std',
groups: [
{
name: 'External Variables',
id: 'ext_vars',
fields: [
{
name: 'extVar',
params: ['x'],
availableSince: '0.10.0',
description: 'If an external variable with the given name was defined, return its string value. Otherwise, raise an error.',
},
],
},
{
name: 'Types and Reflection',
id: 'types_reflection',
fields: [
{
name: 'thisFile',
availableSince: '0.10.0',
description: 'Note that this is a field. It contains the current Jsonnet filename as a string.',
},
{
name: 'type',
params: ['x'],
availableSince: '0.10.0',
description: html.paragraphs([
|||
Return a string that indicates the type of the value. The possible return values are:
"array", "boolean", "function", "null", "number", "object", and "string".
|||,
|||
The following functions are also available and return a boolean:
<code>std.isArray(v)</code>, <code>std.isBoolean(v)</code>, <code>std.isFunction(v)</code>,
<code>std.isNumber(v)</code>, <code>std.isObject(v)</code>, and
<code>std.isString(v)</code>.
|||,
]),
},
{
name: 'length',
params: ['x'],
availableSince: '0.10.0',
description: |||
Depending on the type of the value given, either returns the number of elements in the
array, the number of codepoints in the string, the number of parameters in the function, or
the number of fields in the object. Raises an error if given a primitive value, i.e.
<code>null</code>, <code>true</code> or <code>false</code>.
|||,
},
{
name: 'prune',
params: ['a'],
availableSince: '0.10.0',
description: |||
Recursively remove all "empty" members of <code>a</code>. "Empty" is defined as zero
length `arrays`, zero length `objects`, or `null` values.
The argument <code>a</code> may have any type.
|||,
},
],
},
{
name: 'Mathematical Utilities',
id: 'math',
intro: [
|||
<p>
The following mathematical functions are available:
</p>
<ul>
<ul><code>std.abs(n)</code></ul>
<ul><code>std.sign(n)</code></ul>
<ul><code>std.max(a, b)</code></ul>
<ul><code>std.min(a, b)</code></ul>
<ul><code>std.pow(x, n)</code></ul>
<ul><code>std.exp(x)</code></ul>
<ul><code>std.log(x)</code></ul>
<ul><code>std.exponent(x)</code></ul>
<ul><code>std.mantissa(x)</code></ul>
<ul><code>std.floor(x)</code></ul>
<ul><code>std.ceil(x)</code></ul>
<ul><code>std.sqrt(x)</code></ul>
<ul><code>std.sin(x)</code></ul>
<ul><code>std.cos(x)</code></ul>
<ul><code>std.tan(x)</code></ul>
<ul><code>std.asin(x)</code></ul>
<ul><code>std.acos(x)</code></ul>
<ul><code>std.atan(x)</code></ul>
<ul><code>std.round(x)</code></ul>
<ul><code>std.isEven(x)</code></ul>
<ul><code>std.isOdd(x)</code></ul>
<ul><code>std.isInteger(x)</code></ul>
<ul><code>std.isDecimal(x)</code></ul>
</ul>
<p>
The function <code>std.mod(a, b)</code> is what the % operator is desugared to. It performs
modulo arithmetic if the left hand side is a number, or if the left hand side is a string,
it does Python-style string formatting with <code>std.format()</code>.
</p>
<p>
The functions <code>std.isEven(x)</code> and <code>std.isOdd(x)</code> use integral part of a
floating number to test for even or odd.
</p>
|||,
],
fields: [
{
name: 'clamp',
params: ['x', 'minVal', 'maxVal'],
availableSince: '0.15.0',
description: |||
Clamp a value to fit within the range [<code>minVal</code>, <code>maxVal</code>].
Equivalent to <code>std.max(minVal, std.min(x, maxVal))</code>.
|||,
examples: [
{
input: 'std.clamp(-3, 0, 5)',
output: std.clamp(-3, 0, 5),
},
{
input: 'std.clamp(4, 0, 5)',
output: std.clamp(4, 0, 5),
},
{
input: 'std.clamp(7, 0, 5)',
output: std.clamp(7, 0, 5),
},
],
},
],
},
{
name: 'Assertions and Debugging',
id: 'assertions_debugging',
fields: [
{
name: 'assertEqual',
params: ['a', 'b'],
availableSince: '0.10.0',
description: 'Ensure that <code>a == b</code>. Returns <code>true</code> or throws an error message.',
},
],
},
{
name: 'String Manipulation',
id: 'string',
fields: [
{
name: 'toString',
params: ['a'],
availableSince: '0.10.0',
description: |||
Convert the given argument to a string.
|||,
},
{
name: 'codepoint',
params: ['str'],
availableSince: '0.10.0',
description: |||
Returns the positive integer representing the unicode codepoint of the character in the
given single-character string. This function is the inverse of <code>std.char(n)</code>.
|||,
},
{
name: 'char',
params: ['n'],
availableSince: '0.10.0',
description: |||
Returns a string of length one whose only unicode codepoint has integer id <code>n</code>.
This function is the inverse of <code>std.codepoint(str)</code>.
|||,
},
{
name: 'substr',
params: ['str', 'from', 'len'],
availableSince: '0.10.0',
description: |||
Returns a string that is the part of <code>s</code> that starts at offset <code>from</code>
and is <code>len</code> codepoints long. If the string <code>s</code> is shorter than
<code>from+len</code>, the suffix starting at position <code>from</code> will be returned.
|||,
},
{
name: 'findSubstr',
params: ['pat', 'str'],
availableSince: '0.10.0',
description: |||
Returns an array that contains the indexes of all occurrences of <code>pat</code> in
<code>str</code>.
|||,
},
{
name: 'startsWith',
params: ['a', 'b'],
availableSince: '0.10.0',
description: |||
Returns whether the string a is prefixed by the string b.
|||,
},
{
name: 'endsWith',
params: ['a', 'b'],
availableSince: '0.10.0',
description: |||
Returns whether the string a is suffixed by the string b.
|||,
},
{
name: 'stripChars',
params: ['str', 'chars'],
availableSince: '0.15.0',
description: |||
Removes characters <code>chars</code> from the beginning and from the end of <code>str</code>.
|||,
examples: [
{
input: 'std.stripChars(" test test test ", " ")',
output: std.stripChars(' test test test ', ' '),
},
{
input: 'std.stripChars("aaabbbbcccc", "ac")',
output: std.stripChars('aaabbbbcccc', 'ac'),
},
{
input: 'std.stripChars("cacabbbbaacc", "ac")',
output: std.stripChars('cacabbbbaacc', 'ac'),
},
],
},
{
name: 'lstripChars',
params: ['str', 'chars'],
availableSince: '0.15.0',
description: |||
Removes characters <code>chars</code> from the beginning of <code>str</code>.
|||,
examples: [
{
input: 'std.lstripChars(" test test test ", " ")',
output: std.lstripChars(' test test test ', ' '),
},
{
input: 'std.lstripChars("aaabbbbcccc", "ac")',
output: std.lstripChars('aaabbbbcccc', 'ac'),
},
{
input: 'std.lstripChars("cacabbbbaacc", "ac")',
output: std.lstripChars('cacabbbbaacc', 'ac'),
},
],
},
{
name: 'rstripChars',
params: ['str', 'chars'],
availableSince: '0.15.0',
description: |||
Removes characters <code>chars</code> from the end of <code>str</code>.
|||,
examples: [
{
input: 'std.rstripChars(" test test test ", " ")',
output: std.rstripChars(' test test test ', ' '),
},
{
input: 'std.rstripChars("aaabbbbcccc", "ac")',
output: std.rstripChars('aaabbbbcccc', 'ac'),
},
{
input: 'std.rstripChars("cacabbbbaacc", "ac")',
output: std.rstripChars('cacabbbbaacc', 'ac'),
},
],
},
{
name: 'split',
params: ['str', 'c'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Split the string <code>str</code> into an array of strings, divided by the string
<code>c</code>.
|||),
html.p({}, |||
Note: Versions up to and including 0.18.0 require <code>c</code> to be a single character.
|||),
],
examples: [
{
input: @'std.split("foo/_bar", "/_")',
output: std.split('foo/_bar', '/_'),
},
{
input: @'std.split("/_foo/_bar", "/_")',
output: std.split('/_foo/_bar', '/_'),
},
],
},
{
name: 'splitLimit',
params: ['str', 'c', 'maxsplits'],
availableSince: '0.10.0',
description: [
html.p({}, |||
As <code>std.split(str, c)</code> but will stop after <code>maxsplits</code> splits, thereby the largest
array it will return has length <code>maxsplits + 1</code>. A limit of <code>-1</code> means unlimited.
|||),
html.p({}, |||
Note: Versions up to and including 0.18.0 require <code>c</code> to be a single character.
|||),
],
examples: [
{
input: @'std.splitLimit("foo/_bar", "/_", 1)',
output: std.splitLimit('foo/_bar', '/_', 1),
},
{
input: @'std.splitLimit("/_foo/_bar", "/_", 1)',
output: std.splitLimit('/_foo/_bar', '/_', 1),
},
],
},
{
name: 'splitLimitR',
params: ['str', 'c', 'maxsplits'],
availableSince: '0.19.0',
description: 'As <code>std.splitLimit(str, c, maxsplits)</code> but will split from right to left.',
examples: [
{
input: @'std.splitLimitR("/_foo/_bar", "/_", 1)',
output: std.splitLimitR('/_foo/_bar', '/_', 1),
},
],
},
{
name: 'strReplace',
params: ['str', 'from', 'to'],
availableSince: '0.10.0',
description: |||
Returns a copy of the string in which all occurrences of string <code>from</code> have been
replaced with string <code>to</code>.
|||,
examples: [
{
input: @"std.strReplace('I like to skate with my skateboard', 'skate', 'surf')",
output: std.strReplace('I like to skate with my skateboard', 'skate', 'surf'),
},
],
},
{
name: 'isEmpty',
params: ['str'],
availableSince: '0.20.0',
description: |||
Returns true if the the given string is of zero length.
|||,
},
{
name: 'trim',
params: ['str'],
availableSince: 'upcoming',
description: |||
Returns a copy of string after eliminating leading and trailing whitespaces.
|||,
},
{
name: 'match',
params: ['str', 'pat'],
availableSince: 'upcoming',
description: |||
Matches the given <code>str</code> using <code>pat</code> as regexp pattern and returns an array of the matches.
|||,
},
{
name: 'equalsIgnoreCase',
params: ['str1', 'str2'],
availableSince: 'upcoming',
description: |||
Returns true if the the given <code>str1</code> is equal to <code>str2</code> by doing case insensitive comparison, false otherwise.
|||,
},
{
name: 'asciiUpper',
params: ['str'],
availableSince: '0.10.0',
description: |||
Returns a copy of the string in which all ASCII letters are capitalized.
|||,
examples: [
{
input: "std.asciiUpper('100 Cats!')",
output: std.asciiUpper('100 Cats!'),
},
],
},
{
name: 'asciiLower',
params: ['str'],
availableSince: '0.10.0',
description: |||
Returns a copy of the string in which all ASCII letters are lower cased.
|||,
examples: [
{
input: "std.asciiLower('100 Cats!')",
output: std.asciiLower('100 Cats!'),
},
],
},
{
name: 'stringChars',
params: ['str'],
availableSince: '0.10.0',
description: |||
Split the string <code>str</code> into an array of strings, each containing a single
codepoint.
|||,
examples: [
{
input: 'std.stringChars("foo")',
output: std.stringChars('foo'),
},
],
},
{
name: 'format',
params: ['str', 'vals'],
availableSince: '0.10.0',
description: |||
Format the string <code>str</code> using the values in <code>vals</code>. The values can be
an array, an object, or in other cases are treated as if they were provided in a singleton
array. The string formatting follows the <a
href="https://docs.python.org/2/library/stdtypes.html#string-formatting">same rules</a> as
Python. The <code>%</code> operator can be used as a shorthand for this function.
|||,
examples: [
{
input: 'std.format("Hello %03d", 12)',
output: std.format('Hello %03d', 12),
},
{
input: '"Hello %03d" % 12',
output: 'Hello %03d' % 12,
},
{
input: '"Hello %s, age %d" % ["Foo", 25]',
output: 'Hello %s, age %d' % ['Foo', 25],
},
{
input: '"Hello %(name)s, age %(age)d" % {age: 25, name: "Foo"}',
output: 'Hello %(name)s, age %(age)d' % { age: 25, name: 'Foo' },
},
],
},
{
name: 'escapeStringBash',
params: ['str'],
availableSince: '0.10.0',
description: |||
Wrap <code>str</code> in single quotes, and escape any single quotes within <code>str</code>
by changing them to a sequence <tt>'"'"'</tt>. This allows injection of arbitrary strings
as arguments of commands in bash scripts.
|||,
},
{
name: 'escapeStringDollars',
params: ['str'],
availableSince: '0.10.0',
description: |||
Convert $ to $$ in <code>str</code>. This allows injection of arbitrary strings into
systems that use $ for string interpolation (like Terraform).
|||,
},
{
name: 'escapeStringJson',
params: ['str'],
availableSince: '0.10.0',
description: |||
Convert <code>str</code> to allow it to be embedded in a JSON representation, within a
string. This adds quotes, escapes backslashes, and escapes unprintable characters.
|||,
examples: [
{
input: |||
local description = "Multiline\nc:\\path";
"{name: %s}" % std.escapeStringJson(description)
|||,
output: (
local description = 'Multiline\nc:\\path';
'{name: %s}' % std.escapeStringJson(description)
),
},
],
},
{
name: 'escapeStringPython',
params: ['str'],
availableSince: '0.10.0',
description: |||
Convert <code>str</code> to allow it to be embedded in Python. This is an alias for
<code>std.escapeStringJson</code>.
|||,
},
{
name: 'escapeStringXml',
params: ['str'],
availableSince: '0.10.0',
description: |||
Convert <code>str</code> to allow it to be embedded in XML (or HTML). The following replacements are made:
<pre>
{
"<": "&lt;",
">": "&gt;",
"&": "&amp;",
"\"": "&quot;",
"'": "&apos;",
}
</pre>
|||,
},
],
},
{
name: 'Parsing',
id: 'parsing',
fields: [
{
name: 'parseInt',
params: ['str'],
availableSince: '0.10.0',
description: |||
Parses a signed decimal integer from the input string.
|||,
examples: [
{
input: 'std.parseInt("123")',
output: std.parseInt('123'),
},
{
input: 'std.parseInt("-123")',
output: std.parseInt('-123'),
},
],
},
{
name: 'parseOctal',
params: ['str'],
availableSince: '0.10.0',
description: |||
Parses an unsigned octal integer from the input string. Initial zeroes are tolerated.
|||,
examples: [
{
input: 'std.parseOctal("755")',
output: std.parseOctal('755'),
},
],
},
{
name: 'parseHex',
params: ['str'],
availableSince: '0.10.0',
description: |||
Parses an unsigned hexadecimal integer, from the input string. Case insensitive.
|||,
examples: [
{
input: 'std.parseHex("ff")',
output: std.parseHex('ff'),
},
],
},
{
name: 'parseJson',
params: ['str'],
availableSince: '0.13.0',
description: |||
Parses a JSON string.
|||,
examples: [
{
input: 'std.parseJson(\'{"foo": "bar"}\')',
output: std.parseJson('{"foo": "bar"}'),
},
],
},
{
name: 'parseYaml',
params: ['str'],
availableSince: '0.18.0',
description: |||
Parses a YAML string. This is provided as a "best-effort" mechanism and should not be relied on to provide
a fully standards compliant YAML parser. YAML is a superset of JSON, consequently "downcasting" or
manifestation of YAML into JSON or Jsonnet values will only succeed when using the subset of YAML that is
compatible with JSON. The parser does not support YAML documents with scalar values at the root. The
root node of a YAML document must start with either a YAML sequence or map to be successfully parsed.
|||,
examples: [
{
input: "std.parseYaml('foo: bar')",
output: std.parseYaml('foo: bar'),
},
],
},
{
name: 'encodeUTF8',
params: ['str'],
availableSince: '0.13.0',
description: |||
Encode a string using <a href="https://en.wikipedia.org/wiki/UTF-8">UTF8</a>. Returns an array of numbers
representing bytes.
|||,
},
{
name: 'decodeUTF8',
params: ['arr'],
availableSince: '0.13.0',
description: |||
Decode an array of numbers representing bytes using <a href="https://en.wikipedia.org/wiki/UTF-8">UTF8</a>.
Returns a string.
|||,
},
],
},
{
name: 'Manifestation',
id: 'manifestation',
// TODO(sbarzowski): Clean up the example's representation
fields: [
{
name: 'manifestIni',
params: ['ini'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given structure to a string in <a href="https://en.wikipedia.org/wiki/INI_file">INI format</a>. This
allows using Jsonnet's
object model to build a configuration to be consumed by an application expecting an INI
file. The data is in the form of a set of sections, each containing a key/value mapping.
These examples should make it clear:
|||),
html.pre({}, |||
{
main: { a: "1", b: "2" },
sections: {
s1: {x: "11", y: "22", z: "33"},
s2: {p: "yes", q: ""},
empty: {},
}
}
|||),
html.p({}, |||
Yields a string containing this INI file:
|||),
html.pre({}, |||
a = 1
b = 2
[empty]
[s1]
x = 11
y = 22
z = 33
[s2]
p = yes
q =
|||),
],
},
{
name: 'manifestPython',
params: ['v'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given value to a JSON-like form that is compatible with Python. The chief
differences are True / False / None instead of true / false / null.
|||),
html.pre({}, |||
{
b: ["foo", "bar"],
c: true,
d: null,
e: { f1: false, f2: 42 },
}
|||),
html.p({}, |||
Yields a string containing Python code like:
|||),
html.pre({}, |||
{
"b": ["foo", "bar"],
"c": True,
"d": None,
"e": {"f1": False, "f2": 42}
}
|||),
],
},
{
name: 'manifestPythonVars',
params: ['conf'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given object to a JSON-like form that is compatible with Python. The key
difference to <code>std.manifestPython</code> is that the top level is represented as a list
of Python global variables.
|||),
html.pre({}, |||
{
b: ["foo", "bar"],
c: true,
d: null,
e: { f1: false, f2: 42 },
}
|||),
html.p({}, |||
Yields a string containing this Python code:
|||),
html.pre({}, |||
b = ["foo", "bar"]
c = True
d = None
e = {"f1": False, "f2": 42}
|||),
],
},
{
name: 'manifestJsonEx',
params: ['value', 'indent', 'newline', 'key_val_sep'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given object to a JSON form. <code>indent</code> is a string containing
one or more whitespaces that are used for indentation. <code>newline</code> is
by default <code>\n</code> and is inserted where a newline would normally be used
to break long lines. <code>key_val_sep</code> is used to separate the key and value
of an object field:
|||),
],
examples: [
{
input: |||
std.manifestJsonEx(
{
x: [1, 2, 3, true, false, null,
"string\nstring"],
y: { a: 1, b: 2, c: [1, 2] },
}, " ")
|||,
output:
std.manifestJsonEx(
{
x: [
1,
2,
3,
true,
false,
null,
'string\nstring',
],
y: { a: 1, b: 2, c: [1, 2] },
}, ' '
),
},
{
input: |||
std.manifestJsonEx(
{
x: [1, 2, "string\nstring"],
y: { a: 1, b: [1, 2] },
}, "", " ", " : ")
|||,
output:
std.manifestJsonEx(
{
x: [1, 2, 'string\nstring'],
y: { a: 1, b: [1, 2] },
}, '', ' ', ' : '
),
},
],
},
{
name: 'manifestJsonMinified',
params: ['value'],
availableSince: '0.18.0',
description: |||
Convert the given object to a minified JSON form. Under the covers,
it calls <code>std.manifestJsonEx:')</code>:
|||,
examples: [
{
input: |||
std.manifestJsonMinified(
{
x: [1, 2, 3, true, false, null,
"string\nstring"],
y: { a: 1, b: 2, c: [1, 2] },
})
|||,
output:
std.manifestJsonMinified(
{
x: [
1,
2,
3,
true,
false,
null,
'string\nstring',
],
y: { a: 1, b: 2, c: [1, 2] },
}
),
},
],
},
{
name: 'manifestYamlDoc',
params: ['value', 'indent_array_in_object=false', 'quote_keys=true'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given value to a YAML form. Note that <code>std.manifestJson</code> could also
be used for this purpose, because any JSON is also valid YAML. But this function will
produce more canonical-looking YAML.
|||),
html.pre({}, |||
std.manifestYamlDoc(
{
x: [1, 2, 3, true, false, null,
"string\nstring\n"],
y: { a: 1, b: 2, c: [1, 2] },
},
indent_array_in_object=false)
|||),
html.p({}, |||
Yields a string containing this YAML:
|||),
html.pre({}, |||
"x":
- 1
- 2
- 3
- true
- false
- null
- |
string
string
"y":
"a": 1
"b": 2
"c":
- 1
- 2
|||),
html.p({}, |||
The <code>indent_array_in_object</code> param adds additional indentation which some people
may find easier to read.
|||),
html.p({}, |||
The <code>quote_keys</code> parameter controls whether YAML identifiers are always quoted
or only when necessary.
|||),
],
},
{
name: 'manifestYamlStream',
params: ['value', 'indent_array_in_object=false', 'c_document_end=false', 'quote_keys=true'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Given an array of values, emit a YAML "stream", which is a sequence of documents separated
by <code>---</code> and ending with <code>...</code>.
|||),
html.pre({}, |||
std.manifestYamlStream(
['a', 1, []],
indent_array_in_object=false,
c_document_end=true)
|||),
html.p({}, |||
Yields this string:
|||),
html.pre({}, |||
---
"a"
---
1
---
[]
...
|||),
html.p({}, |||
The <code>indent_array_in_object</code> and <code>quote_keys</code> params are the
same as in <code>manifestYamlDoc</code>.
|||),
html.p({}, |||
The <code>c_document_end</code> param adds the optional terminating <code>...</code>.
|||),
],
},
{
name: 'manifestXmlJsonml',
params: ['value'],
availableSince: '0.10.0',
description: [
html.p({}, |||
Convert the given <a href="http://www.jsonml.org/">JsonML</a>-encoded value to a string
containing the XML.
|||),
html.pre({}, |||
std.manifestXmlJsonml([
'svg', { height: 100, width: 100 },
[
'circle', {
cx: 50, cy: 50, r: 40,
stroke: 'black', 'stroke-width': 3,
fill: 'red',
}
],
])
|||),
html.p({}, |||
Yields a string containing this XML (all on one line):
|||),
html.pre({}, html.escape(|||
<svg height="100" width="100">
<circle cx="50" cy="50" fill="red" r="40"
stroke="black" stroke-width="3"></circle>;
</svg>;
|||)),
html.p({}, |||
Which represents the following image:
|||),
|||
<svg height="100" width="100">
<circle cx="50" cy="50" r="40" stroke="black" stroke-width="3" fill="red" />
Sorry, your browser does not support inline SVG.
</svg>
|||,
html.p({}, |||
JsonML is designed to preserve "mixed-mode content" (i.e., textual data outside of or next
to elements). This includes the whitespace needed to avoid having all the XML on one line,
which is meaningful in XML. In order to have whitespace in the XML output, it must be
present in the JsonML input:
|||),
html.pre({}, |||
std.manifestXmlJsonml([
'svg',
{ height: 100, width: 100 },
'\n ',
[