@stdlib/symbol-replace
v0.1.1
Published
Replace symbol.
Readme
ReplaceSymbol
Symbol which provides a method for replacing substrings matched by the current object.
Installation
npm install @stdlib/symbol-replaceUsage
var ReplaceSymbol = require( '@stdlib/symbol-replace' );ReplaceSymbol
symbol which provides a method for replacing substrings matched by the current object.
var s = typeof ReplaceSymbol;
// e.g., returns 'symbol'Notes
- The symbol is only supported in environments which support symbols. In non-supporting environments, the value is
null. - When calling
String.prototype.replaceandString.prototype.replaceAlland thepatternargument is an object with a[ReplaceSymbol]()method, this method is called with the target string and replacement as arguments.
Examples
var defineProperty = require( '@stdlib/utils-define-property' );
var ReplaceSymbol = require( '@stdlib/symbol-replace' );
function replace( str, replacement ) {
return replacement;
}
var obj = {};
defineProperty( obj, ReplaceSymbol, {
'configurable': true,
'value': null
});
var str = 'beep';
console.log( str.replace( obj, 'boop' ) );
defineProperty( obj, ReplaceSymbol, {
'configurable': true,
'value': replace
});
console.log( str.replace( obj, 'boop' ) );Notice
This package is part of stdlib, a standard library for JavaScript and Node.js, with an emphasis on numerical and scientific computing. The library provides a collection of robust, high performance libraries for mathematics, statistics, streams, utilities, and more.
For more information on the project, filing bug reports and feature requests, and guidance on how to develop stdlib, see the main project repository.
Community
License
See LICENSE.
Copyright
Copyright © 2016-2026. The Stdlib Authors.
