1 | ### esutils [![Build Status](https://secure.travis-ci.org/Constellation/esutils.svg)](http://travis-ci.org/Constellation/esutils)
|
2 | esutils ([esutils](http://github.com/Constellation/esutils)) is
|
3 | utility box for ECMAScript language tools.
|
4 |
|
5 | ### API
|
6 |
|
7 | ### ast
|
8 |
|
9 | #### ast.isExpression(node)
|
10 |
|
11 | Returns true if `node` is an Expression as defined in ECMA262 edition 5.1 section
|
12 | [11](https://es5.github.io/#x11).
|
13 |
|
14 | #### ast.isStatement(node)
|
15 |
|
16 | Returns true if `node` is a Statement as defined in ECMA262 edition 5.1 section
|
17 | [12](https://es5.github.io/#x12).
|
18 |
|
19 | #### ast.isIterationStatement(node)
|
20 |
|
21 | Returns true if `node` is an IterationStatement as defined in ECMA262 edition
|
22 | 5.1 section [12.6](https://es5.github.io/#x12.6).
|
23 |
|
24 | #### ast.isSourceElement(node)
|
25 |
|
26 | Returns true if `node` is a SourceElement as defined in ECMA262 edition 5.1
|
27 | section [14](https://es5.github.io/#x14).
|
28 |
|
29 | #### ast.trailingStatement(node)
|
30 |
|
31 | Returns `Statement?` if `node` has trailing `Statement`.
|
32 | ```js
|
33 | if (cond)
|
34 | consequent;
|
35 | ```
|
36 | When taking this `IfStatement`, returns `consequent;` statement.
|
37 |
|
38 | #### ast.isProblematicIfStatement(node)
|
39 |
|
40 | Returns true if `node` is a problematic IfStatement. If `node` is a problematic `IfStatement`, `node` cannot be represented as an one on one JavaScript code.
|
41 | ```js
|
42 | {
|
43 | type: 'IfStatement',
|
44 | consequent: {
|
45 | type: 'WithStatement',
|
46 | body: {
|
47 | type: 'IfStatement',
|
48 | consequent: {type: 'EmptyStatement'}
|
49 | }
|
50 | },
|
51 | alternate: {type: 'EmptyStatement'}
|
52 | }
|
53 | ```
|
54 | The above node cannot be represented as a JavaScript code, since the top level `else` alternate belongs to an inner `IfStatement`.
|
55 |
|
56 |
|
57 | ### code
|
58 |
|
59 | #### code.isDecimalDigit(code)
|
60 |
|
61 | Return true if provided code is decimal digit.
|
62 |
|
63 | #### code.isHexDigit(code)
|
64 |
|
65 | Return true if provided code is hexadecimal digit.
|
66 |
|
67 | #### code.isOctalDigit(code)
|
68 |
|
69 | Return true if provided code is octal digit.
|
70 |
|
71 | #### code.isWhiteSpace(code)
|
72 |
|
73 | Return true if provided code is white space. White space characters are formally defined in ECMA262.
|
74 |
|
75 | #### code.isLineTerminator(code)
|
76 |
|
77 | Return true if provided code is line terminator. Line terminator characters are formally defined in ECMA262.
|
78 |
|
79 | #### code.isIdentifierStart(code)
|
80 |
|
81 | Return true if provided code can be the first character of ECMA262 Identifier. They are formally defined in ECMA262.
|
82 |
|
83 | #### code.isIdentifierPart(code)
|
84 |
|
85 | Return true if provided code can be the trailing character of ECMA262 Identifier. They are formally defined in ECMA262.
|
86 |
|
87 | ### keyword
|
88 |
|
89 | #### keyword.isKeywordES5(id, strict)
|
90 |
|
91 | Returns `true` if provided identifier string is a Keyword or Future Reserved Word
|
92 | in ECMA262 edition 5.1. They are formally defined in ECMA262 sections
|
93 | [7.6.1.1](http://es5.github.io/#x7.6.1.1) and [7.6.1.2](http://es5.github.io/#x7.6.1.2),
|
94 | respectively. If the `strict` flag is truthy, this function additionally checks whether
|
95 | `id` is a Keyword or Future Reserved Word under strict mode.
|
96 |
|
97 | #### keyword.isKeywordES6(id, strict)
|
98 |
|
99 | Returns `true` if provided identifier string is a Keyword or Future Reserved Word
|
100 | in ECMA262 edition 6. They are formally defined in ECMA262 sections
|
101 | [11.6.2.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-keywords) and
|
102 | [11.6.2.2](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-future-reserved-words),
|
103 | respectively. If the `strict` flag is truthy, this function additionally checks whether
|
104 | `id` is a Keyword or Future Reserved Word under strict mode.
|
105 |
|
106 | #### keyword.isReservedWordES5(id, strict)
|
107 |
|
108 | Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 5.1.
|
109 | They are formally defined in ECMA262 section [7.6.1](http://es5.github.io/#x7.6.1).
|
110 | If the `strict` flag is truthy, this function additionally checks whether `id`
|
111 | is a Reserved Word under strict mode.
|
112 |
|
113 | #### keyword.isReservedWordES6(id, strict)
|
114 |
|
115 | Returns `true` if provided identifier string is a Reserved Word in ECMA262 edition 6.
|
116 | They are formally defined in ECMA262 section [11.6.2](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-reserved-words).
|
117 | If the `strict` flag is truthy, this function additionally checks whether `id`
|
118 | is a Reserved Word under strict mode.
|
119 |
|
120 | #### keyword.isRestrictedWord(id)
|
121 |
|
122 | Returns `true` if provided identifier string is one of `eval` or `arguments`.
|
123 | They are restricted in strict mode code throughout ECMA262 edition 5.1 and
|
124 | in ECMA262 edition 6 section [12.1.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers-static-semantics-early-errors).
|
125 |
|
126 | #### keyword.isIdentifierName(id)
|
127 |
|
128 | Return true if provided identifier string is an IdentifierName as specified in
|
129 | ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6).
|
130 |
|
131 | #### keyword.isIdentifierES5(id, strict)
|
132 |
|
133 | Return true if provided identifier string is an Identifier as specified in
|
134 | ECMA262 edition 5.1 section [7.6](https://es5.github.io/#x7.6). If the `strict`
|
135 | flag is truthy, this function additionally checks whether `id` is an Identifier
|
136 | under strict mode.
|
137 |
|
138 | #### keyword.isIdentifierES6(id, strict)
|
139 |
|
140 | Return true if provided identifier string is an Identifier as specified in
|
141 | ECMA262 edition 6 section [12.1](https://people.mozilla.org/~jorendorff/es6-draft.html#sec-identifiers).
|
142 | If the `strict` flag is truthy, this function additionally checks whether `id`
|
143 | is an Identifier under strict mode.
|
144 |
|
145 | ### License
|
146 |
|
147 | Copyright (C) 2013 [Yusuke Suzuki](http://github.com/Constellation)
|
148 | (twitter: [@Constellation](http://twitter.com/Constellation)) and other contributors.
|
149 |
|
150 | Redistribution and use in source and binary forms, with or without
|
151 | modification, are permitted provided that the following conditions are met:
|
152 |
|
153 | * Redistributions of source code must retain the above copyright
|
154 | notice, this list of conditions and the following disclaimer.
|
155 |
|
156 | * Redistributions in binary form must reproduce the above copyright
|
157 | notice, this list of conditions and the following disclaimer in the
|
158 | documentation and/or other materials provided with the distribution.
|
159 |
|
160 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
161 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
162 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
163 | ARE DISCLAIMED. IN NO EVENT SHALL <COPYRIGHT HOLDER> BE LIABLE FOR ANY
|
164 | DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
165 | (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
166 | LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
|
167 | ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
168 | (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
|
169 | THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|