|
| 1 | +<!-- |
| 2 | +
|
| 3 | +@license Apache-2.0 |
| 4 | +
|
| 5 | +Copyright (c) 2025 The Stdlib Authors. |
| 6 | +
|
| 7 | +Licensed under the Apache License, Version 2.0 (the "License"); |
| 8 | +you may not use this file except in compliance with the License. |
| 9 | +You may obtain a copy of the License at |
| 10 | +
|
| 11 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 12 | +
|
| 13 | +Unless required by applicable law or agreed to in writing, software |
| 14 | +distributed under the License is distributed on an "AS IS" BASIS, |
| 15 | +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 16 | +See the License for the specific language governing permissions and |
| 17 | +limitations under the License. |
| 18 | +
|
| 19 | +--> |
| 20 | + |
| 21 | +# Assert DataView |
| 22 | + |
| 23 | +> Assert that a Node-API value is a DataView. |
| 24 | +
|
| 25 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 26 | + |
| 27 | +<section class="intro"> |
| 28 | + |
| 29 | +</section> |
| 30 | + |
| 31 | +<!-- /.intro --> |
| 32 | + |
| 33 | +<!-- Package usage documentation. --> |
| 34 | + |
| 35 | +<section class="usage"> |
| 36 | + |
| 37 | +## Usage |
| 38 | + |
| 39 | +```javascript |
| 40 | +var headerDir = require( '@stdlib/assert/napi/is-dataview' ); |
| 41 | +``` |
| 42 | + |
| 43 | +#### headerDir |
| 44 | + |
| 45 | +Absolute file path for the directory containing header files for C APIs. |
| 46 | + |
| 47 | +```javascript |
| 48 | +var dir = headerDir; |
| 49 | +// returns <string> |
| 50 | +``` |
| 51 | + |
| 52 | +</section> |
| 53 | + |
| 54 | +<!-- /.usage --> |
| 55 | + |
| 56 | +<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 57 | + |
| 58 | +<section class="notes"> |
| 59 | + |
| 60 | +</section> |
| 61 | + |
| 62 | +<!-- /.notes --> |
| 63 | + |
| 64 | +<!-- Package usage examples. --> |
| 65 | + |
| 66 | +<section class="examples"> |
| 67 | + |
| 68 | +## Examples |
| 69 | + |
| 70 | +```javascript |
| 71 | +var headerDir = require( '@stdlib/assert/napi/is-dataview' ); |
| 72 | + |
| 73 | +console.log( headerDir ); |
| 74 | +// => <string> |
| 75 | +``` |
| 76 | + |
| 77 | +</section> |
| 78 | + |
| 79 | +<!-- /.examples --> |
| 80 | + |
| 81 | +<!-- C interface documentation. --> |
| 82 | + |
| 83 | +* * * |
| 84 | + |
| 85 | +<section class="c"> |
| 86 | + |
| 87 | +## C APIs |
| 88 | + |
| 89 | +<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> |
| 90 | + |
| 91 | +<section class="intro"> |
| 92 | + |
| 93 | +</section> |
| 94 | + |
| 95 | +<!-- /.intro --> |
| 96 | + |
| 97 | +<!-- C usage documentation. --> |
| 98 | + |
| 99 | +<section class="usage"> |
| 100 | + |
| 101 | +### Usage |
| 102 | + |
| 103 | +```c |
| 104 | +#include "stdlib/assert/napi/is_dataview.h" |
| 105 | +``` |
| 106 | + |
| 107 | +#### stdlib_assert_napi_value_is_dataview( env, value, \*message, \*err ) |
| 108 | + |
| 109 | +Asserts that a Node-API value is a DataView. |
| 110 | + |
| 111 | +```c |
| 112 | +#include "stdlib/assert/napi/is_dataview.h" |
| 113 | +#include <node_api.h> |
| 114 | + |
| 115 | +static napi_value addon( napi_env env, napi_callback_info info ) { |
| 116 | + napi_value value; |
| 117 | + |
| 118 | + // ... |
| 119 | + |
| 120 | + napi_value err; |
| 121 | + napi_status status = stdlib_assert_napi_value_is_dataview( env, value, "Must be a DataView.", &err ); |
| 122 | + assert( status == napi_ok ); |
| 123 | + if ( err != NULL ) { |
| 124 | + assert( napi_throw( env, err ) == napi_ok ); |
| 125 | + return NULL; |
| 126 | + } |
| 127 | + |
| 128 | + // ... |
| 129 | +} |
| 130 | +``` |
| 131 | +
|
| 132 | +The function accepts the following arguments: |
| 133 | +
|
| 134 | +- **env**: `[in] napi_env` environment under which the function is invoked. |
| 135 | +- **value**: `[in] napi_value` Node-API value. |
| 136 | +- **message**: `[in] char*` error message. |
| 137 | +- **err**: `[out] napi_value*` pointer for storing a JavaScript error. |
| 138 | +
|
| 139 | +```c |
| 140 | +napi_status stdlib_assert_napi_value_is_dataview( const napi_env env, const napi_value value, const char *message, napi_value *err ); |
| 141 | +``` |
| 142 | + |
| 143 | +The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success). |
| 144 | + |
| 145 | +</section> |
| 146 | + |
| 147 | +<!-- /.usage --> |
| 148 | + |
| 149 | +<!-- C API usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 150 | + |
| 151 | +<section class="notes"> |
| 152 | + |
| 153 | +### Notes |
| 154 | + |
| 155 | +- If not provided a DataView, the function sets `err` with a JavaScript error; otherwise, `err` is set to `NULL`. |
| 156 | + |
| 157 | +</section> |
| 158 | + |
| 159 | +<!-- /.notes --> |
| 160 | + |
| 161 | +<!-- C API usage examples. --> |
| 162 | + |
| 163 | +<section class="examples"> |
| 164 | + |
| 165 | +</section> |
| 166 | + |
| 167 | +<!-- /.examples --> |
| 168 | + |
| 169 | +</section> |
| 170 | + |
| 171 | +<!-- /.c --> |
| 172 | + |
| 173 | +<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 174 | + |
| 175 | +<section class="references"> |
| 176 | + |
| 177 | +</section> |
| 178 | + |
| 179 | +<!-- /.references --> |
| 180 | + |
| 181 | +<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. --> |
| 182 | + |
| 183 | +<section class="related"> |
| 184 | + |
| 185 | +</section> |
| 186 | + |
| 187 | +<!-- /.related --> |
| 188 | + |
| 189 | +<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> |
| 190 | + |
| 191 | +<section class="links"> |
| 192 | + |
| 193 | +</section> |
| 194 | + |
| 195 | +<!-- /.links --> |
0 commit comments