From 68349a250ddb1cb9effa09cfcf81b539eb1885f1 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sun, 9 Nov 2025 15:44:29 +0530 Subject: [PATCH 01/12] Add @stdlib/assert/has-to-primitive-symbol-support --- .../has-to-primitive-symbol-support/README.md | 129 ++++++++++++++ .../benchmark/benchmark.js | 49 ++++++ .../has-to-primitive-symbol-support/bin/cli | 60 +++++++ .../docs/repl.txt | 18 ++ .../docs/types/index.d.ts | 35 ++++ .../docs/types/test.ts | 33 ++++ .../docs/usage.txt | 8 + .../etc/cli_opts.json | 14 ++ .../examples/index.js | 28 +++ .../lib/index.js | 40 +++++ .../lib/main.js | 50 ++++++ .../package.json | 74 ++++++++ .../test/test.cli.js | 163 ++++++++++++++++++ .../test/test.js | 66 +++++++ 14 files changed, 767 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/README.md create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/bin/cli create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/package.json create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/README.md b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/README.md new file mode 100644 index 000000000000..d604d3b49ce8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/README.md @@ -0,0 +1,129 @@ + + +# ToPrimitive Symbol Support + +> Detect native [`Symbol.toPrimitive`][mdn-to-primitive-symbol] support. + +
+ +## Usage + + + +```javascript +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +``` + +#### hasToPrimitiveSymbolSupport() + +Detects if a runtime environment supports [`Symbol.toPrimitive`][mdn-to-primitive-symbol]. + + + +```javascript +var bool = hasToPrimitiveSymbolSupport(); +// returns +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); + +var bool = hasToPrimitiveSymbolSupport(); +if ( bool ) { + console.log( 'Environment has Symbol.toPrimitive support.' ); +} else { + console.log( 'Environment lacks Symbol.toPrimitive support.' ); +} +``` + +
+ + + +* * * + +
+ +## CLI + +
+ +### Usage + +```text +Usage: has-to-primitive-symbol-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. +``` + +
+ + + +
+ +### Examples + +```bash +$ has-to-primitive-symbol-support + +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js new file mode 100644 index 000000000000..49e6048cfbfa --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js @@ -0,0 +1,49 @@ +/** +* @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 bench = require( '@stdlib/bench' ); +var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; +var pkg = require( './../package.json' ).name; +var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length + + +// MAIN // + +bench( pkg, function benchmark( b ) { + var bool; + var i; + + b.tic(); + for ( i = 0; i < b.iterations; i++ ) { + // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. + bool = hasIsConcatSpreadableSymbolSupport(); + if ( typeof bool !== 'boolean' ) { + b.fail( 'should return a boolean' ); + } + } + b.toc(); + if ( !isBoolean( bool ) ) { + b.fail( 'should return a boolean' ); + } + b.pass( 'benchmark finished' ); + b.end(); +}); diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/bin/cli b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/bin/cli new file mode 100644 index 000000000000..8520ae55bf89 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/bin/cli @@ -0,0 +1,60 @@ +#!/usr/bin/env node + +/** +* @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 readFileSync = require( '@stdlib/fs/read-file' ).sync; +var CLI = require( '@stdlib/cli/ctor' ); +var detect = require( './../lib' ); + + +// MAIN // + +/** +* Main execution sequence. +* +* @private +*/ +function main() { + var flags; + var cli; + + // Create a command-line interface: + cli = new CLI({ + 'pkg': require( './../package.json' ), + 'options': require( './../etc/cli_opts.json' ), + 'help': readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }) + }); + + // Get any provided command-line options: + flags = cli.flags(); + if ( flags.help || flags.version ) { + return; + } + + console.log( detect() ); // eslint-disable-line no-console +} + +main(); diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt new file mode 100644 index 000000000000..41e264761e04 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt @@ -0,0 +1,18 @@ + +{{alias}}() + Tests for native `Symbol.isConcatSpreadable` support. + + Returns + ------- + bool: boolean + Boolean indicating if an environment has native + `Symbol.isConcatSpreadable` support. + + Examples + -------- + > var bool = {{alias}}() + + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts new file mode 100644 index 000000000000..0eddfb6b43a9 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts @@ -0,0 +1,35 @@ +/* +* @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 + +/** +* Tests for native `Symbol.isConcatSpreadable` support. +* +* @returns boolean indicating if an environment has `Symbol.isConcatSpreadable` support +* +* @example +* var bool = hasIsConcatSpreadableSymbolSupport(); +* // returns +*/ +declare function hasIsConcatSpreadableSymbolSupport(): boolean; + + +// EXPORTS // + +export = hasIsConcatSpreadableSymbolSupport; diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts new file mode 100644 index 000000000000..0d7a376dfeb4 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.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. +*/ + +import hasIsConcatSpreadableSymbolSupport = require( './index' ); + + +// TESTS // + +// The function returns a boolean... +{ + hasIsConcatSpreadableSymbolSupport(); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided arguments... +{ + hasIsConcatSpreadableSymbolSupport( true ); // $ExpectError + hasIsConcatSpreadableSymbolSupport( [], 123 ); // $ExpectError +} diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/usage.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/usage.txt new file mode 100644 index 000000000000..452f771af560 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/usage.txt @@ -0,0 +1,8 @@ + +Usage: has-to-primitive-symbol-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/etc/cli_opts.json b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/etc/cli_opts.json new file mode 100644 index 000000000000..f245a17e6317 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/etc/cli_opts.json @@ -0,0 +1,14 @@ +{ + "boolean": [ + "help", + "version" + ], + "alias": { + "help": [ + "h" + ], + "version": [ + "V" + ] + } +} diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js new file mode 100644 index 000000000000..0ec81d617d00 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.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'; + +var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length + +var bool = hasIsConcatSpreadableSymbolSupport(); +if ( bool ) { + console.log( 'Environment has Symbol.isConcatSpreadable support.' ); +} else { + console.log( 'Environment lacks Symbol.isConcatSpreadable support.' ); +} diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js new file mode 100644 index 000000000000..d9eef3ddebc8 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js @@ -0,0 +1,40 @@ +/** +* @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'; + +/** + * Test for native `Symbol.toPrimitive` support. + * + * @module @stdlib/assert/has-to-primitive-symbol-support + * + * @example + * var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); + * + * var bool = hasToPrimitiveSymbolSupport(); + * // returns + */ + +// MODULES // + +var main = require( '@stdlib/assert/has-to-primitive-symbol-support/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js new file mode 100644 index 000000000000..1a3a7e41360b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js @@ -0,0 +1,50 @@ +/** +* @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 hasOwnProp = require( '@stdlib/assert/has-own-property' ); +var Symbol = require( '@stdlib/symbol/ctor' ); + + +// MAIN // + +/** +* Tests for native `Symbol.toPrimitive` support. +* +* @returns {boolean} boolean indicating if an environment has `Symbol.toPrimitive` support +* +* @example +* var bool = hasToPrimitiveSymbolSupport(); +* // returns +*/ +function hasToPrimitiveSymbolSupport() { // eslint-disable-line id-length + return ( + typeof Symbol === 'function' && + typeof Symbol( 'foo' ) === 'symbol' && + hasOwnProp( Symbol, 'toPrimitive' ) && + typeof Symbol.toPrimitive === 'symbol' + ); +} + + +// EXPORTS // + +module.exports = hasToPrimitiveSymbolSupport; diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/package.json b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/package.json new file mode 100644 index 000000000000..72d6094ef346 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/package.json @@ -0,0 +1,74 @@ +{ + "name": "@stdlib/assert/has-to-primitive-symbol-support", + "version": "0.0.0", + "description": "Detect native Symbol.toPrimitive support.", + "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" + } + ], + "bin": { + "has-to-primitive-symbol-support": "./bin/cli" + }, + "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", + "stdutils", + "stdutil", + "utilities", + "utility", + "utils", + "util", + "detect", + "feature", + "symbol", + "to-primitive", + "es2015", + "es6", + "support", + "has", + "native", + "issupported", + "cli" + ] +} diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.cli.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.cli.js new file mode 100644 index 000000000000..ddba4322d088 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.cli.js @@ -0,0 +1,163 @@ +/** +* @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 exec = require( 'child_process' ).exec; +var tape = require( 'tape' ); +var IS_BROWSER = require( '@stdlib/assert/is-browser' ); +var IS_WINDOWS = require( '@stdlib/assert/is-windows' ); +var EXEC_PATH = require( '@stdlib/process/exec-path' ); +var readFileSync = require( '@stdlib/fs/read-file' ).sync; + + +// VARIABLES // + +var fpath = resolve( __dirname, '..', 'bin', 'cli' ); +var opts = { + 'skip': IS_BROWSER || IS_WINDOWS +}; + + +// FIXTURES // + +var PKG_VERSION = require( './../package.json' ).version; + + +// TESTS // + +tape( 'command-line interface', function test( t ) { + t.ok( true, __filename ); + t.end(); +}); + +tape( 'when invoked with a `--help` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '--help' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-h` flag, the command-line interface prints the help text to `stderr`', opts, function test( t ) { + var expected; + var cmd; + + expected = readFileSync( resolve( __dirname, '..', 'docs', 'usage.txt' ), { + 'encoding': 'utf8' + }); + cmd = [ + EXEC_PATH, + fpath, + '-h' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), expected+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `--version` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '--version' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'when invoked with a `-V` flag, the command-line interface prints the version to `stderr`', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath, + '-V' + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + if ( error ) { + t.fail( error.message ); + } else { + t.strictEqual( stdout.toString(), '', 'does not print to `stdout`' ); + t.strictEqual( stderr.toString(), PKG_VERSION+'\n', 'expected value' ); + } + t.end(); + } +}); + +tape( 'the command-line interface prints either `true` or `false` to `stdout` indicating whether an environment provides native `Symbol.toPrimitive` support', opts, function test( t ) { + var cmd = [ + EXEC_PATH, + fpath + ]; + + exec( cmd.join( ' ' ), done ); + + function done( error, stdout, stderr ) { + var str; + if ( error ) { + t.fail( error.message ); + } else { + str = stdout.toString(); + t.strictEqual( str === 'true\n' || str === 'false\n', true, 'prints either `true` or `false` to `stdout`' ); + t.strictEqual( stderr.toString(), '', 'does not print to `stderr`' ); + } + t.end(); + } +}); diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js new file mode 100644 index 000000000000..526b8b95c893 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js @@ -0,0 +1,66 @@ +/** +* @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 proxyquire = require( 'proxyquire' ); +var Symbol = require( '@stdlib/symbol/ctor' ); +var detect = require( '@stdlib/assert/has-to-primitive-symbol-support/lib' ); + + +// VARIABLES // + +var hasToPrimitiveSymbol = ( typeof Symbol === 'function' && typeof Symbol.toPrimitive === 'symbol' ); // eslint-disable-line id-length + + +// TESTS // + +tape( 'main export is a function', function test( t ) { + t.ok( true, __filename ); + t.strictEqual( typeof detect, 'function', 'main export is a function' ); + t.end(); +}); + +tape( 'feature detection result is a boolean', function test( t ) { + t.strictEqual( typeof detect(), 'boolean', 'returns expected value' ); + t.end(); +}); + +tape( 'if `Symbol.toPrimitive` is supported, detection result is `true`', function test( t ) { + if ( hasToPrimitiveSymbol ) { + t.strictEqual( detect(), true, 'returns expected value' ); + } else { + t.strictEqual( detect(), false, 'returns expected value' ); + } + t.end(); +}); + +tape( 'the function guards against a `Symbol` global variable which does not produce `symbols`', function test( t ) { + var detect = proxyquire( './../lib/main.js', { + '@stdlib/symbol/ctor': mock + }); + t.strictEqual( detect(), false, 'returns expected value' ); + t.end(); + + function mock() { + return {}; + } +}); From ba549dba52927dee4e7fb8a5b82c5b606bf45e6f Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sun, 9 Nov 2025 16:03:30 +0530 Subject: [PATCH 02/12] Add @stdlib/assert/has-to-primitive-symbol-support --- .../assert/has-to-primitive-symbol-support/lib/main.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js index 1a3a7e41360b..aaf4f6fe3b16 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js @@ -23,19 +23,20 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var Symbol = require( '@stdlib/symbol/ctor' ); - // MAIN // /** * Tests for native `Symbol.toPrimitive` support. * +* @module @stdlib/assert/has-to-primitive-symbol-support +* * @returns {boolean} boolean indicating if an environment has `Symbol.toPrimitive` support * * @example * var bool = hasToPrimitiveSymbolSupport(); * // returns */ -function hasToPrimitiveSymbolSupport() { // eslint-disable-line id-length +function hasToPrimitiveSymbolSupport() { return ( typeof Symbol === 'function' && typeof Symbol( 'foo' ) === 'symbol' && @@ -44,7 +45,6 @@ function hasToPrimitiveSymbolSupport() { // eslint-disable-line id-length ); } - // EXPORTS // module.exports = hasToPrimitiveSymbolSupport; From 57c186aef62f45c918bc2e845a65396b7b1e3867 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 02:34:42 -0800 Subject: [PATCH 03/12] chore: fix variable name Signed-off-by: Athan --- .../has-to-primitive-symbol-support/benchmark/benchmark.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js index 49e6048cfbfa..8984ce271ad7 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js @@ -23,7 +23,7 @@ var bench = require( '@stdlib/bench' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; -var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length +var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length // MAIN // @@ -35,7 +35,7 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. - bool = hasIsConcatSpreadableSymbolSupport(); + bool = hasToPrimitiveSymbolSupport(); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } From 6b6e3efeb82740436a0b12fd14ea07799364b643 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 02:35:40 -0800 Subject: [PATCH 04/12] docs: fix copy Signed-off-by: Athan --- .../assert/has-to-primitive-symbol-support/docs/repl.txt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt index 41e264761e04..84db68c07c05 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt @@ -1,12 +1,12 @@ {{alias}}() - Tests for native `Symbol.isConcatSpreadable` support. + Tests for native `Symbol.toPrimitive` support. Returns ------- bool: boolean - Boolean indicating if an environment has native - `Symbol.isConcatSpreadable` support. + Boolean indicating if an environment has native `Symbol.toPrimitive` + support. Examples -------- From b9de00f000cc5c0851b3790ad4634f095bc36cd5 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 02:36:55 -0800 Subject: [PATCH 05/12] fix: update require path Signed-off-by: Athan --- .../@stdlib/assert/has-to-primitive-symbol-support/lib/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js index d9eef3ddebc8..52efb4c4f0cd 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js @@ -32,7 +32,7 @@ // MODULES // -var main = require( '@stdlib/assert/has-to-primitive-symbol-support/lib/main.js' ); +var main = require( './main.js' ); // EXPORTS // From d22a1e043d77248e23064c3ba69ec8f26fdfe033 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 02:39:03 -0800 Subject: [PATCH 06/12] test: fix require path Signed-off-by: Athan --- .../@stdlib/assert/has-to-primitive-symbol-support/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js index 526b8b95c893..8db3396e9b44 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js @@ -23,7 +23,7 @@ var tape = require( 'tape' ); var proxyquire = require( 'proxyquire' ); var Symbol = require( '@stdlib/symbol/ctor' ); -var detect = require( '@stdlib/assert/has-to-primitive-symbol-support/lib' ); +var detect = require( './../lib' ); // VARIABLES // From c2d5845efa229e5df6d95a9c9ad7d6a92168e848 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 02:46:10 -0800 Subject: [PATCH 07/12] style: fix asterisk alignment Signed-off-by: Athan --- .../lib/index.js | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js index 52efb4c4f0cd..a43f6428c71a 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/index.js @@ -19,16 +19,16 @@ 'use strict'; /** - * Test for native `Symbol.toPrimitive` support. - * - * @module @stdlib/assert/has-to-primitive-symbol-support - * - * @example - * var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); - * - * var bool = hasToPrimitiveSymbolSupport(); - * // returns - */ +* Test for native `Symbol.toPrimitive` support. +* +* @module @stdlib/assert/has-to-primitive-symbol-support +* +* @example +* var hasToPrimitiveSymbolSupport = require( '@stdlib/assert/has-to-primitive-symbol-support' ); +* +* var bool = hasToPrimitiveSymbolSupport(); +* // returns +*/ // MODULES // From c3e4debce9349daf28a316678ed9a21957f0593f Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sun, 9 Nov 2025 16:32:16 +0530 Subject: [PATCH 08/12] Add @stdlib/assert/has-to-primitive-symbol-support fixed copy-paste error --- .../benchmark/benchmark.js | 5 +++-- .../has-to-primitive-symbol-support/docs/repl.txt | 5 +++-- .../docs/types/index.d.ts | 10 +++++----- .../has-to-primitive-symbol-support/docs/types/test.ts | 8 ++++---- .../has-to-primitive-symbol-support/examples/index.js | 8 ++++---- .../assert/has-to-primitive-symbol-support/lib/main.js | 4 ++-- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js index 8984ce271ad7..128588a5da77 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js @@ -24,6 +24,7 @@ var bench = require( '@stdlib/bench' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length +var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length // MAIN // @@ -34,8 +35,8 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. - bool = hasToPrimitiveSymbolSupport(); + // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. + bool = hasToPrimitiveSymbolSupport(); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt index 84db68c07c05..3eefe27fd910 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt @@ -1,12 +1,13 @@ {{alias}}() Tests for native `Symbol.toPrimitive` support. + Tests for native `Symbol.toPrimitive` support. Returns ------- bool: boolean - Boolean indicating if an environment has native `Symbol.toPrimitive` - support. + Boolean indicating if an environment has native + `Symbol.toPrimitive` support. Examples -------- diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts index 0eddfb6b43a9..dff87b2f933f 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/index.d.ts @@ -19,17 +19,17 @@ // TypeScript Version: 4.1 /** -* Tests for native `Symbol.isConcatSpreadable` support. +* Tests for native `Symbol.toPrimitive` support. * -* @returns boolean indicating if an environment has `Symbol.isConcatSpreadable` support +* @returns boolean indicating if an environment has `Symbol.toPrimitive` support * * @example -* var bool = hasIsConcatSpreadableSymbolSupport(); +* var bool = hasToPrimitiveSymbolSupport(); * // returns */ -declare function hasIsConcatSpreadableSymbolSupport(): boolean; +declare function hasToPrimitiveSymbolSupport(): boolean; // EXPORTS // -export = hasIsConcatSpreadableSymbolSupport; +export = hasToPrimitiveSymbolSupport; diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts index 0d7a376dfeb4..94d6daec9b36 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/types/test.ts @@ -16,18 +16,18 @@ * limitations under the License. */ -import hasIsConcatSpreadableSymbolSupport = require( './index' ); +import hasToPrimitiveSymbolSupport = require( './index' ); // TESTS // // The function returns a boolean... { - hasIsConcatSpreadableSymbolSupport(); // $ExpectType boolean + hasToPrimitiveSymbolSupport(); // $ExpectType boolean } // The compiler throws an error if the function is provided arguments... { - hasIsConcatSpreadableSymbolSupport( true ); // $ExpectError - hasIsConcatSpreadableSymbolSupport( [], 123 ); // $ExpectError + hasToPrimitiveSymbolSupport( true ); // $ExpectError + hasToPrimitiveSymbolSupport( [], 123 ); // $ExpectError } diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js index 0ec81d617d00..9cc1f485c477 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/examples/index.js @@ -18,11 +18,11 @@ 'use strict'; -var hasIsConcatSpreadableSymbolSupport = require( './../lib' ); // eslint-disable-line id-length +var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length -var bool = hasIsConcatSpreadableSymbolSupport(); +var bool = hasToPrimitiveSymbolSupport(); if ( bool ) { - console.log( 'Environment has Symbol.isConcatSpreadable support.' ); + console.log( 'Environment has Symbol.toPrimitive support.' ); } else { - console.log( 'Environment lacks Symbol.isConcatSpreadable support.' ); + console.log( 'Environment lacks Symbol.toPrimitive support.' ); } diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js index aaf4f6fe3b16..0efe782b1761 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/lib/main.js @@ -23,13 +23,12 @@ var hasOwnProp = require( '@stdlib/assert/has-own-property' ); var Symbol = require( '@stdlib/symbol/ctor' ); + // MAIN // /** * Tests for native `Symbol.toPrimitive` support. * -* @module @stdlib/assert/has-to-primitive-symbol-support -* * @returns {boolean} boolean indicating if an environment has `Symbol.toPrimitive` support * * @example @@ -45,6 +44,7 @@ function hasToPrimitiveSymbolSupport() { ); } + // EXPORTS // module.exports = hasToPrimitiveSymbolSupport; From 43bff1e7e88b63648cf7dd71b069122290fc32a0 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sun, 9 Nov 2025 16:45:57 +0530 Subject: [PATCH 09/12] Add @stdlib/assert/has-to-primitive-symbol-support fixed copy-paste error --- .../@stdlib/assert/has-to-primitive-symbol-support/test/test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js index 8db3396e9b44..941b095556b9 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/test/test.js @@ -28,7 +28,7 @@ var detect = require( './../lib' ); // VARIABLES // -var hasToPrimitiveSymbol = ( typeof Symbol === 'function' && typeof Symbol.toPrimitive === 'symbol' ); // eslint-disable-line id-length +var hasToPrimitiveSymbol = ( typeof Symbol === 'function' && typeof Symbol.toPrimitive === 'symbol' ); // TESTS // From 3edbffde674a8a9179a155b39e3b9eb7673c9922 Mon Sep 17 00:00:00 2001 From: kaushal-kumar-it Date: Sun, 9 Nov 2025 16:52:37 +0530 Subject: [PATCH 10/12] Add @stdlib/assert/has-to-primitive-symbol-support fixed copy-paste error --- .../has-to-primitive-symbol-support/benchmark/benchmark.js | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js index 128588a5da77..8984ce271ad7 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/benchmark/benchmark.js @@ -24,7 +24,6 @@ var bench = require( '@stdlib/bench' ); var isBoolean = require( '@stdlib/assert/is-boolean' ).isPrimitive; var pkg = require( './../package.json' ).name; var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length -var hasToPrimitiveSymbolSupport = require( './../lib' ); // eslint-disable-line id-length // MAIN // @@ -35,8 +34,8 @@ bench( pkg, function benchmark( b ) { b.tic(); for ( i = 0; i < b.iterations; i++ ) { - // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. - bool = hasToPrimitiveSymbolSupport(); + // Note: the following *could* be optimized away via loop-invariant code motion. If so, the entire loop will disappear. + bool = hasToPrimitiveSymbolSupport(); if ( typeof bool !== 'boolean' ) { b.fail( 'should return a boolean' ); } From ab58de6b486fcf742f3579e45f99d0bf7d565485 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 03:37:28 -0800 Subject: [PATCH 11/12] docs: fix line wrapping Signed-off-by: Athan --- .../assert/has-to-primitive-symbol-support/docs/repl.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt index 3eefe27fd910..8488a2d04092 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt @@ -6,8 +6,8 @@ Returns ------- bool: boolean - Boolean indicating if an environment has native - `Symbol.toPrimitive` support. + Boolean indicating if an environment has native `Symbol.toPrimitive` + support. Examples -------- From 172c6c449e35accb34ed7a3a0a1e049cf859e6c2 Mon Sep 17 00:00:00 2001 From: Athan Date: Sun, 9 Nov 2025 03:37:56 -0800 Subject: [PATCH 12/12] docs: remove duplicate line Signed-off-by: Athan --- .../@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt index 8488a2d04092..84db68c07c05 100644 --- a/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt +++ b/lib/node_modules/@stdlib/assert/has-to-primitive-symbol-support/docs/repl.txt @@ -1,7 +1,6 @@ {{alias}}() Tests for native `Symbol.toPrimitive` support. - Tests for native `Symbol.toPrimitive` support. Returns -------