1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
|
# Value
`Napi::Value` is the C++ manifestation of a JavaScript value.
Value is a the base class upon which other JavaScript values such as Number, Boolean, String, and Object are based.
The following classes inherit, either directly or indirectly, from `Napi::Value`:
- [`Napi::Array`](array.md)
- [`Napi::ArrayBuffer`](array_buffer.md)
- [`Napi::Boolean`](boolean.md)
- [`Napi::Buffer`](buffer.md)
- [`Napi::Date`](date.md)
- [`Napi::External`](external.md)
- [`Napi::Function`](function.md)
- [`Napi::Name`](name.md)
- [`Napi::Number`](number.md)
- [`Napi::Object`](object.md)
- [`Napi::String`](string.md)
- [`Napi::Symbol`](symbol.md)
- [`Napi::TypedArray`](typed_array.md)
- [`Napi::TypedArrayOf`](typed_array_of.md)
## Methods
### Empty Constructor
```cpp
Napi::Value::Value();
```
Creates a new *empty* `Napi::Value` instance.
### Constructor
```cpp
Napi::Value::Value(napi_env env, napi_value value);
```
- `[in] env`: The `napi_env` environment in which to construct the `Napi::Value` object.
- `[in] value`: The C++ primitive from which to instantiate the `Napi::Value`. `value` may be any of:
- `bool`
- Any integer type
- Any floating point type
- `const char*` (encoded using UTF-8, null-terminated)
- `const char16_t*` (encoded using UTF-16-LE, null-terminated)
- `std::string` (encoded using UTF-8)
- `std::u16string`
- `Napi::Value`
- `napi_value`
### From
```cpp
template <typename T> static Napi::Value Napi::Value::From(napi_env env, const T& value);
```
- `[in] env`: The `napi_env` environment in which to create the `Napi::Value` object.
- `[in] value`: The N-API primitive value from which to create the `Napi::Value` object.
Returns a `Napi::Value` object from an N-API primitive value.
### operator napi_value
```cpp
operator napi_value() const;
```
Returns this Value's N-API value primitive.
Returns `nullptr` if this `Napi::Value` is *empty*.
### operator ==
```cpp
bool Napi::Value::operator ==(const Napi::Value& other) const;
```
- `[in] other`: The `Napi::Value` object to be compared.
Returns a `bool` indicating if this `Napi::Value` strictly equals another `Napi::Value`.
### operator !=
```cpp
bool Napi::Value::operator !=(const Napi::Value& other) const;
```
- `[in] other`: The `Napi::Value` object to be compared.
Returns a `bool` indicating if this `Napi::Value` does not strictly equal another `Napi::Value`.
### StrictEquals
```cpp
bool Napi::Value::StrictEquals(const Napi::Value& other) const;
```
- `[in] other`: The `Napi::Value` object to be compared.
Returns a `bool` indicating if this `Napi::Value` strictly equals another `Napi::Value`.
### Env
```cpp
Napi::Env Napi::Value::Env() const;
```
Returns the `Napi::Env` environment this value is associated with.
### IsEmpty
```cpp
bool Napi::Value::IsEmpty() const;
```
Returns a `bool` indicating if this `Napi::Value` is *empty* (uninitialized).
An empty `Napi::Value` is invalid, and most attempts to perform an operation on an empty Value will result in an exception.
Note an empty `Napi::Value` is distinct from JavaScript `null` or `undefined`, which are valid values.
When C++ exceptions are disabled at compile time, a method with a `Napi::Value` return type may return an empty Value to indicate a pending exception. So when not using C++ exceptions, callers should check whether this `Napi::Value` is empty before attempting to use it.
### Type
```cpp
napi_valuetype Napi::Value::Type() const;
```
Returns the `napi_valuetype` type of the `Napi::Value`.
### IsUndefined
```cpp
bool Napi::Value::IsUndefined() const;
```
Returns a `bool` indicating if this `Napi::Value` is an undefined JavaScript value.
### IsNull
```cpp
bool Napi::Value::IsNull() const;
```
Returns a `bool` indicating if this `Napi::Value` is a null JavaScript value.
### IsBoolean
```cpp
bool Napi::Value::IsBoolean() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript boolean.
### IsNumber
```cpp
bool Napi::Value::IsNumber() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript number.
### IsString
```cpp
bool Napi::Value::IsString() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript string.
### IsSymbol
```cpp
bool Napi::Value::IsSymbol() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript symbol.
### IsArray
```cpp
bool Napi::Value::IsArray() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript array.
### IsArrayBuffer
```cpp
bool Napi::Value::IsArrayBuffer() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript array buffer.
### IsTypedArray
```cpp
bool Napi::Value::IsTypedArray() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript typed array.
### IsObject
```cpp
bool Napi::Value::IsObject() const;
```
Returns a `bool` indicating if this `Napi::Value` is JavaScript object.
### IsFunction
```cpp
bool Napi::Value::IsFunction() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript function.
### IsBuffer
```cpp
bool Napi::Value::IsBuffer() const;
```
Returns a `bool` indicating if this `Napi::Value` is a Node buffer.
### IsDate
```cpp
bool Napi::Value::IsDate() const;
```
Returns a `bool` indicating if this `Napi::Value` is a JavaScript date.
### As
```cpp
template <typename T> T Napi::Value::As() const;
```
Casts to another type of `Napi::Value`, when the actual type is known or assumed.
This conversion does not coerce the type. Calling any methods inappropriate for the actual value type will throw `Napi::Error`.
### ToBoolean
```cpp
Napi::Boolean Napi::Value::ToBoolean() const;
```
Returns the `Napi::Value` coerced to a JavaScript boolean.
### ToNumber
```cpp
Napi::Number Napi::Value::ToNumber() const;
```
Returns the `Napi::Value` coerced to a JavaScript number.
### ToString
```cpp
Napi::String Napi::Value::ToString() const;
```
Returns the `Napi::Value` coerced to a JavaScript string.
### ToObject
```cpp
Napi::Object Napi::Value::ToObject() const;
```
Returns the `Napi::Value` coerced to a JavaScript object.
|