annotate xml/en/docs/njs/reference.xml @ 2315:ae56e4613280

Corrected language in njs.
author Yaroslav Zhuravlev <yar@nginx.com>
date Tue, 25 Dec 2018 17:27:37 +0300
parents 35b02ed44e4a
children 5eba0f7b24a9
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
1 <?xml version="1.0"?>
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
2
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
3 <!--
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
4 Copyright (C) Nginx, Inc.
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
5 -->
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
6
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
7 <!DOCTYPE article SYSTEM "../../../../dtd/article.dtd">
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
8
2246
32ba43abf9cd Renamed njs API, njs Changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2245
diff changeset
9 <article name="Reference"
32ba43abf9cd Renamed njs API, njs Changes.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2245
diff changeset
10 link="/en/docs/njs/reference.html"
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
11 lang="en"
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
12 rev="19">
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
13
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
14 <section id="summary">
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
15
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
16 <para>
2244
467aef18bf12 Renamed the "About njs" page.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2237
diff changeset
17 <link doc="index.xml">njs</link> provides objects, methods and properties
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
18 for extending nginx functionality.
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
19 </para>
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
20
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
21 </section>
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
22
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
23
2247
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
24 <section id="http_stream" name="nginx objects">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
25
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
26
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
27 <section id="http" name="HTTP Request">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
28
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
29 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
30 The HTTP request object is available only in the
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
31 <link doc="../http/ngx_http_js_module.xml">ngx_http_js_module</link> module.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
32 All string properties of the object are <link id="string">byte strings</link>.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
33
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
34 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
35
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
36 <tag-name><literal>r.args{}</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
37 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
38 request arguments object, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
39 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
40
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
41 <tag-name><literal>r.error(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
42 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
43 writes a <literal>string</literal> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
44 on the <literal>error</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
45 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
46
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
47 <tag-name><literal>r.finish()</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
48 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
49 finishes sending a response to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
50 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
51
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
52 <tag-name><literal>r.headersIn{}</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
53 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
54 incoming headers object, read-only.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
55 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
56 For example, the <literal>Foo</literal> header
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
57 can be accessed with the syntax <literal>headersIn.foo</literal>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
58 or <literal>headersIn['Foo']</literal>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
59 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
60 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
61
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
62 <tag-name><literal>r.headersOut{}</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
63 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
64 outgoing headers object, writable.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
65 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
66 For example, the <literal>Foo</literal> header
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
67 can be accessed with the syntax <literal>headersOut.foo</literal>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
68 or <literal>headersOut['Foo']</literal>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
69 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
70 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
71
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
72 <tag-name><literal>r.httpVersion</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
73 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
74 HTTP version, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
75 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
76
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
77 <tag-name><literal>r.log(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
78 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
79 writes a <literal>string</literal> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
80 on the <literal>info</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
81 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
82
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
83 <tag-name id="r_internal_redirect"><literal>r.internalRedirect(<value>uri</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
84 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
85 performs an internal redirect to the specified <literal>uri</literal>.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
86 If the uri starts with the “<literal>@</literal>” prefix,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
87 it is considered a named location.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
88 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
89
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
90 <tag-name><literal>r.method</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
91 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
92 HTTP method, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
93 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
94
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
95 <tag-name><literal>r.parent</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
96 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
97 references the parent request object
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
98 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
99
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
100 <tag-name><literal>r.remoteAddress</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
101 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
102 client address, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
103 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
104
2259
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
105 <tag-name id="r_request_body"><literal>r.requestBody</literal></tag-name>
2247
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
106 <tag-desc>
2259
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
107 returns the client request body if it has not been
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
108 written to a temporary file.
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
109 To ensure that the client request body is in memory,
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
110 its size should be limited by
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
111 <link doc="../http/ngx_http_core_module.xml" id="client_max_body_size"/>,
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
112 and a sufficient buffer size should be set using
9644ecb67081 Unified description of njs r.requestBody with perl request_body.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2247
diff changeset
113 <link doc="../http/ngx_http_core_module.xml" id="client_body_buffer_size"/>.
2247
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
114 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
115
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
116 <tag-name><literal>r.responseBody</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
117 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
118 holds the <link id="subrequest">subrequest</link> response body, read-only.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
119 The size of <literal>r.responseBody</literal> is limited by the
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
120 <link doc="../http/ngx_http_core_module.xml" id="subrequest_output_buffer_size"/>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
121 directive.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
122 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
123
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
124 <tag-name><literal>r.return(status[, string])</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
125 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
126 sends the entire response
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
127 with the specified <literal>status</literal> to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
128 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
129 It is possible to specify either a redirect URL
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
130 (for codes 301, 302, 303, 307, and 308)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
131 or the response body text (for other codes) as the second argument
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
132 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
133 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
134
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
135 <tag-name><literal>r.send(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
136 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
137 sends a part of the response body to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
138 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
139
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
140 <tag-name><literal>r.sendHeader()</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
141 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
142 sends the HTTP headers to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
143 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
144
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
145 <tag-name><literal>r.status</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
146 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
147 status, writable
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
148 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
149
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
150 <tag-name><literal>r.variables{}</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
151 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
152 nginx variables object, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
153 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
154
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
155 <tag-name><literal>r.warn(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
156 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
157 writes a <literal>string</literal> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
158 on the <literal>warning</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
159 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
160
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
161 <tag-name><literal>r.uri</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
162 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
163 current URI, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
164 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
165
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
166 <tag-name id="subrequest"><literal>r.subrequest(<value>uri</value>[,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
167 <value>options</value>[, <value>callback</value>]])</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
168 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
169 creates a subrequest with the given <literal>uri</literal> and
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
170 <literal>options</literal>, and installs
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
171 an optional completion <literal>callback</literal>.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
172
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
173 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
174 If <literal>options</literal> is a string, then it
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
175 holds the subrequest arguments string.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
176 Otherwise, <literal>options</literal> is expected to be
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
177 an object with the following keys:
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
178 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
179 <tag-name><literal>args</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
180 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
181 arguments string
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
182 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
183 <tag-name><literal>body</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
184 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
185 request body
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
186 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
187
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
188 <tag-name><literal>method</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
189 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
190 HTTP method
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
191 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
192
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
193 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
194 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
195
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
196 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
197 The completion <literal>callback</literal> receives
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
198 a subrequest response object with methods and properties
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
199 identical to the parent request object.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
200 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
201 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
202
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
203 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
204 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
205
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
206 </section>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
207
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
208
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
209 <section id="stream" name="Stream Session">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
210
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
211 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
212 The stream session object is available only in the
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
213 <link doc="../stream/ngx_stream_js_module.xml">ngx_stream_js_module</link>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
214 module.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
215 All string properties of the object are <link id="string">byte strings</link>.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
216 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
217
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
218 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
219 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
220 Prior to njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
221 the stream session object had some properties which are currently
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
222 <link id="stream_obsolete">removed</link>.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
223 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
224 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
225
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
226 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
227 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
228
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
229 <tag-name id="s_allow"><literal>s.allow()</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
230 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
231 successfully finalizes the phase handler
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
232 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
233 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
234
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
235 <tag-name id="s_decline"><literal>s.decline()</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
236 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
237 finalizes the phase handler and passes control to the next handler
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
238 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
239 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
240
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
241 <tag-name id="s_deny"><literal>s.deny()</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
242 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
243 finalizes the phase handler with the access error code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
244 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
245 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
246
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
247 <tag-name id="s_done"><literal>s.done</literal>(<value>[code]</value>)</tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
248 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
249 successfully finalizes the current phase handler
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
250 or finalizes it with the specified numeric code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
251 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>).
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
252 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
253
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
254 <tag-name><literal>s.error(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
255 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
256 writes a sent <literal>string</literal> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
257 on the <literal>error</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
258 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
259
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
260 <tag-name><literal>s.log(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
261 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
262 writes a sent <value>string</value> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
263 on the <literal>info</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
264 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
265
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
266 <tag-name id="s_off"><literal>s.off(<value>eventName</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
267 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
268 unregisters the callback set by the <link id="s_on">s.on()</link> method
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
269 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
270 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
271
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
272 <tag-name id="s_on"><literal>s.on(<value>event</value>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
273 <value>callback</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
274 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
275 registers a <literal>callback</literal> for the specified <literal>event</literal>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
276 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>).
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
277
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
278 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
279 An <literal>event</literal> may be one of the following strings:
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
280 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
281 <tag-name><literal>upload</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
282 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
283 new data from a client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
284 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
285
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
286 <tag-name><literal>download</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
287 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
288 new data to a client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
289 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
290
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
291 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
292 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
293
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
294 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
295 The completion callback has the following prototype:
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
296 <literal>callback(data, flags)</literal>, where
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
297 <literal>data</literal> is string,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
298 <literal>flags</literal> is an object
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
299 with the following properties:
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
300 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
301 <tag-name id="s_on_callback_last"><literal>last</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
302 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
303 a boolean value, true if data is a last buffer.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
304 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
305
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
306 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
307 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
308 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
309
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
310 <tag-name><literal>s.remoteAddress</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
311 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
312 client address, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
313 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
314
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
315 <tag-name id="s_send"><literal>s.send(<value>data</value>[,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
316 <value>options</value>])</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
317 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
318 sends the data to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
319 (<link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>).
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
320 The <literal>options</literal> is an object used
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
321 to override nginx buffer flags derived from an incoming data chunk buffer.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
322 The flags can be overriden with the following flags:
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
323 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
324 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
325
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
326 <tag-name><literal>last</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
327 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
328 boolean, true if the buffer is the last buffer
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
329 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
330
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
331 <tag-name><literal>flush</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
332 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
333 boolean, true if the buffer should have the <literal>flush</literal> flag
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
334 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
335 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
336 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
337 The method can be called multiple times per callback invocation.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
338 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
339
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
340 <tag-name><literal>s.variables{}</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
341 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
342 nginx variables object, read-only
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
343 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
344
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
345 <tag-name><literal>s.warn(<value>string</value>)</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
346 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
347 writes a sent <literal>string</literal> to the error log
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
348 on the <literal>warning</literal> level of logging
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
349 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
350
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
351 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
352 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
353
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
354
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
355 <section id="stream_obsolete" name="Obsolete properties">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
356
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
357 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
358 These properties have been removed
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
359 in njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
360 and are not backward compatible with the existing njs code.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
361 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
362
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
363 <para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
364 <list type="tag">
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
365
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
366 <tag-name id="s_abort"><literal>s.ABORT</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
367 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
368 the <literal>ABORT</literal> return code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
369 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
370 Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
371 the <link id="s_deny">s.deny()</link> method should be used instead.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
372 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
373 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
374
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
375 <tag-name><literal>s.AGAIN</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
376 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
377 the <literal>AGAIN</literal> return code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
378 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
379 Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
380 the corresponding behavior is achieved if no
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
381 <link id="s_allow">s.allow()</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
382 <link id="s_deny">s.deny()</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
383 <link id="s_decline">s.decline()</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
384 <link id="s_done">s.done()</link>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
385 is invoked and a callback is registered.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
386 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
387 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
388
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
389 <tag-name id="s_buffer"><literal>s.buffer</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
390 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
391 the current buffer, writable
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
392 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
393 Starting from <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
394 the <link id="s_send">s.send()</link> method should be used for writing.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
395 For reading, the current buffer is available as the first argument of the
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
396 <literal>event</literal> callback.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
397 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
398 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
399
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
400 <tag-name><literal>s.DECLINED</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
401 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
402 the <literal>DECLINED</literal> return code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
403 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
404 Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
405 the <link id="s_decline">s.decline()</link> method should be used instead.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
406 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
407 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
408
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
409 <tag-name><literal>s.eof</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
410 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
411 a boolean read-only property, true if the current buffer is the last buffer
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
412 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
413 Starting from <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
414 the <link id="s_on_callback_last">flags.last</link> property
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
415 should be used instead.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
416 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
417 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
418
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
419 <tag-name><literal>s.ERROR</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
420 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
421 the <literal>ERROR</literal> return code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
422 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
423 Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
424 an appropriate exception can be thrown to report an error.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
425 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
426 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
427
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
428 <tag-name><literal>s.fromUpstream</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
429 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
430 a boolean read-only property,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
431 true if the current buffer is from the upstream server to the client
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
432 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
433 Starting from <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
434 a corresponding <link id="s_on">event</link>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
435 (<literal>upload</literal> or <literal>download</literal>)
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
436 should be used to handle data to or from client.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
437 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
438 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
439
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
440 <tag-name id="s_ok"><literal>s.OK</literal></tag-name>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
441 <tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
442 the <literal>OK</literal> return code
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
443 <note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
444 Starting from njs <link doc="../njs/changes.xml" id="njs0.2.4">0.2.4</link>,
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
445 the <link id="s_allow">s.allow()</link> method should be used instead.
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
446 </note>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
447 </tag-desc>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
448
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
449 </list>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
450 </para>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
451
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
452 </section>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
453
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
454 </section>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
455
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
456 </section>
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
457
0f16ef9a8dbe Created "nginx objects" section in reference.xml.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2246
diff changeset
458
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
459 <section id="core" name="Core">
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
460
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
461
2312
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
462 <section id="core_object" name="Object">
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
463
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
464 <para>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
465 The <literal>Object</literal> constructor corresponds to a standard JS object.
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
466 <list type="tag">
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
467
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
468 <tag-name id="object_entries"><literal>Object.entries(<value>object</value>)</literal></tag-name>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
469 <tag-desc>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
470 returns an array of all enumerable property
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
471 <literal>[key, value]</literal> pairs
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
472 of the given <literal>object</literal>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
473 (<link doc="changes.xml" id="njs0.2.7">0.2.7</link>).
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
474 </tag-desc>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
475
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
476 <tag-name id="object_values"><literal>Object.values(<value>object</value>)</literal></tag-name>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
477 <tag-desc>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
478 returns an array of all enumerable property values
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
479 of the given <literal>object</literal>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
480 (<link doc="changes.xml" id="njs0.2.7">0.2.7</link>).
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
481 </tag-desc>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
482
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
483 </list>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
484 </para>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
485
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
486 </section>
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
487
1a6524706c70 njs-0.2.7
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2285
diff changeset
488
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
489 <section id="string" name="String">
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
490
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
491 <para>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
492 There are two types of strings in njs: a Unicode string (default) and
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
493 a byte string.
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
494 </para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
495
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
496 <para>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
497 A Unicode string corresponds to an ECMAScript string
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
498 which contains Unicode characters.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
499 </para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
500
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
501 <para>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
502 Byte strings contain a sequence of bytes
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
503 and are used to serialize Unicode strings
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
504 to external data and deserialize from external sources.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
505 For example, the <link id="string_toutf8">toUTF8()</link> method serializes
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
506 a Unicode string to a byte string using UTF8 encoding:
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
507 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
508 >> '£'.toUTF8().toString('hex')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
509 'c2a3' /* C2 A3 is the UTF8 representation of 00A3 ('£') code point */
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
510 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
511 The <link id="string_tobytes">toBytes()</link> method serializes
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
512 a Unicode string with code points up to 255 into a byte string,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
513 otherwise, <literal>null</literal> is returned:
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
514 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
515 >> '£'.toBytes().toString('hex')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
516 'a3' /* a3 is a byte equal to 00A3 ('£') code point */
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
517 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
518 Only byte strings can be converted to different encodings.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
519 For example, a string cannot be encoded to <literal>hex</literal> directly:
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
520 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
521 >> 'αβγδ'.toString('base64')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
522 TypeError: argument must be a byte string
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
523 at String.prototype.toString (native)
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
524 at main (native)
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
525 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
526 To convert a Unicode string to hex,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
527 first, it should be converted to a byte string and then to hex:
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
528 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
529 >> 'αβγδ'.toUTF8().toString('base64')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
530 'zrHOss6zzrQ='
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
531 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
532
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
533 <list type="tag">
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
534
2211
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
535 <tag-name id="string_bytesfrom"><literal>String.bytesFrom(<value>array</value>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
536 | <value>string</value>, <value>encoding</value>)</literal></tag-name>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
537 <tag-desc>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
538 (njs specific) Creates a byte string either from an array that contains octets,
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
539 or from an encoded string
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
540 (<link doc="../njs/changes.xml" id="njs0.2.3">0.2.3</link>).
2211
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
541 The encoding can be
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
542 <literal>hex</literal>,
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
543 <literal>base64</literal>, and
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
544 <literal>base64url</literal>.
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
545 <example>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
546 >> String.bytesFrom([0x62, 0x75, 0x66, 0x66, 0x65, 0x72])
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
547 'buffer'
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
548
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
549 >> String.bytesFrom('YnVmZmVy', 'base64')
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
550 'buffer'
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
551 </example>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
552 </tag-desc>
660229c5c92f Documented String.bytesFrom() method in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2207
diff changeset
553
2271
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
554 <tag-name id="string_fromcharcode"><literal>String.fromCharCode(<value>CharCode1</value>[, ...[,
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
555 <value>CharCodeN</value>]])</literal></tag-name>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
556 <tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
557 Returns a string from one or more Unicode code points.
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
558 <example>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
559 >> String.fromCharCode(97, 98, 99, 100)
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
560 'abcd'
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
561 </example>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
562 </tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
563
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
564 <tag-name id="string_fromcodepoint"><literal>String.fromCodePoint(<value>codePoint1</value>[, ...[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
565 <value>codePoint2</value>]])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
566 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
567 Returns a string from one or more Unicode code points.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
568 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
569 >> String.fromCodePoint(97, 98, 99, 100)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
570 'abcd'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
571 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
572 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
573
2271
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
574 <tag-name id="string_charat"><literal>String.prototype.charAt(<value>index</value>)</literal></tag-name>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
575 <tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
576 Returns a string representing one Unicode code unit
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
577 at the specified <literal>index</literal>;
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
578 empty string if index is out of range.
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
579 The index can be an integer
2271
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
580 between 0 and 1-less-than the length of the string.
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
581 If no index is provided, the default is <literal>0</literal>,
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
582 so the first character in the string is returned.
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
583 </tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
584
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
585 <tag-name id="string_codepointat"><literal>String.prototype.CodePointAt(<value>position</value>)</literal></tag-name>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
586 <tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
587 Returns a number representing the code point value of the character
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
588 at the given <literal>position</literal>;
2271
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
589 <literal>undefined</literal> if there is no element at position.
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
590 <example>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
591 >> 'ABCD'.codePointAt(3);
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
592 68
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
593 </example>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
594 </tag-desc>
34a1901e663d Described charAt, codePointAt, fromCharCode in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2268
diff changeset
595
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
596 <tag-name id="string_concat"><literal>String.prototype.concat(<value>string1</value>[, ...,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
597 <value>stringN</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
598 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
599 Returns a string that contains the concatenation of specified
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
600 <literal>strings</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
601 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
602 >> "a".concat("b", "c")
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
603 'abc'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
604 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
605 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
606
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
607 <tag-name id="string_endswith"><literal>String.prototype.endsWith(<value>searchString</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
608 <value>length</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
609 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
610 Returns <literal>true</literal> if a string ends with the characters
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
611 of a specified string, otherwise <literal>false</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
612 The optional <literal>length</literal> parameter is the the length of string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
613 If omitted, the default value is the length of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
614 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
615 >> 'abc'.endsWith('abc')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
616 true
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
617 >> 'abca'.endsWith('abc')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
618 false
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
619 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
620 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
621
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
622 <tag-name id="string_frombytes"><literal>String.prototype.fromBytes(<value>start</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
623 <value>end</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
624 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
625 (njs specific) Returns a new Unicode string from a byte string
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
626 where each byte is replaced with a corresponding Unicode code point.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
627 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
628
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
629 <tag-name id="string_fromutf8"><literal>String.prototype.fromUTF8(<value>start</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
630 <value>end</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
631 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
632 (njs specific) Converts a byte string containing a valid UTF8 string
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
633 into a Unicode string,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
634 otherwise <literal>null</literal> is returned.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
635 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
636
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
637 <tag-name id="string_includes"><literal>String.prototype.includes(<value>searchString</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
638 <value>position</value>]))</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
639 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
640 Returns <literal>true</literal> if a string is found within another string,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
641 otherwise <literal>false</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
642 The optional <literal>position</literal> parameter is the position
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
643 within the string at which to begin search for <literal>searchString</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
644 Default value is 0.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
645 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
646 >> 'abc'.includes('bc')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
647 true
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
648 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
649 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
650
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
651 <tag-name id="string_indexof"><literal>String.prototype.indexOf(<value>searchString</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
652 <value>fromIndex</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
653 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
654 Returns the position of the first occurrence
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
655 of the <literal>searchString</literal>.
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
656 The search is started at <literal>fromIndex</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
657 Returns <value>-1</value> if the value is not found.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
658 The <literal>fromIndex</literal> is an integer,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
659 default value is 0.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
660 If <literal>fromIndex</literal> is lower than 0
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
661 or greater than
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
662 <link id="string_length">String.prototype.length</link><value></value>,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
663 the search starts at index <value>0</value> and
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
664 <value>String.prototype.length</value>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
665 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
666 >> 'abcdef'.indexOf('de', 2)
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
667 3
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
668 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
669 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
670
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
671 <tag-name id="string_lastindexof"><literal>String.prototype.lastIndexOf(<value>searchString</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
672 <value>fromIndex</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
673 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
674 Returns the position of the last occurrence
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
675 of the <literal>searchString</literal>,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
676 searching backwards from <literal>fromIndex</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
677 Returns <value>-1</value> if the value is not found.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
678 If <literal>searchString</literal> is empty,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
679 then <literal>fromIndex</literal> is returned.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
680 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
681 >> "nginx".lastIndexOf("gi")
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
682 1
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
683 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
684 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
685
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
686 <tag-name id="string_length"><literal>String.prototype.length</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
687 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
688 Returns the length of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
689 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
690 >> 'αβγδ'.length
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
691 4
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
692 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
693 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
694
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
695 <tag-name id="string_match"><literal>String.prototype.match([<value>regexp</value>])</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
696 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
697 Matches a string against a <literal>regexp</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
698 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
699 >> 'nginx'.match( /ng/i )
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
700 'ng'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
701 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
702 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
703
2212
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
704 <tag-name id="string_padend"><literal>String.prototype.padEnd(<value>length</value>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
705 [, <value>string</value>])</literal></tag-name>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
706 <tag-desc>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
707 Returns a string of a specified <literal>length</literal>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
708 with the pad <literal>string</literal> applied to the end of the specified
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
709 string (<link doc="../njs/changes.xml" id="njs0.2.3">0.2.3</link>).
2212
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
710 <example>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
711 >> '1234'.padEnd(8, 'abcd')
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
712 '1234abcd'
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
713 </example>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
714 </tag-desc>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
715
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
716 <tag-name id="string_padstart"><literal>String.prototype.padStart(<value>length</value>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
717 [, <value>string</value>])</literal></tag-name>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
718 <tag-desc>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
719 Returns a string of a specified <literal>length</literal>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
720 with the pad <literal>string</literal> applied to the start of the specified
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
721 string (<link doc="../njs/changes.xml" id="njs0.2.3">0.2.3</link>).
2212
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
722 <example>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
723 >> '1234'.padStart(8, 'abcd')
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
724 'abcd1234'
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
725 </example>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
726 </tag-desc>
c34a885b9d99 Documented padEnd() and padStart() for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2211
diff changeset
727
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
728 <tag-name id="string_repeat"><literal>String.prototype.repeat(<value>number</value>)</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
729 <tag-desc>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
730 Returns a string
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
731 with the specified <literal>number</literal> of copies of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
732 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
733 >> 'abc'.repeat(3)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
734 'abcabcabc'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
735 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
736 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
737
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
738 <tag-name id="string_replace"><literal>String.prototype.replace([<value>regexp</value>|<value>string</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
739 <value>string</value>|<value>function</value>]])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
740 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
741 Returns a new string with matches of a pattern
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
742 (<literal>string</literal> or a <literal>regexp</literal>)
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
743 replaced by a <literal>string</literal> or a <literal>function</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
744 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
745 >> 'abcdefgh'.replace('d', 1)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
746 'abc1efgh'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
747 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
748 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
749
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
750 <tag-name id="string_search"><literal>String.prototype.search([<value>regexp</value>])</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
751 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
752 Searches for a string using a <literal>regexp</literal>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
753 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
754 >> 'abcdefgh'.search('def')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
755 3
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
756 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
757 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
758
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
759 <tag-name id="string_slice"><literal>String.prototype.slice(<value>start</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
760 <value>end</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
761 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
762 Returns a new string containing a part of an
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
763 original string between <literal>start</literal>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
764 and <literal>end</literal> or
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
765 from <literal>start</literal> to the end of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
766 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
767 >> 'abcdefghijklmno'.slice(NaN, 5)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
768 'abcde'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
769 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
770 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
771
2268
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
772 <tag-name id="string_split"><literal>String.prototype.split(([<value>string</value>|<value>regexp</value>[,
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
773 <value>limit</value>]]))</literal></tag-name>
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
774 <tag-desc>
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
775 Returns match of a string against a <literal>regexp</literal>.
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
776 The optional <literal>limit</literal> parameter is an integer that specifies
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
777 a limit on the number of splits to be found.
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
778 <example>
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
779 >> 'abc'.split('')
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
780 [
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
781 'a',
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
782 'b',
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
783 'c'
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
784 ]
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
785 </example>
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
786 </tag-desc>
cd1b26111884 Moved string.split to follow alphabetical order.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2267
diff changeset
787
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
788 <tag-name id="string_startswith"><literal>String.prototype.startsWith(<value>searchString</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
789 <value>position</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
790 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
791 Returns <literal>true</literal> if a string begins with the characters
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
792 of a specified string, otherwise <literal>false</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
793 The optional <literal>position</literal> parameter is the position
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
794 in this string at which to begin search for <literal>searchString</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
795 Default value is 0.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
796 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
797 >> 'abc'.startsWith('abc')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
798 true
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
799 > 'aabc'.startsWith('abc')
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
800 false
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
801 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
802 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
803
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
804 <tag-name id="string_substr"><literal>String.prototype.substr(<value>start</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
805 <value>length</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
806 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
807 Returns the part of the string of the specified <literal>length</literal>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
808 from <literal>start</literal>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
809 or from <literal>start</literal> to the end of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
810 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
811 >> 'abcdefghijklmno'.substr(3, 5)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
812 'defgh'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
813 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
814 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
815
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
816 <tag-name id="string_substring"><literal>String.prototype.substring(<value>start</value>[,
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
817 <value>end</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
818 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
819 Returns the part of the string between
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
820 <literal>start</literal> and <literal>end</literal> or
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
821 from <literal>start</literal> to the end of the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
822 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
823 >> 'abcdefghijklmno'.substring(3, 5)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
824 'de'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
825 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
826 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
827
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
828 <tag-name id="string_tobytes"><literal>String.prototype.toBytes(start[,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
829 end])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
830 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
831 (njs specific) Serializes a Unicode string to a byte string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
832 Returns <literal>null</literal> if a character larger than 255 is
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
833 found in the string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
834 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
835
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
836 <tag-name id="string_tolowercase"><literal>String.prototype.toLowerCase()</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
837 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
838 Converts a string to lower case.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
839 The method supports only simple Unicode folding.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
840 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
841 >> 'ΑΒΓΔ'.toLowerCase()
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
842 'αβγδ'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
843 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
844 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
845
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
846 <tag-name><literal>String.prototype.toString([<value>encoding</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
847 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
848 <para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
849 If no <literal>encoding</literal> is specified,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
850 returns a specified Unicode string or byte string as in ECMAScript.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
851 </para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
852
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
853 <para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
854 (njs specific) If <literal>encoding</literal> is specified,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
855 encodes a <link id="string_tobytes">byte string</link> to
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
856 <literal>hex</literal>,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
857 <literal>base64</literal>, or
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
858 <literal>base64url</literal>.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
859 </para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
860 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
861 >> 'αβγδ'.toUTF8().toString('base64url')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
862 'zrHOss6zzrQ'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
863 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
864 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
865
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
866 <tag-name id="string_touppercase"><literal>String.prototype.toUpperCase()</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
867 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
868 Converts a string to upper case.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
869 The method supports only simple Unicode folding.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
870 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
871 >> 'αβγδ'.toUpperCase()
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
872 'ΑΒΓΔ'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
873 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
874 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
875
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
876 <tag-name id="string_toutf8"><literal>String.prototype.toUTF8(<value>start</value>[,
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
877 <value>end</value>])</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
878 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
879 (njs specific) Serializes a Unicode string
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
880 to a byte string using UTF8 encoding.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
881 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
882 >> 'αβγδ'.toUTF8().length
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
883 8
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
884 >> 'αβγδ'.length
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
885 4
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
886 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
887 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
888
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
889 <tag-name id="string_trim"><literal>String.prototype.trim()</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
890 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
891 Removes whitespaces from both ends of a string.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
892 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
893 >> ' abc '.trim()
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
894 'abc'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
895 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
896 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
897
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
898 <tag-name id="encodeuri"><literal>encodeURI(<value>URI</value>)</literal></tag-name>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
899 <tag-desc>
2315
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
900 Encodes a URI by replacing each instance of certain characters
ae56e4613280 Corrected language in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2313
diff changeset
901 by one, two, three, or four escape sequences
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
902 representing the UTF-8 encoding of the character
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
903 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
904 >> encodeURI('012αβγδ')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
905 '012%CE%B1%CE%B2%CE%B3%CE%B4'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
906 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
907 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
908
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
909 <tag-name id="encodeuricomponent"><literal>encodeURIComponent(<value>encodedURIString</value>)</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
910 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
911 Encodes a URI by replacing each instance of certain characters
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
912 by one, two, three, or four escape sequences
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
913 representing the UTF-8 encoding of the character.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
914 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
915 >> encodeURIComponent('[@?=')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
916 '%5B%40%3F%3D'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
917 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
918 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
919
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
920 <tag-name id="decodeuri"><literal>decodeURI(<value>encodedURI</value>)</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
921 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
922 Decodes a previously <link id="encodeuri">encoded</link> URI.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
923 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
924 >> decodeURI('012%CE%B1%CE%B2%CE%B3%CE%B4')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
925 '012αβγδ'
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
926 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
927 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
928
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
929 <tag-name id="decodeuricomponent"><literal>decodeURIComponent(<value>decodedURIString</value>)</literal></tag-name>
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
930 <tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
931 Decodes an encoded component of a previously encoded URI.
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
932 <example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
933 >> decodeURIComponent('%5B%40%3F%3D')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
934 '[@?='
2186
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
935 </example>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
936 </tag-desc>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
937
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
938 </list>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
939 </para>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
940
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
941 </section>
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
942
8e2b3aadc3ce Added njs String object.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2183
diff changeset
943
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
944 <section id="core_json" name="JSON">
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
945
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
946 <para>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
947 The <literal>JSON</literal> object (ES 5.1) provides functions
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
948 to convert njs values to and from JSON format.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
949 <list type="tag">
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
950
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
951 <tag-name><literal>JSON.parse(<value>string</value>[,
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
952 <value>reviver</value>])</literal></tag-name>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
953 <tag-desc>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
954 Converts a <literal>string</literal> that represents JSON data
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
955 into an njs object (<literal>{...}</literal>) or
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
956 array (<literal>[...]</literal>).
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
957 The optional <literal>reviver</literal> parameter is a function (key, value)
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
958 that will be called for each (key,value) pair and can transform the value.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
959 </tag-desc>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
960
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
961 <tag-name><literal>JSON.stringify(<value>value</value>[,
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
962 <value>replacer</value>] [, <value>space</value>])</literal></tag-name>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
963 <tag-desc>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
964 Converts an njs object back to JSON.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
965 The obligatory <literal>value</literal> parameter is generally a JSON
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
966 <literal>object</literal> or <literal>array</literal> that will be converted.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
967 If the value has a <literal>toJSON()</literal> method,
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
968 it defines how the object will be serialized.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
969 The optional <literal>replacer</literal> parameter is
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
970 a <literal>function</literal> or <literal>array</literal>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
971 that transforms results.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
972 The optional <literal>space</literal> parameter is
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
973 a <literal>string</literal> or <literal>number</literal>.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
974 If it is a <literal>number</literal>,
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
975 it indicates the number of white spaces placed before a result
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
976 (no more than 10).
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
977 If it is a <literal>string</literal>,
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
978 it is used as a white space (or first 10 characters of it).
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
979 If omitted or is <literal>null</literal>, no white space is used.
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
980 </tag-desc>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
981 </list>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
982 </para>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
983
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
984 <para>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
985 <example>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
986 >> var json = JSON.parse('{"a":1, "b":true}')
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
987 >> json.a
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
988 1
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
989
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
990 >> JSON.stringify(json)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
991 '{"a":1,"b":true}'
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
992
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
993 >> JSON.stringify({ x: [10, undefined, function(){}] })
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
994 '{"x":[10,null,null]}'
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
995
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
996 >> JSON.stringify({"a":1, "toJSON": function() {return "xxx"}})
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
997 '"xxx"'
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
998
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
999 # Example with function replacer
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1000
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1001 >> function replacer(key, value) {return (typeof value === 'string') ? undefined : value}
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1002 >>JSON.stringify({a:1, b:"b", c:true}, replacer)
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
1003 '{"a":1,"c":true}'
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1004 </example>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1005 </para>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1006
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1007 </section>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1008
2177
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1009
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1010 <section id="crypto" name="Crypto">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1011
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1012 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1013 The Crypto module provides cryptographic functionality support.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1014 The Crypto module object is returned by <literal>require('crypto')</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1015 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1016
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1017 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1018 <list type="tag">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1019
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
1020 <tag-name id="crypto_createhash"><literal>crypto.createHash(<value>algorithm</value>)</literal></tag-name>
2177
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1021 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1022 Creates and returns a <link id="crypto_hash">Hash</link> object
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1023 that can be used to generate hash digests
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1024 using the given <value>algorithm</value>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1025 The algorighm can be
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1026 <literal>md5</literal>,
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1027 <literal>sha1</literal>, and
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1028 <literal>sha256</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1029 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1030
2267
c30048802769 Added links to njs reference from njs Compatibility.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2259
diff changeset
1031 <tag-name id="crypto_createhmac"><literal>crypto.createHmac(<value>algorithm</value>,
2177
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1032 <value>secret key</value>)</literal></tag-name>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1033 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1034 Creates and returns an <link id="crypto_hmac">HMAC</link> object
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1035 that uses the given <value>algorithm</value> and <value>secret key</value>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1036 The algorighm can be
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1037 <literal>md5</literal>,
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1038 <literal>sha1</literal>, and
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1039 <literal>sha256</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1040 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1041
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1042 </list>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1043 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1044
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1045
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1046 <section id="crypto_hash" name="Hash">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1047
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1048 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1049 <list type="tag">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1050
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1051 <tag-name><literal>hash.update(<value>data</value>)</literal></tag-name>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1052 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1053 Updates the hash content with the given <value>data</value>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1054 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1055
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1056 <tag-name><literal>hash.digest([<value>encoding</value>])</literal></tag-name>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1057 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1058 Calculates the digest of all of the data passed using
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1059 <literal>hash.update()</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1060 The encoding can be
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1061 <literal>hex</literal>,
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1062 <literal>base64</literal>, and
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1063 <literal>base64url</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1064 If encoding is not provided, a byte string is returned.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1065 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1066
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1067 </list>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1068 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1069
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1070 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1071 <example>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1072 >> var cr = require('crypto')
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1073 undefined
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1074
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1075 >> cr.createHash('sha1').update('A').update('B').digest('base64url')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
1076 'BtlFlCqiamG-GMPiK_GbvKjdK10'
2177
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1077 </example>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1078 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1079
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1080 </section>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1081
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1082
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1083 <section id="crypto_hmac" name="HMAC">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1084
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1085 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1086 <list type="tag">
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1087
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1088 <tag-name><literal>hmac.update(<value>data</value>)</literal></tag-name>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1089 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1090 Updates the HMAC content with the given <value>data</value>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1091 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1092
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1093 <tag-name><literal>hmac.digest([<value>encoding</value>])</literal></tag-name>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1094 <tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1095 Calculates the HMAC digest of all of the data passed using
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1096 <literal>hmac.update()</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1097 The encoding can be
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1098 <literal>hex</literal>,
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1099 <literal>base64</literal>, and
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1100 <literal>base64url</literal>.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1101 If encoding is not provided, a byte string is returned.
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1102 </tag-desc>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1103 </list>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1104 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1105
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1106 <para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1107 <example>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1108 >> var cr = require('crypto')
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1109 undefined
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1110
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1111 >> cr.createHmac('sha1', 'secret.key').update('AB').digest('base64url')
2214
e029f4bc7ede Added quotes to njs examples.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2212
diff changeset
1112 'Oglm93xn23_MkiaEq_e9u8zk374'
2177
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1113 </example>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1114 </para>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1115
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1116 </section>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1117
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1118 </section>
79297494d291 Added njs Crypto API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2176
diff changeset
1119
2203
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1120 <section id="njs_api_timers" name="Timers">
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1121
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1122 <para>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1123
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1124 <list type="tag">
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1125
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1126 <tag-name id="cleartimeout"><literal>clearTimeout(<value>timeout</value>)</literal></tag-name>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1127 <tag-desc>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1128 Cancels a <literal>timeout</literal> object
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1129 created by <link id="settimeout">setTimeout()</link>.
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1130 </tag-desc>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1131
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1132 <tag-name id="settimeout"><literal>setTimeout(<value>function</value>,
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1133 <value>ms</value>[, <value>arg1</value>, <value>argN</value>])</literal></tag-name>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1134 <tag-desc>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1135 Calls a <literal>function</literal>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1136 after a specified number of <literal>milliseconds</literal>.
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1137 One or more optional <literal>arguments</literal>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1138 can be passed to the specified function.
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1139 Returns a <literal>timeout</literal> object.
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1140 <example>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1141 function handler(v)
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1142 {
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1143 // ...
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1144 }
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1145
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1146 t = setTimeout(handler, 12);
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1147
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1148 // ...
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1149
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1150 clearTimeout(t);
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1151 </example>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1152 </tag-desc>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1153
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1154 </list>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1155 </para>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1156
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1157 </section>
56a8cfb422ae Added setTimeout and clearTimeout for njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2202
diff changeset
1158
2204
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1159
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1160 <section id="njs_api_fs" name="File System">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1161
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1162 <para>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1163 The File System module provides operations with files.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1164 The module object is returned by <literal>require('fs')</literal>.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1165 <list type="tag">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1166
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1167 <tag-name id="appendfilesync"><literal>appendFileSync(<value>filename</value>,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1168 <value>data</value>[, <value>options</value>])</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1169 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1170 Synchronously appends specified <literal>data</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1171 to a file with provided <literal>filename</literal>.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1172 If the file does not exist, it will be created.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1173 The <literal>options</literal> parameter is expected to be
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1174 an object with the following keys:
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1175 <list type="tag">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1176
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1177 <tag-name><literal>mode</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1178 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1179 mode option, by default is <literal>0o666</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1180 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1181
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1182 <tag-name><literal>flag</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1183 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1184 file system <link id="njs_api_fs_flags">flag</link>,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1185 by default is <literal>a</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1186 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1187
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1188 </list>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1189 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1190
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1191 <tag-name id="readfilesync"><literal>readFileSync(<value>filename</value>[,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1192 <value>options</value>])</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1193 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1194 Synchronously returns the contents of the file
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1195 with provided <literal>filename</literal>.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1196 The <literal>options</literal> parameter holds
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1197 <literal>string</literal> that specifies encoding.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1198 If not specified, a <link id="string_tobytes">byte string</link> is returned.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1199 If <literal>utf8</literal> encoding is specified, a Unicode string is returned.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1200 Otherwise, <literal>options</literal> is expected to be
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1201 an object with the following keys:
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1202 <list type="tag">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1203
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1204 <tag-name><literal>encoding</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1205 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1206 encoding, by default is not specified.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1207 The encoding can be <literal>utf8</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1208 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1209
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1210 <tag-name><literal>flag</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1211 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1212 file system <link id="njs_api_fs_flags">flag</link>,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1213 by default is <literal>r</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1214 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1215
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1216 </list>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1217 <example>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1218 >> var fs = require('fs')
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1219 undefined
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1220 >> var file = fs.readFileSync('/file/path.tar.gz')
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1221 undefined
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1222 >> var gzipped = /^\x1f\x8b/.test(file); gzipped
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1223 true
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1224 </example>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1225 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1226
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1227 <tag-name id="writefilesync"><literal>writeFileSync(<value>filename</value>,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1228 <value>data</value>[,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1229 <value>options</value>])</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1230 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1231 Synchronously writes <literal>data</literal> to a file
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1232 with provided <literal>filename</literal>.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1233 If the file does not exist, it will be created,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1234 if the file exists, it will be replaced.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1235 The <literal>options</literal> parameter is expected to be
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1236 an object with the following keys:
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1237 <list type="tag">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1238 <tag-name><literal>mode</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1239 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1240 mode option, by default is <literal>0o666</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1241 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1242
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1243 <tag-name><literal>flag</literal></tag-name>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1244 <tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1245 file system <link id="njs_api_fs_flags">flag</link>,
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1246 by default is <literal>w</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1247 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1248
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1249 </list>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1250 <example>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1251 >> var fs = require('fs')
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1252 undefined
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1253 >> var file = fs.writeFileSync('hello.txt', 'Hello world')
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1254 undefined
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1255 </example>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1256 </tag-desc>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1257
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1258 </list>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1259 </para>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1260
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1261
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1262 <section id="njs_api_fs_flags" name="File System Flags">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1263
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1264 <para>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1265 The <literal>flag</literal> option can accept the following values:
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1266
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1267 <list type= "bullet" compact="no">
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1268
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1269 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1270 <literal>a</literal>&mdash;open a file for appending.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1271 The file is created if it does not exist
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1272 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1273
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1274 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1275 <literal>ax</literal>&mdash;the same as <literal>a</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1276 but fails if the file already exists
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1277 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1278
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1279 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1280 <literal>a+</literal>&mdash;open a file for reading and appending.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1281 If the file does not exist, it will be created
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1282 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1283
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1284 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1285 <literal>ax+</literal>&mdash;the same as <literal>a+</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1286 but fails if the file already exists
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1287 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1288
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1289 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1290 <literal>as</literal>&mdash;open a file for appending in synchronous mode.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1291 If the file does not exist, it will be created
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1292 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1293
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1294 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1295 <literal>as+</literal>&mdash;open a file for reading and appending
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1296 in synchronous mode.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1297 If the file does not exist, it will be created
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1298 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1299
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1300 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1301 <literal>r</literal>&mdash;open a file for reading.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1302 An exception occurs if the file does not exist
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1303 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1304
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1305 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1306 <literal>r+</literal>&mdash;open a file for reading and writing.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1307 An exception occurs if the file does not exist
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1308 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1309
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1310 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1311 <literal>rs+</literal>&mdash;open a file for reading and writing
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1312 in synchronous mode.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1313 Instructs the operating system to bypass the local file system cache
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1314 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1315
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1316 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1317 <literal>w</literal>&mdash;open a file for writing.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1318 If the file does not exist, it will be created.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1319 If the file exists, it will be replaced
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1320 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1321
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1322 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1323 <literal>wx</literal>&mdash;the same as <literal>w</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1324 but fails if the file already exists
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1325 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1326
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1327 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1328 <literal>w+</literal>&mdash;open a file for reading and writing.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1329 If the file does not exist, it will be created.
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1330 If the file exists, it will be replaced
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1331 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1332
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1333 <listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1334 <literal>wx+</literal>&mdash;the same as <literal>w+</literal>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1335 but fails if the file already exists
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1336 </listitem>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1337
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1338 </list>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1339 </para>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1340
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1341 </section>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1342
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1343 </section>
001f2d905fd9 Documented fileSystem methods in njs.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2203
diff changeset
1344
2176
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1345 </section>
95b406f1f347 Added njs JSON API.
Yaroslav Zhuravlev <yar@nginx.com>
parents: 2175
diff changeset
1346
2175
cd4889fdcfa4 Moved njs HTTP and Stream API to a separate page.
Yaroslav Zhuravlev <yar@nginx.com>
parents:
diff changeset
1347 </article>