-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4f2e48c
commit 58e7d96
Showing
5 changed files
with
55 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import * as _ from 'radashi' | ||
import { bench } from 'vitest' | ||
|
||
describe('isRegExp', () => { | ||
bench('with no arguments', () => { | ||
_.isRegExp() | ||
}) | ||
}) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
--- | ||
title: isRegExp | ||
description: Returns true for RegExp instances | ||
--- | ||
|
||
## Basic usage | ||
|
||
Returns true for `RegExp` instances, even if they are subclass instances or from | ||
other [realms](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/instanceof#instanceof_and_multiple_realms). | ||
|
||
```ts | ||
import * as _ from 'radashi' | ||
|
||
_.isRegExp(/.+/) // true | ||
_.isRegExp(new RegExp('.+')) // true | ||
_.isRegExp(new (class extends RegExp {})('.+')) // true | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { isTagged } from 'radashi' | ||
|
||
export function isRegExp(value: unknown): value is RegExp { | ||
return isTagged(value, '[object RegExp]') | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import * as vm from 'node:vm' | ||
import * as _ from 'radashi' | ||
|
||
describe('isRegExp', () => { | ||
test('returns true for RegExp instances', () => { | ||
expect(_.isRegExp(/.+/)).toBe(true) | ||
}) | ||
test('returns true for RegExp subclass instances', () => { | ||
expect(_.isRegExp(new (class extends RegExp {})('.+'))).toBe(true) | ||
}) | ||
test('returns true for RegExp instances from other realms', () => { | ||
expect(_.isRegExp(vm.runInNewContext('/.+/'))).toBe(true) | ||
}) | ||
test('returns false for undefined', () => { | ||
expect(_.isRegExp(undefined)).toBe(false) | ||
}) | ||
test('returns false for null', () => { | ||
expect(_.isRegExp(null)).toBe(false) | ||
}) | ||
test('returns false for non-Set objects', () => { | ||
expect(_.isRegExp({})).toBe(false) | ||
}) | ||
}) |