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..7c6471232349 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/README.md @@ -0,0 +1,88 @@ + + +# ReplaceSymbol + +> Well-known [`Symbol.replace`][mdn-symbol], used by `String.prototype.replace()` to customize replacement behavior. + +
+ +
+ +
+ +## Usage + +```javascript +/* eslint-disable */ + +var ReplaceSymbol = require( '@stdlib/symbol/replace' ); + +var s = typeof ReplaceSymbol; +// e.g., returns 'symbol' + +if ( ReplaceSymbol ) { + function CustomReplacer() {} + + CustomReplacer.prototype[ ReplaceSymbol ] = function namedReplace( str ) { + return 'REPLACED: ' + str; + }; + + var out = 'hello world'.replace( new CustomReplacer() ); + console.log( out ); + // => 'REPLACED: hello world' +} else { + console.log( ReplaceSymbol ); + // => null +} + +/* eslint-enable */ +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + + 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..b4667748805f --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/repl.txt @@ -0,0 +1,17 @@ +{{alias}} + Replace symbol. + + This well-known symbol specifies the method that replaces matched + substrings. It is used by `String.prototype.replace()` to delegate + replacement behavior to an object. + + The symbol is only supported in ES6/ES2015+ environments. In + unsupported environments, the value is `null`. + + Examples + -------- + > var s = {{alias}} + e.g., + + 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..7a11ed66c9e9 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/types/index.d.ts @@ -0,0 +1,34 @@ +/* +* @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 + +// EXPORTS // + +/** +* Replace symbol. +* +* ## Notes +* +* - This well-known symbol specifies the method that replaces matched substrings. +* It is used by `String.prototype.replace()` to delegate replacement behavior. +* - The symbol is only supported in ES6/ES2015+ environments. In non-supporting +* environments, the exported 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..f11972eada98 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/docs/types/test.ts @@ -0,0 +1,29 @@ +/* +* @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 @typescript-eslint/no-unused-expressions */ + +import ReplaceSymbol = require( './index' ); + +// TESTS // + +// The exported value is the `replace` 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..89352e2ff28d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/examples/index.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 ReplaceSymbol = require( './../lib' ); + + +// VARIABLES // + +var out; + + +// FUNCTIONS // + +/** +* Custom replacer object. +* +* @private +* @constructor +*/ +function CustomReplacer() { + // Empty constructor +} + +/** +* Replacement method. +* +* @private +* @param {string} str - input string +* @returns {string} replaced string +*/ +function replace( str ) { + return 'REPLACED: ' + str; +} + + +// MAIN // + +if ( ReplaceSymbol ) { + CustomReplacer.prototype[ ReplaceSymbol ] = replace; + + out = 'hello world'.replace( new CustomReplacer() ); + console.log( out ); + // => 'REPLACED: hello world' +} else { + console.log( ReplaceSymbol ); + // => null +} 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..3e610fa31ca0 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/lib/index.js @@ -0,0 +1,56 @@ +/** +* @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'; + +/** +* Well-known symbol `Symbol.replace`. +* +* This symbol specifies the method that replaces matched substrings and is used +* by `String.prototype.replace()` to delegate replacement behavior to an object. +* +* @module @stdlib/symbol/replace +* +* @example +* var ReplaceSymbol = require( '@stdlib/symbol/replace' ); +* +* if ( ReplaceSymbol ) { +* function CustomReplacer() {} +* +* CustomReplacer.prototype[ ReplaceSymbol ] = function( str ) { +* return 'REPLACED: ' + str; +* }; +* +* var out = 'hello world'.replace( new CustomReplacer() ); +* console.log( out ); +* // => 'REPLACED: hello world' +* } +* else { +* console.log( ReplaceSymbol ); +* // => null +* } +*/ + +// MAIN // + +var main = require( './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..935c44b837f9 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/lib/main.js @@ -0,0 +1,54 @@ +/** +* @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' ); + + +// MAIN // + +/** +* Replace symbol. +* +* @name ReplaceSymbol +* @constant +* @type {(symbol|null)} +* +* @example +* var ReplaceSymbol = require( '@stdlib/symbol/replace' ); +* +* if ( ReplaceSymbol ) { +* function Replacer() {} +* +* Replacer.prototype[ ReplaceSymbol ] = function ( str ) { +* return 'REPLACED: ' + str; +* }; +* +* var out = 'hello world'.replace( new Replacer() ); +* console.log( out ); +* } +*/ +var ReplaceSymbol = ( hasReplaceSymbolSupport() ) ? Symbol.replace : null; + + +// 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..7f3528a6558f --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/package.json @@ -0,0 +1,58 @@ +{ + "name": "@stdlib/symbol/replace", + "version": "0.0.0", + "description": "Has instance symbol.", + "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": { + "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", + "symbol", + "sym", + "instance", + "instanceof" + ] +} + 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..a55cbf336f53 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/replace/test/test.js @@ -0,0 +1,68 @@ +/** +* @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' ); +var isSymbol = require( '@stdlib/assert/is-symbol' ); +var Sym = require( './../lib' ); +var opts = { + 'skip': !hasReplaceSymbolSupport() +}; + + +// TESTS // + +tape( 'main export is a symbol in supporting environments or null otherwise', testMain ); + + +// FUNCTIONS // + +/** +* Test whether the main export is a symbol or null. +* +* @private +* @param {Object} t - test object +*/ +function testMain( t ) { + t.ok( true, __filename ); + + if ( opts.skip ) { + t.strictEqual( Sym, null, 'main export is null' ); + } 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, testAlias ); + +/** +* Test whether the main export equals `Symbol.replace`. +* +* @private +* @param {Object} t - test object +*/ +function testAlias( t ) { + t.strictEqual( Sym, Symbol.replace, 'returns expected value' ); + t.end(); +}