<commit_before><!--

@license Apache-2.0

Copyright (c) 2020 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Add-on Arguments

> C API for validating, extracting, and transforming (to native C types) function arguments provided to a strided array N-API add-on interface.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```c
#include "stdlib/strided/napi/addon_arguments.h"
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_napi_addon_arguments( env, argv, nargs, nin, \*arrays[], \*shape, \*strides, \*types, \*err )

Validates, extracts, and transforms (to native C types) function arguments provided to a strided array N-API add-on interface.

```c
#include <node_api.h>
#include <stdint.h>
#include <assert.h>

// ...

/*
* Receives JavaScript callback invocation data via N-API.
*
* @param env    environment under which the function is invoked
* @param info   callback data
* @return       N-API value
*/
napi_value addon( napi_env env, napi_callback_info info ) {
    napi_status status;

    // ...

    int64_t nargs = 7;
    int64_t nin = 2;

    // Get callback arguments:
    size_t argc = 7;
    napi_value argv[ 7 ];
    status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
    assert( status == napi_ok );

    // ...

    // Initialize destination arrays:
    uint8_t *arrays[ 3 ];
    int64_t strides[ 3 ];
    int64_t shape[ 1 ];
    int32_t types[ 3 ];

    // Process the provided arguments:
    napi_value err;
    status = stdlib_strided_napi_addon_arguments( env, argv, nargs, nin, arrays, shape, strides, types, &err );
    assert( status == napi_ok );

    // ...

}

// ...
```

The function accepts the following arguments:

-   **env** (`in; napi_env`): environment under which the function is invoked.
-   **argv** (`in; napi_value`): strided function arguments.
-   **nargs** (`in; int64_t`): total number of expected arguments.
-   **nin** (`in; int64_t`): number of input strided array arguments.
-   **arrays** (`out; uint8_t *`): destination array for storing pointers to both input and output strided byte arrays.
-   **shape** (`out; int64_t *`): destination array for storing the array shape (dimensions).
-   **strides** (`out; int64_t *`): destination array for storing array strides (in bytes) for each strided array.
-   **types** (`out; int32_t *`): destination array for storing strided array argument data types.
-   **err** (`out; napi_value *`): pointer for storing a JavaScript error.

```c
napi_status stdlib_strided_napi_addon_arguments( const napi_env env, const napi_value *argv, const int64_t nargs, const int64_t nin, uint8_t *arrays[], int64_t *shape, int64_t *strides, int32_t *types, napi_value *err );
```

The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success).

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

-   The function assumes the following argument order:
<commit_msg>Update markup<commit_after><!--

@license Apache-2.0

Copyright (c) 2020 The Stdlib Authors.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

-->

# Add-on Arguments

> C API for validating, extracting, and transforming (to native C types) function arguments provided to a strided array N-API add-on interface.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## Usage

```c
#include "stdlib/strided/napi/addon_arguments.h"
```

<!-- lint disable maximum-heading-length -->

#### stdlib_strided_napi_addon_arguments( env, argv, nargs, nin, \*arrays[], \*shape, \*strides, \*types, \*err )

Validates, extracts, and transforms (to native C types) function arguments provided to a strided array N-API add-on interface.

```c
#include <node_api.h>
#include <stdint.h>
#include <assert.h>

// ...

/*
* Receives JavaScript callback invocation data via N-API.
*
* @param env    environment under which the function is invoked
* @param info   callback data
* @return       N-API value
*/
napi_value addon( napi_env env, napi_callback_info info ) {
    napi_status status;

    // ...

    int64_t nargs = 7;
    int64_t nin = 2;

    // Get callback arguments:
    size_t argc = 7;
    napi_value argv[ 7 ];
    status = napi_get_cb_info( env, info, &argc, argv, NULL, NULL );
    assert( status == napi_ok );

    // ...

    // Initialize destination arrays:
    uint8_t *arrays[ 3 ];
    int64_t strides[ 3 ];
    int64_t shape[ 1 ];
    int32_t types[ 3 ];

    // Process the provided arguments:
    napi_value err;
    status = stdlib_strided_napi_addon_arguments( env, argv, nargs, nin, arrays, shape, strides, types, &err );
    assert( status == napi_ok );

    // ...

}

// ...
```

The function accepts the following arguments:

-   \[in] **env** (`napi_env`): environment under which the function is invoked.
-   \[in] **argv** (`napi_value`): strided function arguments.
-   \[in] **nargs** (`int64_t`): total number of expected arguments.
-   \[in] **nin** (`int64_t`): number of input strided array arguments.
-   \[out] **arrays** (`uint8_t *`): destination array for storing pointers to both input and output strided byte arrays.
-   \[out] **shape** (`int64_t *`): destination array for storing the array shape (dimensions).
-   \[out] **strides** (`int64_t *`): destination array for storing array strides (in bytes) for each strided array.
-   \[out] **types** (`int32_t *`): destination array for storing strided array argument data types.
-   \[out] **err** (`napi_value *`): pointer for storing a JavaScript error.

```c
napi_status stdlib_strided_napi_addon_arguments( const napi_env env, const napi_value *argv, const int64_t nargs, const int64_t nin, uint8_t *arrays[], int64_t *shape, int64_t *strides, int32_t *types, napi_value *err );
```

The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success).

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## Notes

-   The function assumes the following argument order:

{'fraction_non_alphanumeric': 0.12401883830455258, 'fraction_numerical': 0.013343799058084773, 'mean_word_length': 3.658744667885436, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 35, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '137422', 'n_tokens_mistral': 2470, 'n_tokens_neox': 2314, 'n_words': 901}