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
135 changes: 135 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
<!--

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

-->

# SearchSymbol

> [`Symbol.search`][mdn-symbol-search], which specifies the method used by [`String.prototype.search()`][mdn-string-search] to match a regular expression or a custom object.

<section class="intro">

The `Symbol.search` symbol allows objects to define custom search behavior when used with the built-in `String.prototype.search()` method.

</section>

<section class="usage">

## Usage

```javascript
var SearchSymbol = require( '@stdlib/symbol/search' );
```

#### SearchSymbol

[`symbol`][mdn-symbol] which specifies the method used by `String.prototype.search()` to determine how a string is searched.
Objects that define a `[Symbol.search]` method can customize their own search behavior.

```javascript
var s = typeof SearchSymbol;
// 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`.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

```javascript
var SearchSymbol = require( '@stdlib/symbol/search' );

/**
* Constructor for creating search objects.
*
* @param {string} value - search value
* @returns {Search} search instance
*/
function Search( value ) {
if ( !(this instanceof Search) ) {
return new Search( value );
}
this.value = value;
}

/**
* Implement `Symbol.search`.
*
* @param {string} str - input string
* @returns {integer} match index
*/
function searchMethod( str ) {
return str.indexOf( this.value );
}

Search.prototype[ SearchSymbol ] = searchMethod;

console.log( 'foobar'.search( new Search( 'bar' ) ) );
// => 3
```

</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
[mdn-symbol-search]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Symbol/search
[mdn-string-search]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/search

</section>

<!-- /.links -->
18 changes: 18 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{{alias}}
Search symbol.

This symbol specifies whether an array-like object should be flattened to
its elements during concatenation.

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

/**
* Search symbol.
*
* ## Notes
*
* - This symbol specifies the method used by `String.prototype.search()`.
* - Objects defining a `[Symbol.search]` method can customize how they are searched within a string.
*/
export = Symbol.search;
29 changes: 29 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/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 search = require( './index' );


// TESTS //

// The exported value is the `search` symbol...
{
search;;
}
43 changes: 43 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/examples/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/**
* @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 SearchSymbol = require( './../lib' );

// MAIN //

/**
* Example demonstrating the use of Symbol.search.
*/
function Search( value ) {
if ( !(this instanceof Search) ) {
return new Search( value );
}
this.value = value;
}

Search.prototype[ SearchSymbol ] = function search( str ) {
return str.indexOf( this.value );
};

// EXPORTS //

console.log( 'foobar'.search( new Search( 'bar' ) ) );
52 changes: 52 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/lib/index.js
Original file line number Diff line number Diff line change
@@ -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';

/**
* Search symbol.
*
* @module @stdlib/symbol/search
*
* @example
* // eslint-disable stdlib/jsdoc-doctest
* var SearchSymbol = require( '@stdlib/symbol/search' );
*
* class Search {
* constructor( value ) {
* this.value = value;
* }
* [ SearchSymbol ]( string ) {
* return string.indexOf( this.value );
* }
* }
*
* console.log( 'foobar'.search( new Search( 'bar' ) ) );
* // => 3
* // eslint-enable stdlib/jsdoc-doctest
*/


// MAIN //

var main = require( './main.js' );


// EXPORTS //

module.exports = main;
55 changes: 55 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/lib/main.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
/**
* @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 hasSearchSymbolSupport = require( '@stdlib/assert/has-search-symbol-support' );
var Symbol = require( '@stdlib/symbol/ctor' );


// MAIN //

/**

Check failure on line 29 in lib/node_modules/@stdlib/symbol/search/lib/main.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Encountered an error while running code: Identifier 'ExampleSearch' has already been declared
* Symbol which specifies the method to match against a string.
*
* @constant
* @type {(symbol|null)}
*
* @example
* // eslint-disable stdlib/jsdoc-doctest
* class ExampleSearch {
* constructor( value ) {
* this.value = value;
* }
* [ SearchSymbol ]( str ) {
* return str.indexOf( this.value );
* }
* }
*
* console.log( 'foobar'.search( new ExampleSearch( 'bar' ) ) );
* // => 3
* // eslint-enable stdlib/jsdoc-doctest
*/
var SearchSymbol = ( hasSearchSymbolSupport() ) ? Symbol.search : null;


// EXPORTS //

module.exports = SearchSymbol;
Loading
Loading