From 0f19917af080e9b8eb481f43bf646b1194914365 Mon Sep 17 00:00:00 2001 From: Aniket Sonawane Date: Sun, 8 Mar 2026 01:57:42 +0530 Subject: [PATCH] feat: add symbol/match package --- type: pre_commit_static_analysis_report description: Results of running static analysis checks when committing changes. report: - task: lint_filenames status: passed - task: lint_editorconfig status: passed - task: lint_markdown status: passed - task: lint_package_json status: passed - task: lint_repl_help status: passed - task: lint_javascript_src status: passed - task: lint_javascript_cli status: na - task: lint_javascript_examples status: passed - task: lint_javascript_tests status: passed - task: lint_javascript_benchmarks status: na - task: lint_python status: na - task: lint_r status: na - task: lint_c_src status: na - task: lint_c_examples status: na - task: lint_c_benchmarks status: na - task: lint_c_tests_fixtures status: na - task: lint_shell status: na - task: lint_typescript_declarations status: passed - task: lint_typescript_tests status: passed - task: lint_license_headers status: passed --- --- .../@stdlib/symbol/match/README.md | 149 ++++++++++++++++++ .../@stdlib/symbol/match/docs/repl.txt | 18 +++ .../symbol/match/docs/types/index.d.ts | 31 ++++ .../@stdlib/symbol/match/docs/types/test.ts | 29 ++++ .../@stdlib/symbol/match/examples/index.js | 44 ++++++ .../@stdlib/symbol/match/lib/index.js | 42 +++++ .../@stdlib/symbol/match/lib/main.js | 47 ++++++ .../@stdlib/symbol/match/package.json | 58 +++++++ .../@stdlib/symbol/match/test/test.js | 52 ++++++ 9 files changed, 470 insertions(+) create mode 100644 lib/node_modules/@stdlib/symbol/match/README.md create mode 100644 lib/node_modules/@stdlib/symbol/match/docs/repl.txt create mode 100644 lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts create mode 100644 lib/node_modules/@stdlib/symbol/match/docs/types/test.ts create mode 100644 lib/node_modules/@stdlib/symbol/match/examples/index.js create mode 100644 lib/node_modules/@stdlib/symbol/match/lib/index.js create mode 100644 lib/node_modules/@stdlib/symbol/match/lib/main.js create mode 100644 lib/node_modules/@stdlib/symbol/match/package.json create mode 100644 lib/node_modules/@stdlib/symbol/match/test/test.js 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..55d718ee5708 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/README.md @@ -0,0 +1,149 @@ + + +# 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`. +- The `MatchSymbol` is used by `String.prototype.match` to match an input string against an object. When `String.prototype.match` is called, it checks whether the argument has a `MatchSymbol` method. If present, this method is invoked with the input string as its argument, and the returned value becomes the result of the match operation. +- The presence of `MatchSymbol` on an object also determines whether the object should be treated as a regular expression when used with string matching methods. + +
+ + + + + +
+ +## 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' ]; +} + +// Attach the custom matcher using Symbol.match: +defineProperty( obj, MatchSymbol, { + 'configurable': false, + 'enumerable': false, + 'writable': false, + 'value': customMatch +}); + +// Using custom match behavior: +var v = 'foobar'.match( obj ); +console.log( v ); +// => [ 'custom', 'match', 'result' ] + +// Default regular expression match: +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..59e7b4ae676d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/docs/repl.txt @@ -0,0 +1,18 @@ + +{{alias}} + Match symbol. + + This symbol which specifies 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..74366b1496cf --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts @@ -0,0 +1,31 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 which specifies 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..62e4213179e7 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/docs/types/test.ts @@ -0,0 +1,29 @@ +/* +* @license Apache-2.0 +* +* Copyright (c) 2026 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 MatchSymbol = require( './index' ); + + +// TESTS // + +// The exported value is the match symbol... +{ + MatchSymbol; +} 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..8351c5011cd0 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/examples/index.js @@ -0,0 +1,44 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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/; + +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' ] + +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..10ba72c0bf4b --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/lib/index.js @@ -0,0 +1,42 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 = {}; +* obj[ MatchSymbol ] = function () { +* return [ 'matched' ]; +* }; +*/ + +// 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..747c0f9fa57d --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/lib/main.js @@ -0,0 +1,47 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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 () { +* return [ 'matched' ]; +* }; +*/ + +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..74378b15843c --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/package.json @@ -0,0 +1,58 @@ +{ + "name": "@stdlib/symbol/match", + "version": "0.0.0", + "description": "Symbol match.", + "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", + "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..ad157683f506 --- /dev/null +++ b/lib/node_modules/@stdlib/symbol/match/test/test.js @@ -0,0 +1,52 @@ +/** +* @license Apache-2.0 +* +* Copyright (c) 2026 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, 'is an alias' ); + t.end(); +});