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
b1b5d27
commit 9a562ff
Showing
8 changed files
with
118 additions
and
25 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 |
---|---|---|
@@ -1,2 +1 @@ | ||
* text=auto | ||
*.js text eol=lf | ||
* text=auto eol=lf |
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '10' | ||
- '8' | ||
- '6' |
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,77 @@ | ||
declare namespace cloneRegexp { | ||
interface Options { | ||
/** | ||
Modifies the [`source`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/source) property of the cloned `RegExp` instance. | ||
*/ | ||
source?: string; | ||
|
||
/** | ||
Modifies the [`global`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/global) property of the cloned `RegExp` instance. | ||
*/ | ||
global?: boolean; | ||
|
||
/** | ||
Modifies the [`ignoreCase`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/ignoreCase) property of the cloned `RegExp` instance. | ||
*/ | ||
ignoreCase?: boolean; | ||
|
||
/** | ||
Modifies the [`multiline`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/multiline) property of the cloned `RegExp` instance. | ||
*/ | ||
multiline?: boolean; | ||
|
||
/** | ||
Modifies the [`dotAll`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/dotAll) property of the cloned `RegExp` instance. | ||
*/ | ||
dotAll?: boolean; | ||
|
||
/** | ||
Modifies the [`sticky`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/sticky) property of the cloned `RegExp` instance. | ||
*/ | ||
sticky?: boolean; | ||
|
||
/** | ||
Modifies the [`unicode`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/unicode) property of the cloned `RegExp` instance. | ||
*/ | ||
unicode?: boolean; | ||
|
||
/** | ||
Modifies the [`lastIndex`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/lastIndex) property of the cloned `RegExp` instance. | ||
*/ | ||
lastIndex?: number; | ||
} | ||
} | ||
|
||
/** | ||
Clone and modify a [RegExp](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) instance. | ||
@param regexp - Regex to clone. | ||
@example | ||
``` | ||
import cloneRegexp = require('clone-regexp'); | ||
const regex = /[a-z]/gi; | ||
cloneRegexp(regex); | ||
//=> /[a-z]/gi | ||
cloneRegexp(regex) === regex; | ||
//=> false | ||
cloneRegexp(regex, {global: false}); | ||
//=> /[a-z]/i | ||
cloneRegexp(regex, {multiline: true}); | ||
//=> /[a-z]/gim | ||
cloneRegexp(regex, {source: 'unicorn'}); | ||
//=> /unicorn/gi | ||
``` | ||
*/ | ||
declare function cloneRegexp( | ||
regexp: RegExp, | ||
options?: cloneRegexp.Options | ||
): RegExp; | ||
|
||
export = cloneRegexp; |
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,14 @@ | ||
import {expectType} from 'tsd'; | ||
import cloneRegexp = require('.'); | ||
|
||
const regex = /[a-z]/gi; | ||
|
||
expectType<RegExp>(cloneRegexp(regex)); | ||
expectType<RegExp>(cloneRegexp(regex, {source: 'unicorn'})); | ||
expectType<RegExp>(cloneRegexp(regex, {global: false})); | ||
expectType<RegExp>(cloneRegexp(regex, {ignoreCase: true})); | ||
expectType<RegExp>(cloneRegexp(regex, {multiline: true})); | ||
expectType<RegExp>(cloneRegexp(regex, {dotAll: true})); | ||
expectType<RegExp>(cloneRegexp(regex, {sticky: true})); | ||
expectType<RegExp>(cloneRegexp(regex, {unicode: true})); | ||
expectType<RegExp>(cloneRegexp(regex, {lastIndex: 1})); |
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
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