magic-regexp
Advanced tools
Comparing version 0.0.2 to 0.0.3
@@ -18,13 +18,23 @@ declare type Flag = 'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'y'; | ||
interface Input<T extends string = never> { | ||
/** this adds a new pattern to the current input */ | ||
and: <X extends string = never>(input: string | Input<X>) => Input<T | X>; | ||
/** this provides an alternative to the current input */ | ||
or: <X extends string = never>(input: string | Input<X>) => Input<T | X>; | ||
/** this is a positive lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */ | ||
after: (input: string | Input) => Input<T>; | ||
/** this is a positive lookahead */ | ||
before: (input: string | Input) => Input<T>; | ||
/** these is a negative lookbehind. Make sure to check [browser support](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp#browser_compatibility) as not all browsers support lookbehinds (notably Safari) */ | ||
notAfter: (input: string | Input) => Input<T>; | ||
/** this is a negative lookahead */ | ||
notBefore: (input: string | Input) => Input<T>; | ||
times: { | ||
/** repeat the previous pattern an exact number of times */ | ||
(number: number): Input<T>; | ||
/** specify a range of times to repeat the previous pattern */ | ||
between: (min: number, max: number) => Input<T>; | ||
}; | ||
/** this defines the entire input so far as a named capture group. You will get type safety when using the resulting RegExp with `String.match()` */ | ||
as: <K extends string>(key: K) => Input<T | K>; | ||
/** this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()` */ | ||
at: { | ||
@@ -36,4 +46,7 @@ lineStart: () => Input<T>; | ||
} | ||
/** This matches any character in the string provided */ | ||
declare const charIn: (chars: string) => Input<never>; | ||
/** This matches any character that is not in the string provided */ | ||
declare const charNotIn: (chars: string) => Input<never>; | ||
/** This takes an array of inputs and matches any of them. */ | ||
declare const anyOf: <T extends string = never>(...args: (string | Input<T>)[]) => Input<T>; | ||
@@ -57,3 +70,5 @@ declare const char: Input<never>; | ||
}; | ||
/** Equivalent to `?` - this marks the input as optional */ | ||
declare const maybe: (str: string | Input) => Input<never>; | ||
/** This escapes a string input to match it exactly */ | ||
declare const exactly: (str: string | Input) => Input<never>; | ||
@@ -60,0 +75,0 @@ |
{ | ||
"name": "magic-regexp", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "", | ||
@@ -5,0 +5,0 @@ "repository": "danielroe/magic-regexp", |
@@ -57,4 +57,11 @@ # 🦄 magic-regexp | ||
Every regular expression you create with the library should be wrapped in `createRegExp`. | ||
Every pattern you create with the library should be wrapped in `createRegExp`. It also takes a second argument, which is an array of flags. | ||
```js | ||
import { createRegExp, global, multiline } from 'magic-regexp' | ||
createRegExp('string-to-match', [global, multiline]) | ||
// you can also pass flags directly as strings | ||
createRegExp('string-to-match', ['g', 'm']) | ||
``` | ||
> **Note** | ||
@@ -61,0 +68,0 @@ > By default, all helpers from `magic-regexp` assume that input that is passed should be escaped - so no special RegExp characters apply. So `createRegExp('foo?\d')` will not match `food3` but only `foo?\d` exactly. |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19351
229
169