diff --git a/lib/node_modules/@stdlib/symbol/match/README.md b/lib/node_modules/@stdlib/symbol/match/README.md new file mode 100644 index 000000000000..2112abf68396 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/README.md @@ -0,0 +1,145 @@ + + +# MatchSymbol + +> [Symbol][mdn-symbol] which specifies whether an object should be treated as a regular expression. + + + +
+ +
+ + + + + +
+ +## Usage + +```javascript +var MatchSymbol = require( '@stdlib/symbol/match' ); +``` + +#### MatchSymbol + +[`Symbol`][mdn-symbol] which specifies whether an object should be treated as a regular expression. + +```javascript +var s = typeof MatchSymbol; +// e.g., returns 'symbol' +``` + +
+ + + + + +
+ +## Notes + +- The [symbol][mdn-symbol] is only supported in environments which support [symbols][mdn-symbol]. In non-supporting environments, the value is `null`. + +- `String.prototype.match()` uses the following algorithm to determine how to match a string: + + - If the first argument is an object with a `[MatchSymbol]()` method, `String.prototype.match()` calls that method with the string as the first argument and returns the result. + - Otherwise, if the first argument is a [regular expression][mdn-regexp], `String.prototype.match()` performs a standard regular expression match. + - Otherwise, `String.prototype.match()` coerces the first argument to a string and searches for that substring. + +- The symbol is also used to identify whether an object should be treated as a [regular expression][mdn-regexp]. For example, the methods `String.prototype.startsWith()`, `String.prototype.endsWith()`, and `String.prototype.includes()` check if their first argument is a regular expression and will throw a `TypeError` if it is. By setting `[MatchSymbol]` to `false` (or a [falsy][mdn-falsy] value except `undefined`), an object can indicate that it should not be treated as a regular expression object. + +
+ + + + + +
+ +## Examples + + + +```javascript +var defineProperty = require( '@stdlib/utils/define-property' ); +var MatchSymbol = require( '@stdlib/symbol/match' ); + +var obj = {}; +var re = /foo/; + +// Define a custom match behavior: +function customMatch() { + return [ 'custom', 'match', 'result' ]; +} + +defineProperty( obj, MatchSymbol, { + 'configurable': false, + 'enumerable': false, + 'writable': false, + 'value': customMatch +}); + +var v = 'foobar'.match( obj ); +console.log( v ); +// => [ 'custom', 'match', 'result' ] + +// Default match behavior: +v = 'football'.match( re ); +console.log( v ); +// => [ 'foo' ] +``` + +
+ + + + + +
+ +
+ + + + + + + + + + + + + + diff --git a/lib/node_modules/@stdlib/symbol/match/docs/repl.txt b/lib/node_modules/@stdlib/symbol/match/docs/repl.txt new file mode 100644 index 000000000000..a55f31ea3534 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/docs/repl.txt @@ -0,0 +1,19 @@ + +{{alias}} + Match symbol. + + This symbol is used as a method by String.prototype.match() to match an + input string against the current object and to determine whether an object + should be treated as a regular expression. + + The symbol is only supported in ES6/ES2015+ environments. For non-supporting + environments, the value is `null`. + + Examples + -------- + > var s = {{alias}} + e.g., + + See Also + -------- + diff --git a/lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts b/lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts new file mode 100644 index 000000000000..39baabe6cd1c --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts @@ -0,0 +1,31 @@ +/* +* @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 // + +/** +* Match symbol. +* +* ## Notes +* +* - This symbol is used as a method by `String.prototype.match()` to match an input string against the current object and to determine whether an object should be treated as a regular expression. +* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`. +*/ +export = Symbol.match; diff --git a/lib/node_modules/@stdlib/symbol/match/docs/types/test.ts b/lib/node_modules/@stdlib/symbol/match/docs/types/test.ts new file mode 100644 index 000000000000..80fde66ae03d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/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 Match = require( './index' ); + + +// TESTS // + +// The exported value is the `match` symbol... +{ + Match; +} diff --git a/lib/node_modules/@stdlib/symbol/match/examples/index.js b/lib/node_modules/@stdlib/symbol/match/examples/index.js new file mode 100644 index 000000000000..b27a8dcc8f2d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/examples/index.js @@ -0,0 +1,46 @@ +/** +* @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 defineProperty = require( '@stdlib/utils/define-property' ); +var MatchSymbol = require( './../lib' ); + +var obj = {}; +var re = /foo/; + +// Define a custom match behavior: +function customMatch() { + return [ 'custom', 'match', 'result' ]; +} + +defineProperty( obj, MatchSymbol, { + 'configurable': false, + 'enumerable': false, + 'writable': false, + 'value': customMatch +}); + +var v = 'foobar'.match( obj ); +console.log( v ); +// => [ 'custom', 'match', 'result' ] + +// Default match behavior: +v = 'football'.match( re ); +console.log( v ); +// => [ 'foo' ] diff --git a/lib/node_modules/@stdlib/symbol/match/lib/index.js b/lib/node_modules/@stdlib/symbol/match/lib/index.js new file mode 100644 index 000000000000..5c561a27777b --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/lib/index.js @@ -0,0 +1,53 @@ +/** +* @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'; + +/** +* Match symbol. +* +* @module @stdlib/symbol/match +* +* @example +* var MatchSymbol = require( '@stdlib/symbol/match' ); +* +* var obj = { +* 'toString': function toString() { +* return 'foo'; +* } +* }; +* +* obj[ MatchSymbol ] = function match( str ) { +* if ( str.indexOf( this.toString() ) !== -1 ) { +* return [ this.toString() ]; +* } +* return null; +* }; +* +* var str = 'football'; +* var v = str.match( obj ); +*/ + +// MAIN // + +var main = require( './main.js' ); + + +// EXPORTS // + +module.exports = main; diff --git a/lib/node_modules/@stdlib/symbol/match/lib/main.js b/lib/node_modules/@stdlib/symbol/match/lib/main.js new file mode 100644 index 000000000000..9b534aead438 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/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 hasMatchSymbolSupport = require( '@stdlib/assert/has-match-symbol-support' ); + + +// MAIN // + +/** +* Match symbol. +* +* @name MatchSymbol +* @constant +* @type {(symbol|null)} +* +* @example +* var obj = {}; +* +* obj[ MatchSymbol ] = function match( str ) { +* return [ 'beep' ]; +* }; +*/ +var MatchSymbol = ( hasMatchSymbolSupport() ) ? Symbol.match : null; + + +// EXPORTS // + +module.exports = MatchSymbol; diff --git a/lib/node_modules/@stdlib/symbol/match/package.json b/lib/node_modules/@stdlib/symbol/match/package.json new file mode 100644 index 000000000000..efd785cb4590 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/package.json @@ -0,0 +1,59 @@ +{ + "name": "@stdlib/symbol/match", + "version": "0.0.0", + "description": "Match 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", + "match", + "regex", + "regexp", + "string" + ] +} diff --git a/lib/node_modules/@stdlib/symbol/match/test/test.js b/lib/node_modules/@stdlib/symbol/match/test/test.js new file mode 100644 index 000000000000..38fb2e89930a --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/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 hasMatchSymbolSupport = require( '@stdlib/assert/has-match-symbol-support' ); +var isSymbol = require( '@stdlib/assert/is-symbol' ); +var Sym = require( './../lib' ); + + +// VARIABLES // + +var opts = { + 'skip': !hasMatchSymbolSupport() +}; + + +// TESTS // + +tape( 'main export is a symbol in supporting environments (ES6/2015+) or otherwise null', function test( 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.match`', opts, function test( t ) { + t.strictEqual( Sym, Symbol.match, 'returns expected value' ); + t.end(); +});