https://github.com/opensly/isregex
Determines if a given value is a regular expression.
https://github.com/opensly/isregex
Last synced: about 1 year ago
JSON representation
Determines if a given value is a regular expression.
- Host: GitHub
- URL: https://github.com/opensly/isregex
- Owner: opensly
- License: mit
- Created: 2024-11-09T02:58:32.000Z (over 1 year ago)
- Default Branch: main
- Last Pushed: 2024-11-09T03:14:19.000Z (over 1 year ago)
- Last Synced: 2025-02-06T17:11:41.001Z (over 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 7.81 KB
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# isRegex
Determines if a given value is a regular expression.
## Usage Guide
Some usage examples for the `isRegex` function:
#### Basic Type Checking
```
import isRegex from './isRegex';
const pattern = /abc/;
console.log(isRegex(pattern)); // true
const nonPattern = 'abc';
console.log(isRegex(nonPattern)); // false
```
#### Validation before using regex methods
```
const maybePattern = '/[a-z]/';
if (isRegex(maybePattern)) {
console.log(maybePattern.test('hello')); // Executes safely
} else {
console.log('Not a valid regex pattern');
}
```
#### Filtering an Array
```
const items = [/test/, 'hello', /abc/, 123];
const regexItems = items.filter(isRegex);
console.log(regexItems); // [/test/, /abc/]
```
## Support
Your support inspires & encourage us more. If you are interested to make a donation to us, please click the below PayPal button.
[](https://www.paypal.me/LakshmikanthV)
## License
This project is licensed under the MIT License.