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

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

-->

# SearchSymbol

> `Symbol.search` which is used to define the search behavior of objects when used with `String.prototype.search`.

<!-- 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 SearchSymbol = require( '@stdlib/symbol/search' );
```

#### searchSymbol

`Symbol.search` which is used to define the search behavior of objects when used with `String.prototype.search`.

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

- `Symbol.search` defines the behavior of an object when used by `String.prototype.search()`.
For example, when `str.search(obj)` is called, JavaScript will check for a `[Symbol.search]` method on `obj` and call it.

</section>

<!-- /.notes -->

<!-- Package usage examples. -->

<section class="examples">

## Examples

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

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

function searchFn(str) {
return str.indexOf('foo');
}

var myObj = {};
myObj[ SearchSymbol ] = searchFn;

console.log('foo bar'.search(myObj)); // 0
console.log('bar baz'.search(myObj)); // -1
```

</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/search/docs/repl.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@

{{alias}}
Has instance symbol.

This symbol is used to determine whether a constructor object recognizes an
object as its instance.

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

/**
* Search symbol.
*
* ## Notes
*
* - This symbol is used by `String.prototype.search()` to find the index of a match in a string.
* - The symbol is only supported in ES6/ES2015+ environments. For non-supporting environments, the value is `null`.
*/
export = Symbol.search;
30 changes: 30 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,30 @@
/*
* @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 SearchSymbol = require( './index' );


// TESTS //

// The exported value is the `search` symbol...
{
SearchSymbol;
}
30 changes: 30 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,30 @@
/**
* @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 SearchSymbol = require( './../lib' );

var mySearcher = {
[ SearchSymbol ]: function ( str ) {

Check failure on line 24 in lib/node_modules/@stdlib/symbol/search/examples/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Using 'FunctionExpression' is not allowed

Check failure on line 24 in lib/node_modules/@stdlib/symbol/search/examples/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Unexpected unnamed method

Check failure on line 24 in lib/node_modules/@stdlib/symbol/search/examples/index.js

View workflow job for this annotation

GitHub Actions / Lint Changed Files

Computed properties are not supported until Node.js 4.0.0. The configured version range is '>=0.12.18'
return str.indexOf( 'foo' );
}
};

console.log( 'foo bar'.search( mySearcher ) );
console.log( 'bar baz'.search( mySearcher ) );
49 changes: 49 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,49 @@
/**
* @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';

/**
* Symbol used to determine if a constructor object recognizes an object as its instance.
*
* @module @stdlib/symbol/search
*
* @example
* var isArray = require( '@stdlib/assert/is-array' );
* var SearchSymbol = require( '@stdlib/symbol/search' );
*
* function ArrayLike() {
* return {
* 'length': 3,
* '0': 1,
* '1': 2,
* '2': 3
* };
* }
*
* ArrayLike[ SearchSymbol ] = isArray;
*/

// MAIN //

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


// EXPORTS //

module.exports = main;
54 changes: 54 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,54 @@
/**
* @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 hasSearchSymbolSupport = require( '@stdlib/assert/has-search-symbol-support' );


// MAIN //

/**
* Search symbol.
*
* @name SearchSymbol
* @constant
* @type {(symbol|null)}
*
* @example
* var isArray = require( '@stdlib/assert/is-array' );
*
* function ArrayLike() {
* return {
* 'length': 3,
* '0': 1,
* '1': 2,
* '2': 3
* };
* };
*
* ArrayLike[ SearchSymbol ] = isArray;
*/
var SearchSymbol = ( hasSearchSymbolSupport() ) ? Symbol.search : null;


// EXPORTS //

module.exports = SearchSymbol;
56 changes: 56 additions & 0 deletions lib/node_modules/@stdlib/symbol/search/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
{
"name": "@stdlib/symbol/search",
"version": "0.0.0",
"description": "Search 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",
"search"
]
}
Loading
Loading