Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

magic-regexp

Package Overview
Dependencies
Maintainers
1
Versions
20
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

magic-regexp - npm Package Compare versions

Comparing version 0.0.4 to 0.1.0

12

dist/index.d.ts

@@ -35,2 +35,6 @@ declare type Flag = 'd' | 'g' | 'i' | 'm' | 's' | 'u' | 'y';

between: (min: number, max: number) => Input<T>;
/** specify that the expression can repeat any number of times, _including none_ */
any: () => Input<T>;
/** specify that the expression must occur at least x times */
atLeast: (min: number) => Input<T>;
};

@@ -44,2 +48,4 @@ /** 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()` */

};
/** this allows you to mark the input so far as optional */
optionally: () => Input<T>;
toString: () => string;

@@ -74,2 +80,3 @@ }

declare const exactly: (str: string | Input) => Input<never>;
declare const oneOrMore: (str: string | Input) => Input<never>;

@@ -87,5 +94,8 @@ declare const MagicRegExpSymbol: unique symbol;

}) | null;
matchAll<T extends string>(regexp: MagicRegExp<T>): IterableIterator<Omit<RegExpMatchArray, 'groups'> & {
groups: Record<T, string | undefined>;
}>;
}
}
export { Flag, Input, MagicRegExp, anyOf, carriageReturn, caseInsensitive, char, charIn, charNotIn, createRegExp, digit, dotAll, exactly, global, letter, linefeed, maybe, multiline, not, sticky, tab, unicode, whitespace, withIndices, word };
export { Flag, Input, MagicRegExp, anyOf, carriageReturn, caseInsensitive, char, charIn, charNotIn, createRegExp, digit, dotAll, exactly, global, letter, linefeed, maybe, multiline, not, oneOrMore, sticky, tab, unicode, whitespace, withIndices, word };

3

package.json
{
"name": "magic-regexp",
"version": "0.0.4",
"version": "0.1.0",
"description": "",

@@ -33,2 +33,3 @@ "repository": "danielroe/magic-regexp",

"test": "vitest run",
"test:types": "tsc --noEmit",
"_postinstall": "husky install",

@@ -35,0 +36,0 @@ "postpublish": "pinst --enable"

@@ -21,4 +21,4 @@ # 🦄 magic-regexp

- Supports automatically typed capture groups
- Packed with useful utilities: `charIn`, `charNotIn`, `anyOf`, `char`, `word`, `digit`, `whitespace`, `letter`, `tab`, `linefeed`, `carriageReturn`, `not`, `maybe`, `exactly`
- All chainable with `and`, `or`, `after`, `before`, `notAfter`, `notBefore`, `times`, `as`, `at`
- Packed with useful utilities: `charIn`, `charNotIn`, `anyOf`, `char`, `word`, `digit`, `whitespace`, `letter`, `tab`, `linefeed`, `carriageReturn`, `not`, `maybe`, `exactly`, `oneOrMore`
- All chainable with `and`, `or`, `after`, `before`, `notAfter`, `notBefore`, `times`, `as`, `at`, `optionally`

@@ -79,2 +79,3 @@ **Future ideas**

- `maybe` - equivalent to `?` - this marks the input as optional.
- `oneOrMore` - equivalent to `+` - this marks the input as repeatable, any number of times but at least once.
- `exactly` - this escapes a string input to match it exactly.

@@ -87,3 +88,4 @@

- `after`, `before`, `notAfter` and `notBefore` - these activate positive/negative lookahead/lookbehinds. 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).
- `times` - this is a function you can call directly to repeat the previous pattern an exact number of times, or you can use `times.between(min, max)` to specify a range.
- `times` - this is a function you can call directly to repeat the previous pattern an exact number of times, or you can use `times.between(min, max)` to specify a range, `times.atLeast(num)` to indicate it must repeat x times or `times.any()` to indicate it can repeat any number of times, _including none_.
- `optionally` - this is a function you can call to mark the current input as optional.
- `as` - 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()`.

@@ -125,3 +127,3 @@ - `at` - this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()`.

import { defineConfig } from 'vite'
import { MagicRegExpTransformPlugin } from 'magic-regexp'
import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'

@@ -153,3 +155,3 @@ export default defineConfig({

import { defineBuildConfig } from 'unbuild'
import { MagicRegExpTransformPlugin } from 'magic-regexp'
import { MagicRegExpTransformPlugin } from 'magic-regexp/transform'

@@ -165,2 +167,18 @@ export default defineBuildConfig({

## Examples
```js
import { createRegExp, exactly, oneOrMore, digit } from 'magic-regexp'
// Quick-and-dirty semver
createRegExp(
oneOrMore(digit)
.as('major')
.and('.')
.and(oneOrMore(digit).as('minor'))
.and(exactly('.').and(oneOrMore(char).as('patch')).optionally())
)
// /(?<major>(\d)+)\.(?<minor>(\d)+)(\.(?<patch>(.)+))?/
```
## 💻 Development

@@ -173,2 +191,7 @@

## Similar packages
- [verbal-expressions](http://verbalexpressions.github.io/)
- [typed-regex](https://github.com/phenax/typed-regex/)
## License

@@ -175,0 +198,0 @@

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc