Skip to content

Commit

Permalink
chore: drop prettier and use antfu lint config
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Mar 7, 2024
1 parent 4085c3c commit c07b7ef
Show file tree
Hide file tree
Showing 48 changed files with 1,401 additions and 478 deletions.
2 changes: 0 additions & 2 deletions .eslintignore

This file was deleted.

29 changes: 0 additions & 29 deletions .eslintrc.cjs

This file was deleted.

4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/---bug-report.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "\U0001F41B Bug report"
name: 🐛 Bug report
description: Something's not working
labels: ["bug"]
labels: [bug]
assignees: danielroe
body:
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/---documentation.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "\U0001F4DA Documentation"
name: 📚 Documentation
description: How do I ... ?
labels: ["documentation"]
labels: [documentation]
assignees: danielroe
body:
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions .github/ISSUE_TEMPLATE/---feature-suggestion.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: "\U0001F195 Feature suggestion"
name: 🆕 Feature suggestion
description: Suggest an idea
labels: ["enhancement"]
labels: [enhancement]
assignees: danielroe
body:
- type: textarea
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 16
cache: "pnpm"
cache: pnpm

- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
Expand All @@ -35,7 +35,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 16
cache: "pnpm"
cache: pnpm

- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
12 changes: 6 additions & 6 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
name: "CodeQL"
name: CodeQL

on:
push:
branches: [ "main" ]
branches: [main]
pull_request:
branches: [ "main" ]
branches: [main]
schedule:
- cron: "2 2 * * 0"
- cron: '2 2 * * 0'

jobs:
analyze:
Expand All @@ -20,7 +20,7 @@ jobs:
strategy:
fail-fast: false
matrix:
language: [ javascript ]
language: [javascript]

steps:
- name: Checkout
Expand All @@ -38,4 +38,4 @@ jobs:
- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v3
with:
category: "/language:${{ matrix.language }}"
category: '/language:${{ matrix.language }}'
2 changes: 1 addition & 1 deletion .github/workflows/performance.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
- uses: actions/setup-node@v4
with:
node-version: 16
cache: "pnpm"
cache: pnpm

- name: 📦 Install dependencies
run: pnpm install --frozen-lockfile
Expand Down
1 change: 1 addition & 0 deletions build.config.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { defineBuildConfig } from 'unbuild'

export default defineBuildConfig({
declaration: true,
rollup: { emitCJS: true },
Expand Down
4 changes: 3 additions & 1 deletion docs/components/content/Logo.vue
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
<template>
<div class="font-bold flex flex-row items-center gap-2">🦄 magic-regexp</div>
<div class="font-bold flex flex-row items-center gap-2">
🦄 magic-regexp
</div>
</template>
1 change: 0 additions & 1 deletion docs/content/1.index.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ secondary:
snippet: npm install magic-regexp
---


#title
🦄 magic-regexp

Expand Down
32 changes: 16 additions & 16 deletions docs/content/2.getting-started/2.usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Every pattern you create with the library should be wrapped in `createRegExp`, w
`createRegExp` accepts an arbitrary number of arguments of type `string` or `Input` (built up using helpers from `magic-regexp`), and an optional final argument of an array of flags or a flags string. It creates a `MagicRegExp`, which concatenates all the patterns from the arguments that were passed in.

```js
import { createRegExp, global, multiline, exactly } from 'magic-regexp'
import { createRegExp, exactly, global, multiline } from 'magic-regexp'

createRegExp(exactly('foo').or('bar'))

Expand All @@ -33,7 +33,7 @@ createRegExp(
maybe('bar').groupedAs('g1'),
'baz',
[global, multiline]
)
)
// equivalent to /foo(?<g1>(?:bar)?)baz/gm
```

Expand Down Expand Up @@ -63,17 +63,17 @@ All helpers that takes `string` and `Input` are variadic functions, so you can p

All of the helpers above return an object of type `Input` that can be chained with the following helpers:

| | |
| --------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `and` | this takes a variable number of inputs and adds them as new pattern to the current input, or you can use `and.referenceTo(groupName)` to adds a new pattern referencing to a named group. |
| `or` | this takes a variable number of inputs and provides as an alternative to the current input. |
| `after`, `before`, `notAfter` and `notBefore` | these takes a variable number of inputs and 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.atLeast(x)` to indicate it must repeat at least x times, `times.atMost(x)` to indicate it must repeat at most 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` | alias for `groupedAs` |
| `groupedAs` | 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()`. |
| `grouped` | this defines the entire input so far as an anonymous group. |
| `at` | this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()`. |
| | |
| --------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `and` | this takes a variable number of inputs and adds them as new pattern to the current input, or you can use `and.referenceTo(groupName)` to adds a new pattern referencing to a named group. |
| `or` | this takes a variable number of inputs and provides as an alternative to the current input. |
| `after`, `before`, `notAfter` and `notBefore` | these takes a variable number of inputs and 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.atLeast(x)` to indicate it must repeat at least x times, `times.atMost(x)` to indicate it must repeat at most 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` | alias for `groupedAs` |
| `groupedAs` | 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()`. |
| `grouped` | this defines the entire input so far as an anonymous group. |
| `at` | this allows you to match beginning/ends of lines with `at.lineStart()` and `at.lineEnd()`. |

::alert
By default, for better regex performance, creation input helpers such as `anyOf`, `maybe`, `oneOrMore`, and chaining input helpers such as `or`, `times(.between/atLeast/any)`, or `optionally` will wrap the input in a non-capturing group with `(?:)`. You can use chaining input helper `grouped` after any `Input` type to capture it as an anonymous group.
Expand Down Expand Up @@ -105,7 +105,7 @@ You can also call `.toString()` on any input to see the same information at runt
We also provide an experimental feature that allows you to obtain the type-level results of a RegExp match or replace in string literals. To try this feature, please import all helpers from a subpath export `magic-regexp/further-magic` instead of `magic-regexp`.

```ts
import { createRegExp, exactly, digit } from 'magic-regexp/further-magic'
import { createRegExp, digit, exactly } from 'magic-regexp/further-magic'
```

This feature is especially useful when you want to obtain the type of the matched groups or test if your RegExp matches and captures from a given string as expected.
Expand All @@ -116,12 +116,12 @@ This feature works best for matching literal strings such as
```
which will return a matched result of type `['foo', 'foo']`. `result.groups` of type `{ g1: 'foo' }`, `result.index` of type `0` and `result.length` of type `2`.

If matching with dynamic string, such as
If matching with dynamic string, such as
```ts
myString.match(createRegExp(exactly('foo').or('bar').groupedAs('g1')))
```
the type of the matched result will be `null`, or array of union of possible matches `["bar", "bar"] | ["foo", "foo"]` and `result.groups` will be type `{ g1: "bar" } | { g1: "foo" }`.

::alert
For more usage details please see the [usage examples](3.examples.md#type-level-regexp-match-and-replace-result-experimental) or [test](https://github.com/danielroe/magic-regexp/blob/main/test/further-magic.test.ts). For type-related issues, please report them to [type-level-regexp](https://github.com/didavid61202/type-level-regexp).
::
::
27 changes: 13 additions & 14 deletions docs/content/2.getting-started/3.examples.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ title: Examples
### Quick-and-dirty semver

```js
import { createRegExp, exactly, maybe, oneOrMore, digit, char } from 'magic-regexp'
import { char, createRegExp, digit, exactly, maybe, oneOrMore } from 'magic-regexp'

createRegExp(
oneOrMore(digit).groupedAs('major'),
Expand All @@ -20,7 +20,7 @@ createRegExp(

```js
import assert from 'node:assert'
import { createRegExp, wordChar, char, oneOrMore } from 'magic-regexp'
import { char, createRegExp, oneOrMore, wordChar } from 'magic-regexp'

const TENET_RE = createRegExp(
wordChar
Expand All @@ -44,13 +44,13 @@ This feature is still experimental, to try it please import `createRegExp ` and
When matching or replacing with literal string such as `magic-regexp v3.2.5.beta.1 just release!`

```ts
import {
createRegExp,
oneOrMore,
exactly,
anyOf,
digit,
wordChar
import {
anyOf,
createRegExp,
digit,
exactly,
oneOrMore,
wordChar
} from 'magic-regexp/further-magic'

const literalString = 'magic-regexp 3.2.5.beta.1 just release!'
Expand Down Expand Up @@ -82,17 +82,17 @@ matchResult.groups

// `String.replace()` example
const replaceResult = literalString.replace(
semverRegExp,
semverRegExp,
`minor version "$2" brings many great DX improvements, while patch "$<patch>" fix some bugs and it's`
)
)

replaceResult // "magic-regexp minor version \"2\" brings many great DX improvements, while patch \"5.beta.1\" fix some bugs and it's just release!"
```

When matching dynamic string, the result will be union of possible matches

```ts
let myString = 'dynamic'
const myString = 'dynamic'

const RegExp = createRegExp(exactly('foo').or('bar').groupedAs('g1'))
const matchAllResult = myString.match(RegExp)
Expand All @@ -103,12 +103,11 @@ matchAllResult
// namedCaptures: ["g1", "bar"] | ["g1", "foo"];
// input: string;
// restInput: undefined;
// }>
// }>
matchAllResult?.[0] // ['foo', 'foo'] | ['bar', 'bar']
matchAllResult?.length // 2 | undefined
matchAllResult?.groups
// groups: {
// g1: "foo" | "bar";
// } | undefined
```

2 changes: 1 addition & 1 deletion docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "magic-regexp-docs",
"version": "1.0.0",
"description": "A compiled-away, type-safe, readable RegExp alternative",
"homepage": "https://regexp.dev/",
"license": "MIT",
"homepage": "https://regexp.dev/",
"scripts": {
"dev": "nuxi dev",
"build": "nuxi build",
Expand Down
20 changes: 10 additions & 10 deletions docs/tokens.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ import { defineTheme } from 'pinceau'
export default defineTheme({
color: {
primary: {
'50': '#ff46c5',
'100': '#ff3cbb',
'200': '#ff32b1',
'300': '#ff28a7',
'400': '#ff1e9d',
'500': '#ff1493',
'600': '#f50a89',
'700': '#eb007f',
'800': '#e10075',
'900': '#d7006b',
50: '#ff46c5',
100: '#ff3cbb',
200: '#ff32b1',
300: '#ff28a7',
400: '#ff1e9d',
500: '#ff1493',
600: '#f50a89',
700: '#eb007f',
800: '#e10075',
900: '#d7006b',
},
},
})
8 changes: 8 additions & 0 deletions eslint.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import antfu from '@antfu/eslint-config'

export default antfu({
stylistic: true,
rules: {
'ts/method-signature-style': 'off',
},
})
3 changes: 2 additions & 1 deletion examples/date.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { anyOf, createRegExp, digit, exactly } from 'magic-regexp'

// YYYY-MM-DD
Expand All @@ -9,7 +10,7 @@ const day = anyOf(
exactly('1').and(digit),
exactly('2').and(digit),
'30',
'31'
'31',
).groupedAs('day')

const date = createRegExp(exactly(year, '-', month, '-', day))
Expand Down
3 changes: 2 additions & 1 deletion examples/email.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { anyOf, createRegExp, digit, letter, oneOrMore } from 'magic-regexp'

const email = createRegExp(
Expand All @@ -8,7 +9,7 @@ const email = createRegExp(
oneOrMore(anyOf(letter, digit, '-', '.')).groupedAs('domain'),
'.',
// TLD
oneOrMore(letter).groupedAs('tld')
oneOrMore(letter).groupedAs('tld'),
)

/**
Expand Down
3 changes: 2 additions & 1 deletion examples/semver.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/* eslint-disable no-console */
import { anyOf, createRegExp, digit, letter, maybe, oneOrMore } from 'magic-regexp'

// https://semver.org/
Expand All @@ -19,7 +20,7 @@ const semver = createRegExp(
maybe('-'),
maybe(prerelease),
maybe('+'),
maybe(build)
maybe(build),
)

/**
Expand Down
5 changes: 3 additions & 2 deletions examples/time.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
/* eslint-disable no-console */
import { anyOf, createRegExp, digit, exactly } from 'magic-regexp'

const hour = anyOf(exactly('0').and(digit), exactly('1').and(anyOf('0', '1', '2'))).groupedAs(
'hour'
'hour',
)

const minute = anyOf(
Expand All @@ -10,7 +11,7 @@ const minute = anyOf(
exactly('2').and(digit),
exactly('3').and(digit),
exactly('4').and(digit),
exactly('5').and(digit)
exactly('5').and(digit),
).groupedAs('minute')

const dayPart = anyOf(exactly('AM'), exactly('PM')).groupedAs('dayPart')
Expand Down
Loading

0 comments on commit c07b7ef

Please sign in to comment.