From 85d8df8d913f77d79b4034608afee4f8998b3c31 Mon Sep 17 00:00:00 2001 From: aryan7071 Date: Sat, 15 Nov 2025 00:13:08 +0530 Subject: [PATCH] Add symbol/replace and has-replace-symbol-support packages --- .../has-replace-symbol-support/README.md | 145 ++++++++++++++++ .../benchmark/benchmark.js | 49 ++++++ .../assert/has-replace-symbol-support/bin/cli | 60 +++++++ .../has-replace-symbol-support/docs/repl.txt | 15 ++ .../docs/types/index.d.ts | 35 ++++ .../docs/types/test.ts | 38 ++++ .../has-replace-symbol-support/docs/usage.txt | 8 + .../etc/cli_opts.json | 14 ++ .../examples/index.js | 28 +++ .../has-replace-symbol-support/lib/index.js | 40 +++++ .../has-replace-symbol-support/lib/main.js | 51 ++++++ .../has-replace-symbol-support/package.json | 70 ++++++++ .../test/test.cli.js | 163 ++++++++++++++++++ .../has-replace-symbol-support/test/test.js | 73 ++++++++ .../@stdlib/symbol/replace/README.md | 129 ++++++++++++++ .../@stdlib/symbol/replace/docs/repl.txt | 16 ++ .../symbol/replace/docs/types/index.d.ts | 31 ++++ .../@stdlib/symbol/replace/docs/types/test.ts | 29 ++++ .../@stdlib/symbol/replace/examples/index.js | 27 +++ .../@stdlib/symbol/replace/lib/index.js | 43 +++++ .../@stdlib/symbol/replace/lib/main.js | 47 +++++ .../@stdlib/symbol/replace/package.json | 60 +++++++ .../@stdlib/symbol/replace/test/test.js | 52 ++++++ 23 files changed, 1223 insertions(+) create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/README.md create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/benchmark/benchmark.js create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/bin/cli create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/usage.txt create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/etc/cli_opts.json create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/examples/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/index.js create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/main.js create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/package.json create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.cli.js create mode 100644 lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.js create mode 100644 lib/node_modules/@stdlib/symbol/replace/README.md create mode 100644 lib/node_modules/@stdlib/symbol/replace/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/symbol/replace/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/symbol/replace/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/symbol/replace/examples/index.js create mode 100644 lib/node_modules/@stdlib/symbol/replace/lib/index.js create mode 100644 lib/node_modules/@stdlib/symbol/replace/lib/main.js create mode 100644 lib/node_modules/@stdlib/symbol/replace/package.json create mode 100644 lib/node_modules/@stdlib/symbol/replace/test/test.js diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/README.md b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/README.md new file mode 100644 index 000000000000..e0228f0db23b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/README.md @@ -0,0 +1,145 @@ + + +# Replace Symbol Support + +> Detect native [`Symbol.replace`][mdn-symbol] support. + +
+ +## Usage + + + +```javascript +var hasReplaceSymbolSupport = require( '@stdlib/assert/has-replace-symbol-support' ); + +``` + +#### hasReplaceSymbolSupport() + +Detects if a runtime environment supports ES2018 [`Symbol.asyncIterator`][mdn-symbol]. + + + +```javascript +var bool = hasReplaceSymbolSupport(); +// returns +``` + +
+ + + +
+ +## Examples + + + + + +```javascript +var hasReplaceSymbolSupport = require( '@stdlib/assert/has-replace-symbol-support' ); + +var bool = hasReplaceSymbolSupport(); +if ( bool ) { + console.log( 'Environment has Symbol.replace support.' ); +} else { + console.log( 'Environment lacks Symbol.replace support.' ); +} +``` + +
+ + + +* * * + +
+ +## CLI + +
+ +### Usage + +```text +Usage: has-replace-symbol-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. +``` + +
+ + + +
+ +### Examples + +```bash +$ has-replace-symbol-support + +``` + +
+ + + +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/benchmark/benchmark.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/benchmark/benchmark.js new file mode 100644 index 000000000000..b36b33403677 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-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 hasReplaceSymbolSupport = 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: this *could* be optimized by a JS engine. If so, the loop may be removed. + bool = hasReplaceSymbolSupport(); + 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-replace-symbol-support/bin/cli b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/bin/cli new file mode 100644 index 000000000000..f5bc7bd21022 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-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 hasReplaceSymbolSupport = require( './../lib' ); // eslint-disable-line id-length + + +// 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( hasReplaceSymbolSupport() ); // eslint-disable-line no-console +} + +main(); diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/repl.txt b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/repl.txt new file mode 100644 index 000000000000..ed1bce103817 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/repl.txt @@ -0,0 +1,15 @@ +{{alias}}() + Tests for native `Symbol.replace` support. + + Returns + ------- + bool: boolean + Boolean indicating if an environment supports native `Symbol.replace`. + + Examples + -------- + > var bool = {{alias}}() + + + See Also + -------- diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/index.d.ts b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/index.d.ts new file mode 100644 index 000000000000..7931720c1342 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-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.replace` support. +* +* @returns boolean indicating if an environment supports `Symbol.replace` +* +* @example +* var bool = hasReplaceSymbolSupport(); +* // returns +*/ +declare function hasReplaceSymbolSupport(): boolean; + + +// EXPORTS // + +export = hasReplaceSymbolSupport; diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/test.ts b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/test.ts new file mode 100644 index 000000000000..82038ab2893b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/types/test.ts @@ -0,0 +1,38 @@ +/* +* @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 hasReplaceSymbolSupport from './index'; + + +// TESTS // + +// The function returns a boolean... +{ + hasReplaceSymbolSupport(); // $ExpectType boolean +} + +// The compiler throws an error if the function is provided arguments... +{ + // @ts-expect-error: intentionally testing invalid args + hasReplaceSymbolSupport( true ); // $ExpectError + + // @ts-expect-error: intentionally testing invalid args + hasReplaceSymbolSupport( [], 123 ); // $ExpectError +} + + diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/usage.txt b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/usage.txt new file mode 100644 index 000000000000..188268622257 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/docs/usage.txt @@ -0,0 +1,8 @@ + +Usage: has-replace-symbol-support [options] + +Options: + + -h, --help Print this message. + -V, --version Print the package version. + diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/etc/cli_opts.json b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/etc/cli_opts.json new file mode 100644 index 000000000000..f245a17e6317 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-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-replace-symbol-support/examples/index.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/examples/index.js new file mode 100644 index 000000000000..fc6832a5bbf1 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-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 hasReplaceSymbolSupport = require( './../lib' ); // eslint-disable-line id-length + +var bool = hasReplaceSymbolSupport(); +if ( bool ) { + console.log( 'Environment has Symbol.replace support.' ); +} else { + console.log( 'Environment lacks Symbol.replace support.' ); +} diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/index.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/index.js new file mode 100644 index 000000000000..17140849e81c --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/index.js @@ -0,0 +1,40 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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.asyncIterator` support. +* +* @module @stdlib/assert/has-async-iterator-symbol-support +* +* @example +* var hasAsyncIteratorSymbolSupport = require( '@stdlib/assert/has-async-iterator-symbol-support' ); +* +* var bool = hasAsyncIteratorSymbolSupport(); +* // returns +*/ + +// MODULES // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/main.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/main.js new file mode 100644 index 000000000000..a493df733e5b --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/lib/main.js @@ -0,0 +1,51 @@ +/** +* @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. +*/ + +/* eslint-disable stdlib/require-globals */ + +'use strict'; + +// MODULES // + +var hasOwnProp = require( '@stdlib/assert/has-own-property' ); + + +// MAIN // + +/** +* Tests for native `Symbol.replace` support. +* +* @returns {boolean} boolean indicating if an environment supports `Symbol.replace` +* +* @example +* var bool = hasReplaceSymbolSupport(); +* // returns +*/ +function hasReplaceSymbolSupport() { // eslint-disable-line id-length + return ( + typeof Symbol === 'function' && + typeof Symbol( 'foo' ) === 'symbol' && + hasOwnProp( Symbol, 'replace' ) && + typeof Symbol.replace === 'symbol' + ); +} + + +// EXPORTS // + +module.exports = hasReplaceSymbolSupport; diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/package.json b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/package.json new file mode 100644 index 000000000000..f8e128f6350f --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/package.json @@ -0,0 +1,70 @@ +{ + "name": "@stdlib/assert/has-replace-symbol-support", + "version": "0.0.0", + "description": "Detect native Symbol.replace 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-replace-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", + "assert", + "detect", + "feature", + "symbol", + "replace", + "string", + "regexp", + "es2015", + "es6", + "support", + "has", + "native", + "cli" + ] +} diff --git a/lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.cli.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.cli.js new file mode 100644 index 000000000000..cad36ada69e9 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.cli.js @@ -0,0 +1,163 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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.replace` 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-replace-symbol-support/test/test.js b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.js new file mode 100644 index 000000000000..8238ebb3db62 --- /dev/null +++ b/lib/node_modules/@stdlib/assert/has-replace-symbol-support/test/test.js @@ -0,0 +1,73 @@ +/** +* @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. +*/ + +/* eslint-disable stdlib/require-globals */ + +'use strict'; + +// MODULES // + +var tape = require( 'tape' ); +var hasSymbolSupport = require( '@stdlib/assert/has-symbol-support' ); +var detect = require( './../lib' ); + + +// VARIABLES // + +var hasSymbols = hasSymbolSupport(); +var hasReplaceSymbol = ( typeof Symbol === 'function' && typeof Symbol.replace === 'symbol' ); + + +// 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', 'detection result is a boolean' ); + t.end(); +}); + +tape( 'if `Symbol.replace` is supported, detection result is `true`', function test( t ) { + if ( hasReplaceSymbol ) { + t.strictEqual( detect(), true, 'detection result is `true`' ); + } else { + t.strictEqual( detect(), false, 'detection result is `false`' ); + } + t.end(); +}); + +tape( 'the function guards against a `Symbol` global variable which does not produce `symbols`', function test( t ) { + var tmp; + if ( hasSymbols ) { + tmp = Symbol; + Symbol = {}; // eslint-disable-line no-global-assign + } else { + global.Symbol = {}; + } + t.strictEqual( detect(), false, 'detection result is `false`' ); + if ( hasSymbols ) { + Symbol = tmp; // eslint-disable-line no-global-assign + } else { + delete global.Symbol; + } + t.end(); +}); diff --git a/lib/node_modules/@stdlib/symbol/replace/README.md b/lib/node_modules/@stdlib/symbol/replace/README.md new file mode 100644 index 000000000000..5824d680069a --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/README.md @@ -0,0 +1,129 @@ + + +# replaceSymbol + +> Export [`Symbol.replace`][mdn-replace-symbol] if available. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var replaceSymbol = require( '@stdlib/symbol/replace' ); +``` + +#### replaceSymbol + +replace [`symbol`][mdn-symbol] which specifies the default replace for an object. + +```javascript +var replaceSymbol = require( '@stdlib/symbol/replace' ); +// e.g., returns 'symbol' +``` + +
+ + + + + +
+ +## Notes + +- The [symbol][mdn-symbol] is only supported in environments which support [symbols][mdn-symbol] and replace. In non-supporting environments, the value is `null`. + +
+ + + + + +
+ +## Examples + + + +```javascript +var replaceSymbol = require( '@stdlib/symbol/replace' ); + +if ( replaceSymbol === null ) { + console.log( 'Environment does not support Symbol.replace.' ); +} else { + console.log( 'Environment does support Symbol.replace.' ); +} +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/symbol/replace/docs/repl.txt b/lib/node_modules/@stdlib/symbol/replace/docs/repl.txt new file mode 100644 index 000000000000..57fbc2dee31d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/repl.txt @@ -0,0 +1,16 @@ + +{{alias}} + Async iterator symbol. + + This symbol specifies the default async iterator for an object. + + The symbol is only supported in ES2018+ environments. For non-supporting + environments, the value is `null`. + + Examples + -------- + > var s = {{alias}} + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/symbol/replace/docs/types/index.d.ts b/lib/node_modules/@stdlib/symbol/replace/docs/types/index.d.ts new file mode 100644 index 000000000000..2cb4eee2948d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/types/index.d.ts @@ -0,0 +1,31 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 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 + +// EXPORTS // + +/** +* Async iterator symbol. +* +* ## Notes +* +* - This symbol specifies the default async iterator for an object. +* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`. +*/ +export = Symbol.replace; diff --git a/lib/node_modules/@stdlib/symbol/replace/docs/types/test.ts b/lib/node_modules/@stdlib/symbol/replace/docs/types/test.ts new file mode 100644 index 000000000000..ca6bf2622a14 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/types/test.ts @@ -0,0 +1,29 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2021 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. +*/ + +/* eslint-disable @typescript-eslint/no-unused-expressions */ + +import replaceSymbol from '@stdlib/symbol/replace'; + + +// TESTS // + +// The exported value is the async iterator symbol... +{ + replaceSymbol; +} diff --git a/lib/node_modules/@stdlib/symbol/replace/examples/index.js b/lib/node_modules/@stdlib/symbol/replace/examples/index.js new file mode 100644 index 000000000000..fdde8488b4dd --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/examples/index.js @@ -0,0 +1,27 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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 replaceSymbol = require( '@stdlib/symbol/replace/lib' ); + +if ( replaceSymbol === null ) { + console.log( 'Environment does not support Symbol.replace.' ); +} else { + console.log( 'Environment does support Symbol.replace.' ); +} diff --git a/lib/node_modules/@stdlib/symbol/replace/lib/index.js b/lib/node_modules/@stdlib/symbol/replace/lib/index.js new file mode 100644 index 000000000000..72a532311d69 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/lib/index.js @@ -0,0 +1,43 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2018 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'; + +/** +* replace symbol. +* +* @module @stdlib/symbol/replace +* +* @example +* var replaceSymbol = require( '@stdlib/symbol/replace' ); +* +* if ( replaceSymbol === null ) { +* console.log( 'Environment does not support Symbol.replace.' ); +* } else { +* console.log( 'Environment does support Symbol.replace.' ); +* } +*/ + +// MAIN // + +var main = require( '@stdlib/symbol/replace/lib/main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/symbol/replace/lib/main.js b/lib/node_modules/@stdlib/symbol/replace/lib/main.js new file mode 100644 index 000000000000..16228c841aaa --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/lib/main.js @@ -0,0 +1,47 @@ +/** +* @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 hasReplaceSymbolSupport = require( '@stdlib/assert/has-replace-symbol-support' ); // eslint-disable-line id-length + + +// MAIN // + +/** +* replace symbol. +* +* @name replaceSymbol +* @constant +* @type {(symbol|null)} +* +* @example +* if ( replaceSymbol === null ) { +* console.log( 'Environment does not support Symbol.replace.' ); +* } else { +* console.log( 'Environment does support Symbol.replace.' ); +* } +*/ +var replaceSymbol = ( hasReplaceSymbolSupport() ) ? Symbol.replace : null; // eslint-disable-line max-len + + +// EXPORTS // + +module.exports = replaceSymbol; diff --git a/lib/node_modules/@stdlib/symbol/replace/package.json b/lib/node_modules/@stdlib/symbol/replace/package.json new file mode 100644 index 000000000000..8f1252ad5858 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/package.json @@ -0,0 +1,60 @@ +{ + "name": "@stdlib/symbol/replace", + "version": "0.0.0", + "description": "Export Symbol.replace if available.", + "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/index.js", + "directories": { + "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": { + "tape": "^5.9.0" + }, + "engines": { + "node": ">=0.10.0", + "npm": ">2.7.0" + }, + "os": [ + "aix", + "darwin", + "freebsd", + "linux", + "macos", + "openbsd", + "sunos", + "win32", + "windows" + ], + "keywords": [ + "stdlib", + "symbol", + "replace", + "string", + "regexp", + "es2015", + "es6" + ] +} diff --git a/lib/node_modules/@stdlib/symbol/replace/test/test.js b/lib/node_modules/@stdlib/symbol/replace/test/test.js new file mode 100644 index 000000000000..46ea4e705a84 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/test/test.js @@ -0,0 +1,52 @@ +/** +* @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 hasReplaceSymbolSupport = require( '@stdlib/assert/has-replace-symbol-support' ); // eslint-disable-line id-length +var isSymbol = require( '@stdlib/assert/is-symbol' ); +var Sym = require( '@stdlib/symbol/replace/lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasReplaceSymbolSupport() +}; + + +// TESTS // + +tape( 'main export is a symbol in supporting environments (ES2018+) or otherwise undefined', function test( t ) { + t.ok( true, __filename ); + if ( opts.skip ) { + t.strictEqual( Sym, void 0, 'main export is undefined' ); + } else { + t.strictEqual( typeof Sym, 'symbol', 'main export is a symbol' ); + t.strictEqual( isSymbol( Sym ), true, 'main export is a symbol' ); + } + t.end(); +}); + +tape( 'the main export is an alias for `Symbol.replace`', opts, function test( t ) { + t.strictEqual( Sym, Symbol.replace, 'is an alias' ); + t.end(); +});