diff --git a/lib/node_modules/@stdlib/napi/create-int64/README.md b/lib/node_modules/@stdlib/napi/create-int64/README.md new file mode 100644 index 000000000000..a14e30bac35e --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/README.md @@ -0,0 +1,230 @@ + + +# create_int64 + +> Convert a signed 64-bit integer to a Node-API value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var headerDir = require( '@stdlib/napi/create-int64' ); +``` + +#### 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-int64' ); + +console.log( headerDir ); +// => +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/napi/create_int64.h" +``` + +#### stdlib_napi_create_int64( env, value, \*out ) + +Converts a signed 64-bit integer to a Node-API BigInt value. + +```c +#include "stdlib/napi/create_int64.h" +#include + +static napi_value addon( napi_env env, napi_callback_info info ) { + + // ... + + napi_value value; + napi_status status = stdlib_napi_create_int64( env, 1, &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] int64_t` signed 64-bit integer. +- **out**: `[out] napi_value*` destination for storing output value. + +```c +napi_status stdlib_napi_create_int64( const napi_env env, const int64_t value, napi_value *out ); +``` + +The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success). + +#### STDLIB_NAPI_CREATE_INT64( env, expression, name ) + +Macro for converting a signed 64-bit integer to a Node-API BigInt value. + +```c +#include "stdlib/napi/create_int64.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv.h" +#include +#include + +static int64_t fcn( const int64_t 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_INT64( env, value, argv, 0 ); + + // ... + + // Convert a value having a C type to a Node-API value: + STDLIB_NAPI_CREATE_INT64( env, fcn( value ), out ); + + return out; +} +``` + +The macro expects the following arguments: + +- **env**: environment under which the callback is invoked. +- **expression**: expression returning a signed 64-bit integer. +- **name**: output variable name. + +
+ + + + + +
+ +- The generated JavaScript value is a `BigInt` (N-API Version 6+). + +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/napi/create-int64/binding.gyp b/lib/node_modules/@stdlib/napi/create-int64/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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-int64/docs/repl.txt b/lib/node_modules/@stdlib/napi/create-int64/docs/repl.txt new file mode 100644 index 000000000000..ba8eb98ffe65 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/docs/repl.txt @@ -0,0 +1,12 @@ + +{{alias}} + Absolute file path for the directory containing header files for C APIs. + + Returns + ------- + out: string + Absolute file path. + + Examples + -------- + > var dir = {{alias}} diff --git a/lib/node_modules/@stdlib/napi/create-int64/docs/types/index.d.ts b/lib/node_modules/@stdlib/napi/create-int64/docs/types/index.d.ts new file mode 100644 index 000000000000..023f953ef32f --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/docs/types/test.ts b/lib/node_modules/@stdlib/napi/create-int64/docs/types/test.ts new file mode 100644 index 000000000000..6df3096e67da --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/examples/index.js b/lib/node_modules/@stdlib/napi/create-int64/examples/index.js new file mode 100644 index 000000000000..d6ded1a29e22 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/examples/index.js @@ -0,0 +1,24 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/include.gypi b/lib/node_modules/@stdlib/napi/create-int64/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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 signed 64-bit integer to a Node-API BigInt value. +* +* @param env environment under which the function is invoked +* @param expression expression returning a signed 64-bit integer +* @param name output variable name +* +* @example +* #include "stdlib/napi/create_int64.h" +* #include "stdlib/napi/argv_int64.h" +* #include "stdlib/napi/argv.h" +* #include +* #include +* +* static int64_t fcn( const int64_t 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_INT64( env, value, argv, 0 ); +* +* // ... +* +* // Convert a value having a C type to a Node-API value: +* STDLIB_NAPI_CREATE_INT64( env, fcn( value ), out ); +* return out; +* } +*/ +#define STDLIB_NAPI_CREATE_INT64( env, expression, name ) \ + napi_value name; \ + stdlib_napi_create_int64( 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 signed 64-bit integer to a Node-API BigInt value. +*/ +napi_status stdlib_napi_create_int64( const napi_env env, const int64_t value, napi_value *out ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_NAPI_CREATE_INT64_H diff --git a/lib/node_modules/@stdlib/napi/create-int64/lib/browser.js b/lib/node_modules/@stdlib/napi/create-int64/lib/browser.js new file mode 100644 index 000000000000..fef77f39a5af --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/lib/browser.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/lib/index.js b/lib/node_modules/@stdlib/napi/create-int64/lib/index.js new file mode 100644 index 000000000000..e96662ced2a5 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/lib/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64 +* +* @example +* var headerDir = require( '@stdlib/napi/create-int64' ); +* +* console.log( headerDir ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/napi/create-int64/lib/main.js b/lib/node_modules/@stdlib/napi/create-int64/lib/main.js new file mode 100644 index 000000000000..87c1ce69a03c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/lib/main.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/lib/native.js b/lib/node_modules/@stdlib/napi/create-int64/lib/native.js new file mode 100644 index 000000000000..d58a15e36426 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/lib/native.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 {number} v - input value +* @returns {bigint} input value as a BigInt +* +* @example +* var v = wrapper( 1 ); +* // returns 1 +*/ +function wrapper( v ) { + return addon( v ); +} + + +// EXPORTS // + +module.exports = wrapper; diff --git a/lib/node_modules/@stdlib/napi/create-int64/manifest.json b/lib/node_modules/@stdlib/napi/create-int64/manifest.json new file mode 100644 index 000000000000..6cc74e2dea93 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/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-int64", + "@stdlib/napi/argv" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/napi/create-int64/package.json b/lib/node_modules/@stdlib/napi/create-int64/package.json new file mode 100644 index 000000000000..6ee6fd3eb90b --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/napi/create-int64", + "version": "0.0.0", + "description": "Convert a signed 64-bit integer to a Node-API value.", + "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", + "gypfile": true, + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "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", + "native", + "addon", + "utilities", + "utils", + "macros", + "integer", + "int64", + "bigint" + ], + "__stdlib__": { + "envs": { + "browser": false + } + } +} diff --git a/lib/node_modules/@stdlib/napi/create-int64/src/Makefile b/lib/node_modules/@stdlib/napi/create-int64/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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-int64/src/addon.c b/lib/node_modules/@stdlib/napi/create-int64/src/addon.c new file mode 100644 index 000000000000..b65630db872d --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/src/addon.c @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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_int64.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv.h" +#include +#include +#include + +/** +* Identity function. +* +* @param v input value +* @return input value +*/ +static int64_t identity( const int64_t 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_INT64( env, value, argv, 0 ) + int64_t out = identity( value ); + STDLIB_NAPI_CREATE_INT64( 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-int64/src/main.c b/lib/node_modules/@stdlib/napi/create-int64/src/main.c new file mode 100644 index 000000000000..b70dace301d0 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/src/main.c @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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_int64.h" +#include "stdlib/assert/napi/status_ok.h" +#include +#include + +/** +* Converts a signed 64-bit integer to a Node-API BigInt value. +* +* @param env environment under which the function is invoked +* @param value signed 64-bit integer +* @param out destination for storing output value +* @return status code indicating success or failure (returns `napi_ok` if success) +* +* @example +* #include "stdlib/napi/create_int64.h" +* #include +* +* static napi_value addon( napi_env env, napi_callback_info info ) { +* +* // ... +* +* napi_value value; +* napi_status status = stdlib_napi_create_int64( env, 1, &value ); +* assert( status == napi_ok ); +* if ( err != NULL ) { +* assert( napi_throw( env, err ) == napi_ok ); +* return NULL; +* } +* +* // ... +* } +*/ +napi_status stdlib_napi_create_int64( const napi_env env, const int64_t value, napi_value *out ) { + STDLIB_ASSERT_NAPI_STATUS_OK_RET_VALUE( env, napi_create_bigint_int64( env, value, out ), "", napi_ok ) + return napi_ok; +} diff --git a/lib/node_modules/@stdlib/napi/create-int64/test/test.browser.js b/lib/node_modules/@stdlib/napi/create-int64/test/test.browser.js new file mode 100644 index 000000000000..64de4bf16d9c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/test/test.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/test/test.js b/lib/node_modules/@stdlib/napi/create-int64/test/test.js new file mode 100644 index 000000000000..b07fdee0470e --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/test/test.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-int64/test/test.native.js b/lib/node_modules/@stdlib/napi/create-int64/test/test.native.js new file mode 100644 index 000000000000..5263a5b3e101 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-int64/test/test.native.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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', + true, + false, + null, + void 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 number', opts, function test( t ) { + var values; + var v; + var i; + + values = [ + 5, + -5, + 0 + ]; + for ( i = 0; i < values.length; i++ ) { + v = addon( values[ i ] ); + t.strictEqual( typeof v, 'bigint', 'returns a BigInt when provided '+values[ i ] ); + t.strictEqual( v === BigInt( values[ i ] ), true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/napi/create-uint64/README.md b/lib/node_modules/@stdlib/napi/create-uint64/README.md new file mode 100644 index 000000000000..cd100aedf7ce --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/README.md @@ -0,0 +1,230 @@ + + +# create_uint64 + +> Convert an unsigned 64-bit integer to a Node-API value. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var headerDir = require( '@stdlib/napi/create-uint64' ); +``` + +#### 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-uint64' ); + +console.log( headerDir ); +// => +``` + +
+ + + + + +* * * + +
+ +## C APIs + + + +
+ +
+ + + + + +
+ +### Usage + +```c +#include "stdlib/napi/create_uint64.h" +``` + +#### stdlib_napi_create_uint64( env, value, \*out ) + +Converts an unsigned 64-bit integer to a Node-API BigInt value. + +```c +#include "stdlib/napi/create_uint64.h" +#include + +static napi_value addon( napi_env env, napi_callback_info info ) { + + // ... + + napi_value value; + napi_status status = stdlib_napi_create_uint64( env, 1, &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] uint64_t` unsigned 64-bit integer. +- **out**: `[out] napi_value*` destination for storing output value. + +```c +napi_status stdlib_napi_create_uint64( const napi_env env, const uint64_t value, napi_value *out ); +``` + +The function returns a `napi_status` status code indicating success or failure (returns `napi_ok` if success). + +#### STDLIB_NAPI_CREATE_UINT64( env, expression, name ) + +Macro for converting an unsigned 64-bit integer to a Node-API BigInt value. + +```c +#include "stdlib/napi/create_uint64.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv.h" +#include +#include + +static uint64_t fcn( const uint64_t 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_INT64( env, value, argv, 0 ); + + // ... + + // Convert a value having a C type to a Node-API value: + STDLIB_NAPI_CREATE_UINT64( env, fcn( (uint64_t)value ), out ); + + return out; +} +``` + +The macro expects the following arguments: + +- **env**: environment under which the callback is invoked. +- **expression**: expression returning an unsigned 64-bit integer. +- **name**: output variable name. + +
+ + + + + +
+ +- The generated JavaScript value is a `BigInt` (N-API Version 6+). + +
+ + + + + +
+ +
+ + + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/napi/create-uint64/binding.gyp b/lib/node_modules/@stdlib/napi/create-uint64/binding.gyp new file mode 100644 index 000000000000..0d6508a12e99 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/binding.gyp @@ -0,0 +1,170 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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-uint64/docs/repl.txt b/lib/node_modules/@stdlib/napi/create-uint64/docs/repl.txt new file mode 100644 index 000000000000..ba8eb98ffe65 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/docs/repl.txt @@ -0,0 +1,12 @@ + +{{alias}} + Absolute file path for the directory containing header files for C APIs. + + Returns + ------- + out: string + Absolute file path. + + Examples + -------- + > var dir = {{alias}} diff --git a/lib/node_modules/@stdlib/napi/create-uint64/docs/types/index.d.ts b/lib/node_modules/@stdlib/napi/create-uint64/docs/types/index.d.ts new file mode 100644 index 000000000000..023f953ef32f --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/docs/types/index.d.ts @@ -0,0 +1,33 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/docs/types/test.ts b/lib/node_modules/@stdlib/napi/create-uint64/docs/types/test.ts new file mode 100644 index 000000000000..6df3096e67da --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/docs/types/test.ts @@ -0,0 +1,28 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/examples/index.js b/lib/node_modules/@stdlib/napi/create-uint64/examples/index.js new file mode 100644 index 000000000000..d6ded1a29e22 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/examples/index.js @@ -0,0 +1,24 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/include.gypi b/lib/node_modules/@stdlib/napi/create-uint64/include.gypi new file mode 100644 index 000000000000..bee8d41a2caf --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/include.gypi @@ -0,0 +1,53 @@ +# @license Apache-2.0 +# +# Copyright (c) 2026 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 an unsigned 64-bit integer to a Node-API BigInt value. +* +* @param env environment under which the function is invoked +* @param expression expression returning an unsigned 64-bit integer +* @param name output variable name +* +* @example +* #include "stdlib/napi/create_uint64.h" +* #include "stdlib/napi/argv_int64.h" +* #include "stdlib/napi/argv.h" +* #include +* #include +* +* static uint64_t fcn( const uint64_t 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_INT64( env, value, argv, 0 ); +* +* // ... +* +* // Convert a value having a C type to a Node-API value: +* STDLIB_NAPI_CREATE_UINT64( env, fcn( (uint64_t)value ), out ); +* return out; +* } +*/ +#define STDLIB_NAPI_CREATE_UINT64( env, expression, name ) \ + napi_value name; \ + stdlib_napi_create_uint64( 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 an unsigned 64-bit integer to a Node-API BigInt value. +*/ +napi_status stdlib_napi_create_uint64( const napi_env env, const uint64_t value, napi_value *out ); + +#ifdef __cplusplus +} +#endif + +#endif // !STDLIB_NAPI_CREATE_UINT64_H diff --git a/lib/node_modules/@stdlib/napi/create-uint64/lib/browser.js b/lib/node_modules/@stdlib/napi/create-uint64/lib/browser.js new file mode 100644 index 000000000000..fef77f39a5af --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/lib/browser.js @@ -0,0 +1,28 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/lib/index.js b/lib/node_modules/@stdlib/napi/create-uint64/lib/index.js new file mode 100644 index 000000000000..2d5fb7230abf --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/lib/index.js @@ -0,0 +1,39 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64 +* +* @example +* var headerDir = require( '@stdlib/napi/create-uint64' ); +* +* console.log( headerDir ); +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/napi/create-uint64/lib/main.js b/lib/node_modules/@stdlib/napi/create-uint64/lib/main.js new file mode 100644 index 000000000000..87c1ce69a03c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/lib/main.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/lib/native.js b/lib/node_modules/@stdlib/napi/create-uint64/lib/native.js new file mode 100644 index 000000000000..d58a15e36426 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/lib/native.js @@ -0,0 +1,46 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 {number} v - input value +* @returns {bigint} input value as a BigInt +* +* @example +* var v = wrapper( 1 ); +* // returns 1 +*/ +function wrapper( v ) { + return addon( v ); +} + + +// EXPORTS // + +module.exports = wrapper; diff --git a/lib/node_modules/@stdlib/napi/create-uint64/manifest.json b/lib/node_modules/@stdlib/napi/create-uint64/manifest.json new file mode 100644 index 000000000000..6cc74e2dea93 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/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-int64", + "@stdlib/napi/argv" + ] + } + ] +} diff --git a/lib/node_modules/@stdlib/napi/create-uint64/package.json b/lib/node_modules/@stdlib/napi/create-uint64/package.json new file mode 100644 index 000000000000..ebd38e219e0f --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/package.json @@ -0,0 +1,71 @@ +{ + "name": "@stdlib/napi/create-uint64", + "version": "0.0.0", + "description": "Convert an unsigned 64-bit integer to a Node-API value.", + "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", + "gypfile": true, + "directories": { + "doc": "./docs", + "example": "./examples", + "include": "./include", + "lib": "./lib", + "src": "./src", + "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", + "native", + "addon", + "utilities", + "utils", + "macros", + "integer", + "uint64", + "bigint" + ], + "__stdlib__": { + "envs": { + "browser": false + } + } +} diff --git a/lib/node_modules/@stdlib/napi/create-uint64/src/Makefile b/lib/node_modules/@stdlib/napi/create-uint64/src/Makefile new file mode 100644 index 000000000000..2caf905cedbe --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/src/Makefile @@ -0,0 +1,70 @@ +#/ +# @license Apache-2.0 +# +# Copyright (c) 2026 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-uint64/src/addon.c b/lib/node_modules/@stdlib/napi/create-uint64/src/addon.c new file mode 100644 index 000000000000..ca134efd53b4 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/src/addon.c @@ -0,0 +1,65 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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_uint64.h" +#include "stdlib/napi/argv_int64.h" +#include "stdlib/napi/argv.h" +#include +#include +#include + +/** +* Identity function. +* +* @param v input value +* @return input value +*/ +static uint64_t identity( const uint64_t 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_INT64( env, value, argv, 0 ) + uint64_t out = identity( (uint64_t)value ); + STDLIB_NAPI_CREATE_UINT64( 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-uint64/src/main.c b/lib/node_modules/@stdlib/napi/create-uint64/src/main.c new file mode 100644 index 000000000000..4a99c4203f65 --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/src/main.c @@ -0,0 +1,54 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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_uint64.h" +#include "stdlib/assert/napi/status_ok.h" +#include +#include + +/** +* Converts an unsigned 64-bit integer to a Node-API BigInt value. +* +* @param env environment under which the function is invoked +* @param value unsigned 64-bit integer +* @param out destination for storing output value +* @return status code indicating success or failure (returns `napi_ok` if success) +* +* @example +* #include "stdlib/napi/create_uint64.h" +* #include +* +* static napi_value addon( napi_env env, napi_callback_info info ) { +* +* // ... +* +* napi_value value; +* napi_status status = stdlib_napi_create_uint64( env, 1, &value ); +* assert( status == napi_ok ); +* if ( err != NULL ) { +* assert( napi_throw( env, err ) == napi_ok ); +* return NULL; +* } +* +* // ... +* } +*/ +napi_status stdlib_napi_create_uint64( const napi_env env, const uint64_t value, napi_value *out ) { + STDLIB_ASSERT_NAPI_STATUS_OK_RET_VALUE( env, napi_create_bigint_uint64( env, value, out ), "", napi_ok ) + return napi_ok; +} diff --git a/lib/node_modules/@stdlib/napi/create-uint64/test/test.browser.js b/lib/node_modules/@stdlib/napi/create-uint64/test/test.browser.js new file mode 100644 index 000000000000..64de4bf16d9c --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/test/test.browser.js @@ -0,0 +1,33 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/test/test.js b/lib/node_modules/@stdlib/napi/create-uint64/test/test.js new file mode 100644 index 000000000000..b07fdee0470e --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/test/test.js @@ -0,0 +1,48 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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-uint64/test/test.native.js b/lib/node_modules/@stdlib/napi/create-uint64/test/test.native.js new file mode 100644 index 000000000000..8a8110b3327a --- /dev/null +++ b/lib/node_modules/@stdlib/napi/create-uint64/test/test.native.js @@ -0,0 +1,85 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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', + true, + false, + null, + void 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 non-negative number', opts, function test( t ) { + var values; + var v; + var i; + + values = [ + 5, + 0, + 100 + ]; + for ( i = 0; i < values.length; i++ ) { + v = addon( values[ i ] ); + t.strictEqual( typeof v, 'bigint', 'returns a BigInt when provided '+values[ i ] ); + t.strictEqual( v === BigInt( values[ i ] ), true, 'returns expected value when provided '+values[ i ] ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js index e742eb6cbdfb..a99a74617375 100644 --- a/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/base/atleastnd/lib/main.js @@ -21,10 +21,7 @@ // MODULES // var isndarrayLike = require( '@stdlib/assert/is-ndarray-like' ); -var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; -var isComplexLike = require( '@stdlib/assert/is-complex-like' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; -var complexDataType = require( '@stdlib/complex/dtype' ); +var scalarDataType = require( '@stdlib/ndarray/base/scalar-dtype' ); var broadcastScalar = require( '@stdlib/ndarray/base/broadcast-scalar' ); var dims = require( '@stdlib/ndarray/base/ndims' ); var defaults = require( '@stdlib/ndarray/defaults' ); @@ -40,9 +37,6 @@ var ones = require( '@stdlib/array/base/ones' ); // VARIABLES // -var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' ); -var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' ); -var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' ); var ORDER = defaults.get( 'order' ); @@ -108,18 +102,7 @@ function atleastnd( ndims, arrays ) { continue; } // For scalar values, resolve a corresponding ndarray data type... - if ( isNumber( v ) ) { // TODO: consider abstracting this logic to an `ndarray/base/scalar-dtype` (???) package, as this logic is found elsewhere (e.g., `ndarray/from-scalar`) and it would be good to avoid duplication, especially as we add support for more ndarray data types - dt = DEFAULT_REAL; - } else if ( isBoolean( v ) ) { - dt = DEFAULT_BOOL; - } else if ( isComplexLike( v ) ) { - dt = complexDataType( v ); - if ( dt === null ) { - dt = DEFAULT_CMPLX; - } - } else { - dt = 'generic'; - } + dt = scalarDataType( v ); out.push( broadcastScalar( v, dt, ones( ndims ), ORDER ) ); } return out; diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/README.md b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/README.md new file mode 100644 index 000000000000..3c1b0140ce53 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/README.md @@ -0,0 +1,83 @@ + + +# scalarDataType + +> Resolve a default [ndarray][@stdlib/ndarray/ctor] data type from a scalar value. + +
+ +## Usage + +```javascript +var scalarDataType = require( '@stdlib/ndarray/base/scalar-dtype' ); +``` + +#### scalarDataType( value ) + +Resolves a default [ndarray][@stdlib/ndarray/ctor] data type from a scalar value. + +```javascript +var dt = scalarDataType( 3.14 ); +// returns + +dt = scalarDataType( 'beep' ); +// returns 'generic' +``` + +The function applies the following resolution rules: + +- If `value` is a number, the function returns the default real-valued floating-point data type. +- If `value` is a boolean, the function returns the default boolean data type. +- If `value` is a complex number object of a known complex data type, the function returns the corresponding complex data type. +- If `value` is a complex number object of an unknown complex data type, the function returns the default complex-valued floating-point data type. +- For any other value, the function returns `'generic'`. + +
+ + + +
+ +## Examples + + + +```javascript +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalarDataType = require( '@stdlib/ndarray/base/scalar-dtype' ); + +console.log( scalarDataType( 3.14 ) ); +console.log( scalarDataType( true ) ); +console.log( scalarDataType( new Complex128( 1.0, 2.0 ) ) ); +console.log( scalarDataType( 'beep' ) ); +``` + +
+ + + + + + diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/benchmark/benchmark.js b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/benchmark/benchmark.js new file mode 100644 index 000000000000..8cac0c9de9e5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/benchmark/benchmark.js @@ -0,0 +1,57 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 bench = require( '@stdlib/bench' ); +var isString = require( '@stdlib/assert/is-string' ).isPrimitive; +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var pkg = require( './../package.json' ).name; +var scalarDataType = require( './../lib' ); + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var values; + var dt; + var i; + + values = [ + 3.14, + true, + new Complex128( 1.0, 2.0 ), + 'beep' + ]; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + dt = scalarDataType( values[ i % values.length ] ); + if ( typeof dt !== 'string' ) { + b.fail( 'should return a string' ); + } + } + b.toc(); + if ( !isString( dt ) ) { + b.fail( 'should return a string' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/repl.txt b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/repl.txt new file mode 100644 index 000000000000..b462c2314f4d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/repl.txt @@ -0,0 +1,38 @@ + +{{alias}}( value ) + Resolves a default ndarray data type from a scalar value. + + If `value` is a number, the function returns the default real-valued + floating-point data type. + + If `value` is a boolean, the function returns the default boolean data + type. + + If `value` is a complex number object of a known complex data type, the + function returns the corresponding complex data type. + + If `value` is a complex number object of an unknown complex data type, the + function returns the default complex-valued floating-point data type. + + For any other value, the function returns 'generic'. + + Parameters + ---------- + value: any + Scalar value. + + Returns + ------- + out: string + Data type. + + Examples + -------- + > var dt = {{alias}}( 3.14 ) + + > dt = {{alias}}( 'beep' ) + 'generic' + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/index.d.ts b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/index.d.ts new file mode 100644 index 000000000000..4aa6877e0b7e --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/index.d.ts @@ -0,0 +1,40 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 + +/** +* Resolves a default ndarray data type from a scalar value. +* +* @param value - scalar value +* @returns data type +* +* @example +* var dt = scalarDataType( 3.14 ); +* // returns +* +* @example +* var dt = scalarDataType( 'beep' ); +* // returns 'generic' +*/ +declare function scalarDataType( value: any ): string; + + +// EXPORTS // + +export = scalarDataType; diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/test.ts b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/test.ts new file mode 100644 index 000000000000..945b189260cf --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/docs/types/test.ts @@ -0,0 +1,34 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 scalarDataType = require( './index' ); + + +// TESTS // + +// The function returns a string... +{ + scalarDataType( 3.14 ); // $ExpectType string + scalarDataType( 'beep' ); // $ExpectType string +} + +// The compiler throws an error if the function is provided an unsupported number of arguments... +{ + scalarDataType(); // $ExpectError + scalarDataType( 3.14, 3 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/examples/index.js b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/examples/index.js new file mode 100644 index 000000000000..b001b472e0fe --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/examples/index.js @@ -0,0 +1,27 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Complex128 = require( '@stdlib/complex/float64/ctor' ); +var scalarDataType = require( './../lib' ); + +console.log( scalarDataType( 3.14 ) ); +console.log( scalarDataType( true ) ); +console.log( scalarDataType( new Complex128( 1.0, 2.0 ) ) ); +console.log( scalarDataType( 'beep' ) ); diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/index.js b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/index.js new file mode 100644 index 000000000000..afdc7dffa45a --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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'; + +/** +* Resolve a default ndarray data type from a scalar value. +* +* @module @stdlib/ndarray/base/scalar-dtype +* +* @example +* var scalarDataType = require( '@stdlib/ndarray/base/scalar-dtype' ); +* +* var dt = scalarDataType( 3.14 ); +* // returns +* +* dt = scalarDataType( 'beep' ); +* // returns 'generic' +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/main.js b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/main.js new file mode 100644 index 000000000000..5d723727403d --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/lib/main.js @@ -0,0 +1,86 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var isComplexLike = require( '@stdlib/assert/is-complex-like' ); +var complexDataType = require( '@stdlib/complex/dtype' ); +var defaults = require( '@stdlib/ndarray/defaults' ); + + +// VARIABLES // + +var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' ); +var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' ); +var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' ); + + +// MAIN // + +/** +* Resolves a default ndarray data type from a scalar value. +* +* ## Notes +* +* - If `value` is a number, the returned data type is the default real-valued floating-point data type. +* - If `value` is a boolean, the returned data type is the default boolean data type. +* - If `value` is a complex number object of a known complex data type, the returned data type is the corresponding complex data type. +* - If `value` is a complex number object of an unknown complex data type, the returned data type is the default complex-valued floating-point data type. +* - For any other value, the returned data type is `'generic'`. +* +* @param {*} value - scalar value +* @returns {string} ndarray data type +* +* @example +* var dt = scalarDataType( 3.14 ); +* // returns +* +* @example +* var dt = scalarDataType( true ); +* // returns +* +* @example +* var dt = scalarDataType( 'beep' ); +* // returns 'generic' +*/ +function scalarDataType( value ) { + var dt; + if ( isNumber( value ) ) { + return DEFAULT_REAL; + } + if ( isBoolean( value ) ) { + return DEFAULT_BOOL; + } + if ( isComplexLike( value ) ) { + dt = complexDataType( value ); + if ( dt === null ) { + return DEFAULT_CMPLX; + } + return dt; + } + return 'generic'; +} + + +// EXPORTS // + +module.exports = scalarDataType; diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/package.json b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/package.json new file mode 100644 index 000000000000..2bd5ef805da5 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/package.json @@ -0,0 +1,68 @@ +{ + "name": "@stdlib/ndarray/base/scalar-dtype", + "version": "0.0.0", + "description": "Resolve a default ndarray data type from a scalar value.", + "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", + "directories": { + "benchmark": "./benchmark", + "doc": "./docs", + "example": "./examples", + "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", + "stdtypes", + "types", + "base", + "ndarray", + "dtypes", + "dtype", + "scalar", + "resolve", + "default", + "utilities", + "utility", + "utils", + "util" + ], + "__stdlib__": {} +} diff --git a/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/test/test.js b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/test/test.js new file mode 100644 index 000000000000..c7b81049d3d3 --- /dev/null +++ b/lib/node_modules/@stdlib/ndarray/base/scalar-dtype/test/test.js @@ -0,0 +1,89 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 Complex64 = require( '@stdlib/complex/float32/ctor' ); +var Complex128 = require( '@stdlib/complex/float64/ctor' ); +var defaults = require( '@stdlib/ndarray/defaults' ); +var scalarDataType = require( './../lib' ); + + +// VARIABLES // + +var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' ); +var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' ); +var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' ); + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof scalarDataType, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'the function returns the default real-valued floating-point data type for numbers', function test( t ) { + t.strictEqual( scalarDataType( 3.14 ), DEFAULT_REAL, 'returns expected value' ); + t.strictEqual( scalarDataType( 0 ), DEFAULT_REAL, 'returns expected value' ); + t.strictEqual( scalarDataType( -1 ), DEFAULT_REAL, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the default boolean data type for booleans', function test( t ) { + t.strictEqual( scalarDataType( true ), DEFAULT_BOOL, 'returns expected value' ); + t.strictEqual( scalarDataType( false ), DEFAULT_BOOL, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns a corresponding complex data type for complex-like values of a known complex data type', function test( t ) { + t.strictEqual( scalarDataType( new Complex64( 1.0, 2.0 ) ), 'complex64', 'returns expected value' ); + t.strictEqual( scalarDataType( new Complex128( 1.0, 2.0 ) ), 'complex128', 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns the default complex-valued floating-point data type for complex-like values of an unknown complex data type', function test( t ) { + var v = { + 're': 1.0, + 'im': 2.0 + }; + t.strictEqual( scalarDataType( v ), DEFAULT_CMPLX, 'returns expected value' ); + t.end(); +}); + +tape( 'the function returns "generic" for any other value', function test( t ) { + var values; + var i; + + values = [ + 'beep', + [ 1, 2, 3 ], + {}, + null, + void 0, + function noop() {} + ]; + for ( i = 0; i < values.length; i++ ) { + t.strictEqual( scalarDataType( values[ i ] ), 'generic', 'returns expected value for '+JSON.stringify( values[ i ] ) ); + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/ndarray/from-scalar/lib/main.js b/lib/node_modules/@stdlib/ndarray/from-scalar/lib/main.js index 1b7814f4cafb..2291204d6939 100644 --- a/lib/node_modules/@stdlib/ndarray/from-scalar/lib/main.js +++ b/lib/node_modules/@stdlib/ndarray/from-scalar/lib/main.js @@ -24,24 +24,19 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var isPlainObject = require( '@stdlib/assert/is-plain-object' ); var isNumber = require( '@stdlib/assert/is-number' ).isPrimitive; var isComplexDataType = require( '@stdlib/array/base/assert/is-complex-floating-point-data-type' ); -var isComplexLike = require( '@stdlib/assert/is-complex-like' ); -var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var isAccessorArray = require( '@stdlib/array/base/assert/is-accessor-array' ); var accessorSetter = require( '@stdlib/array/base/accessor-setter' ); var setter = require( '@stdlib/array/base/setter' ); var buffer = require( '@stdlib/ndarray/base/buffer' ); var ndarray = require( '@stdlib/ndarray/ctor' ); var defaults = require( '@stdlib/ndarray/defaults' ); -var dtype = require( '@stdlib/complex/dtype' ); +var scalarDataType = require( '@stdlib/ndarray/base/scalar-dtype' ); var format = require( '@stdlib/string/format' ); // VARIABLES // var ORDER = defaults.get( 'order' ); -var DEFAULT_REAL = defaults.get( 'dtypes.real_floating_point' ); -var DEFAULT_CMPLX = defaults.get( 'dtypes.complex_floating_point' ); -var DEFAULT_BOOL = defaults.get( 'dtypes.boolean' ); // MAIN // @@ -127,18 +122,7 @@ function scalar2ndarray( value ) { } flg = isNumber( value ); if ( opts.dtype === '' ) { - if ( flg ) { - dt = DEFAULT_REAL; - } else if ( isBoolean( value ) ) { - dt = DEFAULT_BOOL; - } else if ( isComplexLike( value ) ) { - dt = dtype( value ); - if ( dt === null ) { - dt = DEFAULT_CMPLX; - } - } else { - dt = 'generic'; - } + dt = scalarDataType( value ); } else { dt = opts.dtype; }