Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
149 changes: 149 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
<!--

@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.

-->

# MatchSymbol

> [symbol][mdn-symbol] which specifies whether an object should be treated as a regular expression.

<!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. -->

<section class="intro">

</section>

<!-- /.intro -->

<!-- Package usage documentation. -->

<section class="usage">

## 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'
```

</section>

<!-- /.usage -->

<!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="notes">

## 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.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

<!-- eslint no-undef: "error" -->

```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' ]
```

</section>

<!-- /.examples -->

<!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="references">

</section>

<!-- /.references -->

<!-- Section for related `stdlib` packages. Do not manually edit this section, as it is automatically populated. -->

<section class="related">

* * *

## See Also

- <span class="package-name">[`@stdlib/symbol/ctor`][@stdlib/symbol/ctor]</span><span class="delimiter">: </span><span class="description">symbols.</span>

</section>

<!-- /.related -->

<!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. -->

<section class="links">

[mdn-symbol]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol

<!-- <related-links> -->

[@stdlib/symbol/ctor]: https://github.com/stdlib-js/stdlib/tree/develop/lib/node_modules/%40stdlib/symbol/ctor

<!-- </related-links> -->

</section>

<!-- /.links -->
18 changes: 18 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -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., <symbol>

See Also
--------

31 changes: 31 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/docs/types/index.d.ts
Original file line number Diff line number Diff line change
@@ -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;
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/docs/types/test.ts
Original file line number Diff line number Diff line change
@@ -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;
}
44 changes: 44 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/examples/index.js
Original file line number Diff line number Diff line change
@@ -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' ]
42 changes: 42 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/lib/index.js
Original file line number Diff line number Diff line change
@@ -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;
47 changes: 47 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/lib/main.js
Original file line number Diff line number Diff line change
@@ -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;
Loading