diff --git a/lib/node_modules/@stdlib/napi/create-bool/README.md b/lib/node_modules/@stdlib/napi/create-bool/README.md new file mode 100644 index 000000000000..7eeaac39f58b --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/README.md @@ -0,0 +1,229 @@ + + +# create_bool + +> Convert a boolean value to a Node-API value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var headerDir = require( '@stdlib/napi/create-bool' ); +``` + +#### headerDir + +Absolute file path for the directory containing header files for C APIs. + +```javascript +var dir = headerDir; +// returns +``` + +
+ + + + + +
+ +
+ + + + + +
+ +## Examples + +```javascript +var headerDir = require( '@stdlib/napi/create-bool' ); + +console.log( headerDir ); +// => +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/napi/create_bool.h" +``` + +#### stdlib_napi_create_bool( env, value, \*out ) + +Converts a boolean value to a Node-API value. + +```c +#include "stdlib/napi/create_bool.h" +#include +#include + +static napi_value addon( napi_env env, napi_callback_info info ) { + + // ... + + napi_value value; + napi_status status = stdlib_napi_create_bool( env, true, &value ); + assert( status == napi_ok ); + if ( err != NULL ) { + assert( napi_throw( env, err ) == napi_ok ); + return NULL; + } + + // ... +} +``` + +The function accepts the following arguments: + +- **env**: `[in] napi_env` environment under which the function is invoked. +- **value**: `[in] bool` boolean value. +- **out**: `[out] napi_value*` destination for storing output value. + +```c +napi_status stdlib_napi_create_bool( const napi_env env, const bool value, napi_value *out ); +``` + +The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success). + +#### STDLIB_NAPI_CREATE_BOOL( env, expression, name ) + +Macro for converting a boolean value to a Node-API value. + +```c +#include "stdlib/napi/create_bool.h" +#include "stdlib/napi/argv_bool.h" +#include "stdlib/napi/argv.h" +#include +#include + +static bool fcn( const bool v ) { + return v; +} + +// ... + +static napi_value addon( napi_env env, napi_callback_info info ) { + // Retrieve add-on callback arguments: + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); + + // Convert the first argument to a C type: + STDLIB_NAPI_ARGV_BOOL( env, value, argv, 0 ); + + // ... + + // Convert a value having a C type to a Node-API value: + STDLIB_NAPI_CREATE_BOOL( env, fcn( value ), out ); + + return out; +} +``` + +The macro expects the following arguments: + +- **env**: environment under which the callback is invoked. +- **expression**: expression returning a boolean value. +- **name**: output variable name. + +
+ + + + + +
+ +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/napi/create-bool/binding.gyp b/lib/node_modules/@stdlib/napi/create-bool/binding.gyp new file mode 100644 index 000000000000..68a1ca11d160 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. + +# A `.gyp` file for building a Node.js native add-on. +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # List of files to include in this file: + 'includes': [ + './include.gypi', + ], + + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Target name should match the add-on export name: + 'addon_target_name%': 'addon', + + # Set variables based on the host OS: + 'conditions': [ + [ + 'OS=="win"', + { + # Define the object file suffix: + 'obj': 'obj', + }, + { + # Define the object file suffix: + 'obj': 'o', + } + ], # end condition (OS=="win") + ], # end conditions + }, # end variables + + # Define compile targets: + 'targets': [ + + # Target to generate an add-on: + { + # The target name should match the add-on export name: + 'target_name': '<(addon_target_name)', + + # Define dependencies: + 'dependencies': [], + + # Define directories which contain relevant include headers: + 'include_dirs': [ + # Local include directory: + '<@(include_dirs)', + ], + + # List of source files: + 'sources': [ + '<@(src_files)', + ], + + # Settings which should be applied when a target's object files are used as linker input: + 'link_settings': { + # Define libraries: + 'libraries': [ + '<@(libraries)', + ], + + # Define library directories: + 'library_dirs': [ + '<@(library_dirs)', + ], + }, + + # C/C++ compiler flags: + 'cflags': [ + # Enable commonly used warning options: + '-Wall', + + # Aggressive optimization: + '-O3', + ], + + # C specific compiler flags: + 'cflags_c': [ + # Specify the C standard to which a program is expected to conform: + '-std=c99', + ], + + # C++ specific compiler flags: + 'cflags_cpp': [ + # Specify the C++ standard to which a program is expected to conform: + '-std=c++11', + ], + + # Linker flags: + 'ldflags': [], + + # Apply conditions based on the host OS: + 'conditions': [ + [ + 'OS=="mac"', + { + # Linker flags: + 'ldflags': [ + '-undefined dynamic_lookup', + '-Wl,-no-pie', + '-Wl,-search_paths_first', + ], + }, + ], # end condition (OS=="mac") + [ + 'OS!="win"', + { + # C/C++ flags: + 'cflags': [ + # Generate platform-independent code: + '-fPIC', + ], + }, + ], # end condition (OS!="win") + ], # end conditions + }, # end target <(addon_target_name) + + # Target to copy a generated add-on to a standard location: + { + 'target_name': 'copy_addon', + + # Declare that the output of this target is not linked: + 'type': 'none', + + # Define dependencies: + 'dependencies': [ + # Require that the add-on be generated before building this target: + '<(addon_target_name)', + ], + + # Define a list of actions: + 'actions': [ + { + 'action_name': 'copy_addon', + 'message': 'Copying addon...', + + # Explicitly list the inputs in the command-line invocation below: + 'inputs': [], + + # Declare the expected outputs: + 'outputs': [ + '<(addon_output_dir)/<(addon_target_name).node', + ], + + # Define the command-line invocation: + 'action': [ + 'cp', + '<(PRODUCT_DIR)/<(addon_target_name).node', + '<(addon_output_dir)/<(addon_target_name).node', + ], + }, + ], # end actions + }, # end target copy_addon + ], # end targets +} diff --git a/lib/node_modules/@stdlib/napi/create-bool/docs/types/index.d.ts b/lib/node_modules/@stdlib/napi/create-bool/docs/types/index.d.ts new file mode 100644 index 000000000000..fd6d90004849 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +// TypeScript Version: 4.1 + +/** +* Absolute file path for the directory containing header files for C APIs. +* +* @example +* var dir = headerDir; +* // returns +*/ +declare const headerDir: string; + + +// EXPORTS // + +export = headerDir; diff --git a/lib/node_modules/@stdlib/napi/create-bool/docs/types/test.ts b/lib/node_modules/@stdlib/napi/create-bool/docs/types/test.ts new file mode 100644 index 000000000000..d7e59543e51e --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +import headerDir = require( './index' ); + + +// TESTS // + +// The variable is a string... +{ + // eslint-disable-next-line @typescript-eslint/no-unused-expressions + headerDir; // $ExpectType string +} diff --git a/lib/node_modules/@stdlib/napi/create-bool/examples/index.js b/lib/node_modules/@stdlib/napi/create-bool/examples/index.js new file mode 100644 index 000000000000..b0b1fa522f05 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/examples/index.js @@ -0,0 +1,24 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +var headerDir = require( './../lib' ); + +console.log( headerDir ); +// => diff --git a/lib/node_modules/@stdlib/napi/create-bool/include.gypi b/lib/node_modules/@stdlib/napi/create-bool/include.gypi new file mode 100644 index 000000000000..ecfaf82a3279 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. + +# A GYP include file for building a Node.js native add-on. +# +# Main documentation: +# +# [1]: https://gyp.gsrc.io/docs/InputFormatReference.md +# [2]: https://gyp.gsrc.io/docs/UserDocumentation.md +{ + # Define variables to be used throughout the configuration for all targets: + 'variables': { + # Source directory: + 'src_dir': './src', + + # Include directories: + 'include_dirs': [ + ' +#include + +/** +* Macro for converting a boolean to a Node-API value. +* +* @param env environment under which the function is invoked +* @param expression expression returning a boolean value +* @param name output variable name +* +* @example +# #include "stdlib/napi/create_bool.h" +* #include "stdlib/napi/argv_bool.h" +* #include "stdlib/napi/argv.h" +* #include +* +* static bool fcn( const bool v ) { +* return v; +* } +* +* // ... +* +* static napi_value addon( napi_env env, napi_callback_info info ) { +* // Retrieve add-on callback arguments: +* STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ); +* +* // Convert the first argument to a C type: +* STDLIB_NAPI_ARGV_BOOL( env, value, argv, 0 ); +* +* // ... +* +* // Convert a value having a C type to a Node-API value: +* STDLIB_NAPI_CREATE_BOOL( env, fcn( value ), out ); +* return out; +* } +*/ +#define STDLIB_NAPI_CREATE_BOOL( env, expression, name ) \ + napi_value name; \ + stdlib_napi_create_bool( env, expression, &name ); + +/* +* If C++, prevent name mangling so that the compiler emits a binary file having undecorated names, thus mirroring the behavior of a C compiler. +*/ +#ifdef __cplusplus +extern "C" { +#endif + +/** +* Converts a boolean to a Node-API value. +*/ +napi_status stdlib_napi_create_bool( const napi_env env, const bool value, napi_value *out ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_NAPI_CREATE_BOOL_H diff --git a/lib/node_modules/@stdlib/napi/create-bool/lib/browser.js b/lib/node_modules/@stdlib/napi/create-bool/lib/browser.js new file mode 100644 index 000000000000..104fe93e3a6c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/lib/browser.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MAIN // + +var dir = null; + + +// EXPORTS // + +module.exports = dir; diff --git a/lib/node_modules/@stdlib/napi/create-bool/lib/index.js b/lib/node_modules/@stdlib/napi/create-bool/lib/index.js new file mode 100644 index 000000000000..57fd1e971c4a --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/lib/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +/** +* Absolute file path for the directory containing header files for C APIs. +* +* @module @stdlib/napi/create-bool +* +* @example +* var headerDir = require( '@stdlib/napi/create-bool' ); +* +* console.log( headerDir ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/napi/create-bool/lib/main.js b/lib/node_modules/@stdlib/napi/create-bool/lib/main.js new file mode 100644 index 000000000000..d09f5d231f4d --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/lib/main.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; + + +// MAIN // + +var dir = resolve( __dirname, '..', 'include' ); + + +// EXPORTS // + +module.exports = dir; diff --git a/lib/node_modules/@stdlib/napi/create-bool/lib/native.js b/lib/node_modules/@stdlib/napi/create-bool/lib/native.js new file mode 100644 index 000000000000..bade3e048960 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/lib/native.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MODULES // + +var addon = require( './../src/addon.node' ); + + +// MAIN // + +/** +* Wrapper function exposing the C API to JavaScript. +* +* @private +* @param {boolean} v - input value +* @returns {boolean} input value +* +* @example +* var v = wrapper( true ); +* // returns true +*/ +function wrapper( v ) { + return addon( v ); +} + + +// EXPORTS // + +module.exports = wrapper; diff --git a/lib/node_modules/@stdlib/napi/create-bool/manifest.json b/lib/node_modules/@stdlib/napi/create-bool/manifest.json new file mode 100644 index 000000000000..533b753a4109 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/manifest.json @@ -0,0 +1,42 @@ +{ + "options": {}, + "fields": [ + { + "field": "src", + "resolve": true, + "relative": true + }, + { + "field": "include", + "resolve": true, + "relative": true + }, + { + "field": "libraries", + "resolve": false, + "relative": false + }, + { + "field": "libpath", + "resolve": true, + "relative": false + } + ], + "confs": [ + { + "src": [ + "./src/main.c" + ], + "include": [ + "./include" + ], + "libraries": [], + "libpath": [], + "dependencies": [ + "@stdlib/assert/napi/status-ok", + "@stdlib/napi/argv-bool", + "@stdlib/napi/argv" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/napi/create-bool/package.json b/lib/node_modules/@stdlib/napi/create-bool/package.json new file mode 100644 index 000000000000..8aa66e222185 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/package.json @@ -0,0 +1,64 @@ +{ + "name": "@stdlib/napi", + "version": "0.0.0", + "description": "C APIs for creating Node-API native add-ons.", + "license": "Apache-2.0", + "author": { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + }, + "contributors": [ + { + "name": "The Stdlib Authors", + "url": "https://github.com/stdlib-js/stdlib/graphs/contributors" + } + ], + "main": "./lib", + "browser": "./lib/browser.js", + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "test": "./test" + }, + "types": "./docs/types", + "scripts": {}, + "homepage": "https://github.com/stdlib-js/stdlib", + "repository": { + "type": "git", + "url": "git://github.com/stdlib-js/stdlib.git" + }, + "bugs": { + "url": "https://github.com/stdlib-js/stdlib/issues" + }, + "dependencies": {}, + "devDependencies": {}, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "napi", + "n-api", + "node-api", + "addon" + ], + "__stdlib__": { + "envs": { + "browser": false + } + } +} diff --git a/lib/node_modules/@stdlib/napi/create-bool/src/Makefile b/lib/node_modules/@stdlib/napi/create-bool/src/Makefile new file mode 100644 index 000000000000..7733b6180cb4 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2025 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. +#/ + +# VARIABLES # + +ifndef VERBOSE + QUIET := @ +else + QUIET := +endif + +# Determine the OS ([1][1], [2][2]). +# +# [1]: https://en.wikipedia.org/wiki/Uname#Examples +# [2]: http://stackoverflow.com/a/27776822/2225624 +OS ?= $(shell uname) +ifneq (, $(findstring MINGW,$(OS))) + OS := WINNT +else +ifneq (, $(findstring MSYS,$(OS))) + OS := WINNT +else +ifneq (, $(findstring CYGWIN,$(OS))) + OS := WINNT +else +ifneq (, $(findstring Windows_NT,$(OS))) + OS := WINNT +endif +endif +endif +endif + + +# RULES # + +#/ +# Removes generated files for building an add-on. +# +# @example +# make clean-addon +#/ +clean-addon: + $(QUIET) -rm -f *.o *.node + +.PHONY: clean-addon + +#/ +# Removes generated files. +# +# @example +# make clean +#/ +clean: clean-addon + +.PHONY: clean diff --git a/lib/node_modules/@stdlib/napi/create-bool/src/addon.c b/lib/node_modules/@stdlib/napi/create-bool/src/addon.c new file mode 100644 index 000000000000..9d2a8d30f84d --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/src/addon.c @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/napi/create_bool.h" +#include "stdlib/napi/argv_bool.h" +#include "stdlib/napi/argv.h" +#include +#include +#include + +/** +* Identity function. +* +* @param v input value +* @return input value +*/ +static bool identity( const bool v ) { + return v; +} + +/** +* Receives JavaScript callback invocation data. +* +* @param env environment under which the function is invoked +* @param info callback data +* @return Node-API value +*/ +static napi_value addon( napi_env env, napi_callback_info info ) { + STDLIB_NAPI_ARGV( env, info, argv, argc, 1 ) + STDLIB_NAPI_ARGV_BOOL( env, value, argv, 0 ) + bool out = identity( value ); + STDLIB_NAPI_CREATE_BOOL( env, out, v ) + return v; +} + +/** +* Initializes a Node-API module. +* +* @param env environment under which the function is invoked +* @param exports exports object +* @return main export +*/ +static napi_value init( napi_env env, napi_value exports ) { + napi_value fcn; + napi_status status = napi_create_function( env, "exports", NAPI_AUTO_LENGTH, addon, NULL, &fcn ); + assert( status == napi_ok ); + return fcn; +} + +NAPI_MODULE( NODE_GYP_MODULE_NAME, init ) diff --git a/lib/node_modules/@stdlib/napi/create-bool/src/main.c b/lib/node_modules/@stdlib/napi/create-bool/src/main.c new file mode 100644 index 000000000000..c1eb37aadb30 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/src/main.c @@ -0,0 +1,55 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +#include "stdlib/napi/create_bool.h" +#include "stdlib/assert/napi/status_ok.h" +#include +#include + +/** +* Converts a boolean to a Node-API value. +* +* @param env environment under which the function is invoked +* @param value boolean value +* @param out destination for storing output value +* @return status code indicating success or failure (returns `napi_ok` if success) +* +* @example +* #include "stdlib/napi/create_bool.h" +* #include +* #include +* +* static napi_value addon( napi_env env, napi_callback_info info ) { +* +* // ... +* +* napi_value value; +* napi_status status = stdlib_napi_create_bool( env, true, &value ); +* assert( status == napi_ok ); +* if ( err != NULL ) { +* assert( napi_throw( env, err ) == napi_ok ); +* return NULL; +* } +* +* // ... +* } +*/ +napi_status stdlib_napi_create_bool( const napi_env env, const bool value, napi_value *out ) { + STDLIB_ASSERT_NAPI_STATUS_OK_RET_VALUE( env, napi_get_boolean( env, value, out ), "", napi_ok ) + return napi_ok; +} diff --git a/lib/node_modules/@stdlib/napi/create-bool/test/test.browser.js b/lib/node_modules/@stdlib/napi/create-bool/test/test.browser.js new file mode 100644 index 000000000000..ed4a1e26b956 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/test/test.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var headerDir = require( './../lib/browser.js' ); + + +// TESTS // + +tape( 'main export is null', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( headerDir, null, 'main export is null' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/napi/create-bool/test/test.js b/lib/node_modules/@stdlib/napi/create-bool/test/test.js new file mode 100644 index 000000000000..3efe6d8d766c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/test/test.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var headerDir = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': IS_BROWSER +}; + + +// TESTS // + +tape( 'main export is a string', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof headerDir, 'string', 'main export is a string' ); + t.end(); +}); + +tape( 'the exported value corresponds to the package directory containing header files', opts, function test( t ) { + var dir = resolve( __dirname, '..', 'include' ); + t.strictEqual( headerDir, dir, 'exports expected value' ); + t.end(); +}); diff --git a/lib/node_modules/@stdlib/napi/create-bool/test/test.native.js b/lib/node_modules/@stdlib/napi/create-bool/test/test.native.js new file mode 100644 index 000000000000..b4cf0fbfcc9f --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-bool/test/test.native.js @@ -0,0 +1,88 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2025 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. +*/ + +'use strict'; + +// MODULES // + +var resolve = require( 'path' ).resolve; +var tape = require( 'tape' ); +var tryRequire = require( '@stdlib/utils/try-require' ); + + +// VARIABLES // + +var addon = tryRequire( resolve( __dirname, './../lib/native.js' ) ); +var opts = { + 'skip': ( addon instanceof Error ) +}; + + +// TESTS // + +tape( 'main export is a function', opts, function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof addon, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function throws an error if provided an argument which is not a number', opts, function test( t ) { + var values; + var i; + + values = [ + '5', + null, + void 0, + [], + {}, + NaN, + 0, + 1.0 + ]; + for ( i = 0; i < values.length; i++ ) { + t.throws( badValue( values[ i ] ), Error, 'throws an error when provided '+values[ i ] ); + } + t.end(); + + function badValue( value ) { + return function badValue() { + addon( value ); + }; + } +}); + +tape( 'the function does not throw an error if provided a boolean', opts, function test( t ) { + var values; + var v; + var i; + + values = [ + true, + false + ]; + for ( i = 0; i < values.length; i++ ) { + v = addon( values[ i ] ); + if ( values[ i ] === values[ i ] ) { + t.strictEqual( v, values[ i ], 'returns expected value when provided '+values[ i ] ); + } else { + t.strictEqual( v !== v, true, 'returns expected value when provided '+values[ i ] ); + } + } + t.end(); +});