comparison xml/en/docs/njs/reference.xml @ 2873:b4eb565bbb1f

Documented atob and btoa global functions in njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 19 Jul 2022 16:53:10 +0100
parents 1e1a15c84515
children 0280b6c71d38
comparison
equal deleted inserted replaced
2872:1e1a15c84515 2873:b4eb565bbb1f
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd"> 7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
8 8
9 <article name="Reference" 9 <article name="Reference"
10 link="/en/docs/njs/reference.html" 10 link="/en/docs/njs/reference.html"
11 lang="en" 11 lang="en"
12 rev="83"> 12 rev="84">
13 13
14 <section id="summary"> 14 <section id="summary">
15 15
16 <para> 16 <para>
17 <link doc="index.xml">njs</link> provides objects, methods and properties 17 <link doc="index.xml">njs</link> provides objects, methods and properties
2589 </tag-desc> 2589 </tag-desc>
2590 2590
2591 </list> 2591 </list>
2592 </para> 2592 </para>
2593 2593
2594 <section id="njs_global_functions" name="Global functions">
2595
2596 <para>
2597 <list type="tag">
2598
2599 <tag-name id="atob"><literal>atob(<value>encodedData</value>)</literal></tag-name>
2600 <tag-desc>
2601 Decodes a string of data which has been encoded
2602 using <literal>Base64</literal> encoding.
2603 The <literal>encodedData</literal> parameter is a binary string
2604 that contains Base64-encoded data.
2605 Returns a string that contains decoded data from <literal>encodedData</literal>.
2606 <para>
2607 The similar <link id="btoa"><literal>btoa()</literal></link> method
2608 can be used to encode and transmit data
2609 which may otherwise cause communication problems,
2610 then transmit it and use the <literal>atob()</literal> method
2611 to decode the data again.
2612 For example, you can encode, transmit, and decode control characters
2613 such as ASCII values <literal>0</literal> through <literal>31</literal>.
2614 <example>
2615 const encodedData = btoa("text to encode"); // encode a string
2616 const decodedData = atob(encodedData); // decode the string
2617 </example>
2618 </para>
2619 </tag-desc>
2620
2621 <tag-name id="btoa"><literal>btoa(<value>stringToEncode</value>)</literal></tag-name>
2622 <tag-desc>
2623 Creates a Base64-encoded ASCII string from a binary string.
2624 The <literal>stringToEncode</literal> parameter is a binary string to encode.
2625 Returns an ASCII string containing the Base64 representation of
2626 <literal>stringToEncode</literal>.
2627 <para>
2628 The method can be used to encode data
2629 which may otherwise cause communication problems, transmit it,
2630 then use the <link id="atob"><literal>atob()</literal></link> method
2631 to decode the data again.
2632 For example, you can encode control characters
2633 such as ASCII values <literal>0</literal> through <literal>31</literal>.
2634 <example>
2635 const encodedData = btoa("text to encode"); // encode a string
2636 const decodedData = atob(encodedData); // decode the string
2637 </example>
2638 </para>
2639 </tag-desc>
2640
2641 </list>
2642 </para>
2643
2644 </section>
2645
2594 </section> 2646 </section>
2595 2647
2596 2648
2597 <section id="builtin_modules" name="built-in modules"> 2649 <section id="builtin_modules" name="built-in modules">
2598 2650