Skip to content
Open
Show file tree
Hide file tree
Changes from 7 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
133 changes: 133 additions & 0 deletions lib/node_modules/@stdlib/symbol/match/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
<!--

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

-->

# MatchSymbol

> [Symbol][mdn-symbol] which specifies the matching of a regular expression against a string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
> [Symbol][mdn-symbol] which specifies the matching of a regular expression against a string.
> [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 the matching of a regular expression against a string. Used by `String.prototype.match()`.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
[`Symbol`][mdn-symbol] which specifies the matching of a regular expression against a string. Used by `String.prototype.match()`.
[`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`.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Describe how MatchSymbol is used here. 1) As a method used by String.prototype.match to match an input string against the current object. This method is provided a single argument: a string. 2) To determine whether an object should be treated as a regular expression.

This is discussed in more depth on MDN: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/match

</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' ];
}

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( JSON.stringify( v ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need JSON.stringify.

// => '["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">

</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

</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 specifies the matching of a regular expression against a string.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated once the README is updated.

It is used by String.prototype.match().

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) 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 specifies the matching of a regular expression against a string. Used by String.prototype.match().
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be updated once README is updated.

* - 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) 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 IsConcatSpreadable = require( './index' );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy-paste mistake.



// TESTS //

// The exported value is the `isConcatSpreadable` symbol...
{
IsConcatSpreadable;
}
46 changes: 46 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,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( JSON.stringify( v ) );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No JSON.stringify.

// => '["foo"]'
53 changes: 53 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,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;
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) 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 re = /foo/;
* var str = 'football';
*
* var v = str.match( re );
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This example doesn't actually demonstrate symbol.match usage.

* // returns <Array>
*/
var MatchSymbol = ( hasMatchSymbolSupport() ) ? Symbol.match : null;


// EXPORTS //

module.exports = MatchSymbol;
Loading