Skip to content

Commit 1a519c6

Browse files
committed
chore: init
0 parents  commit 1a519c6

32 files changed

+6793
-0
lines changed

.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
root = true
2+
3+
[*]
4+
end_of_line = lf
5+
insert_final_newline = true
6+
trim_trailing_whitespace = true
7+
charset = utf-8
8+
9+
[*.js]
10+
indent_style = space
11+
indent_size = 2
12+
13+
[{package.json,*.yml,*.cjson}]
14+
indent_style = space
15+
indent_size = 2

.eslintignore

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
dist
2+
node_modules

.eslintrc.cjs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
module.exports = {
2+
env: {
3+
browser: true,
4+
es6: true,
5+
node: true,
6+
},
7+
parser: '@typescript-eslint/parser',
8+
parserOptions: {
9+
sourceType: 'module',
10+
},
11+
plugins: ['@typescript-eslint'],
12+
extends: [
13+
'plugin:@typescript-eslint/recommended',
14+
'eslint:recommended',
15+
'plugin:prettier/recommended',
16+
'prettier',
17+
],
18+
rules: {
19+
'@typescript-eslint/ban-ts-comment': 'off',
20+
'@typescript-eslint/ban-types': 'off',
21+
'@typescript-eslint/explicit-function-return-type': 'off',
22+
'@typescript-eslint/explicit-module-boundary-types': 'off',
23+
'@typescript-eslint/no-inferrable-types': 1,
24+
'@typescript-eslint/no-explicit-any': 'off',
25+
'no-unused-vars': 'off',
26+
'no-redeclare': 'off',
27+
},
28+
}
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
name: "\U0001F41B Bug report"
2+
description: Something's not working
3+
title: "fix: "
4+
labels: ["bug"]
5+
assignees: danielroe
6+
body:
7+
- type: textarea
8+
validations:
9+
required: true
10+
attributes:
11+
label: 🐛 The bug
12+
description: What isn't working? Describe what the bug is.
13+
- type: input
14+
validations:
15+
required: true
16+
attributes:
17+
label: 🛠️ To reproduce
18+
description: A reproduction of the bug via https://stackblitz.com/github/danielroe/magic-regexp/tree/main/playground
19+
placeholder: https://stackblitz.com/[...]
20+
- type: textarea
21+
validations:
22+
required: true
23+
attributes:
24+
label: 🌈 Expected behaviour
25+
description: What did you expect to happen? Is there a section in the docs about this?
26+
- type: textarea
27+
attributes:
28+
label: ℹ️ Additional context
29+
description: Add any other context about the problem here.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "\U0001F4DA Documentation"
2+
description: How do I ... ?
3+
title: "docs: "
4+
labels: ["documentation"]
5+
assignees: danielroe
6+
body:
7+
- type: textarea
8+
validations:
9+
required: true
10+
attributes:
11+
label: 📚 Is your documentation request related to a problem?
12+
description: A clear and concise description of what the problem is.
13+
placeholder: I feel I should be able to [...] but I can't see how to do it from the docs.
14+
- type: textarea
15+
attributes:
16+
label: 🔍 Where should you find it?
17+
description: What page of the docs do you expect this information to be found on?
18+
- type: textarea
19+
attributes:
20+
label: ℹ️ Additional context
21+
description: Add any other context or information.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: "\U0001F195 Feature suggestion"
2+
description: Suggest an idea
3+
title: "feat: "
4+
labels: ["enhancement"]
5+
assignees: danielroe
6+
body:
7+
- type: textarea
8+
validations:
9+
required: true
10+
attributes:
11+
label: 🆒 Your use case
12+
description: Add a description of your use case, and how this feature would help you.
13+
placeholder: When I do [...] I would expect to be able to do [...]
14+
- type: textarea
15+
validations:
16+
required: true
17+
attributes:
18+
label: 🆕 The solution you'd like
19+
description: Describe what you want to happen.
20+
- type: textarea
21+
attributes:
22+
label: 🔍 Alternatives you've considered
23+
description: Have you considered any alternative solutions or features?
24+
- type: textarea
25+
attributes:
26+
label: ℹ️ Additional info
27+
description: Is there any other context you think would be helpful to know?
+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: "\U0001F198 Help"
2+
description: I need help with ...
3+
title: "help: "
4+
labels: ["help"]
5+
assignees: danielroe
6+
body:
7+
- type: textarea
8+
validations:
9+
required: true
10+
attributes:
11+
label: 📚 What are you trying to do?
12+
description: A clear and concise description of your objective.
13+
placeholder: I'm not sure how to [...].
14+
- type: textarea
15+
attributes:
16+
label: 🔍 What have you tried?
17+
description: Have you looked through the docs? Tried different approaches? The more detail the better.
18+
- type: textarea
19+
attributes:
20+
label: ℹ️ Additional context
21+
description: Add any other context or information.

.github/workflows/ci.yml

+50
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
name: ci
2+
3+
on:
4+
pull_request:
5+
branches:
6+
- main
7+
push:
8+
branches:
9+
- main
10+
11+
jobs:
12+
lint:
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- uses: actions/checkout@v3
17+
- run: corepack enable
18+
- uses: actions/setup-node@v3
19+
with:
20+
node-version: 16
21+
cache: "pnpm"
22+
23+
- name: 📦 Install dependencies
24+
run: pnpm install --frozen-lockfile
25+
26+
- name: 🔠 Lint project
27+
run: pnpm run lint
28+
29+
test:
30+
runs-on: ubuntu-latest
31+
32+
steps:
33+
- uses: actions/checkout@v3
34+
- run: corepack enable
35+
- uses: actions/setup-node@v3
36+
with:
37+
node-version: 16
38+
cache: "pnpm"
39+
40+
- name: 📦 Install dependencies
41+
run: pnpm install --frozen-lockfile
42+
43+
- name: 🛠 Build project
44+
run: pnpm run build
45+
46+
- name: 🧪 Test project
47+
run: pnpm run test -- --coverage
48+
49+
- name: 🟩 Coverage
50+
uses: codecov/codecov-action@v3

.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
dist
2+
node_modules
3+
coverage

.husky/pre-commit

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#!/bin/sh
2+
. "$(dirname "$0")/_/husky.sh"
3+
4+
pnpm exec lint-staged

CODE_OF_CONDUCT.md

+47
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# Contributor Covenant Code of Conduct
2+
3+
## Our pledge
4+
5+
In the interest of fostering an open and welcoming environment, we as contributors and maintainers pledge to make participation in our project and our community a harassment-free experience for everyone, regardless of age, body size, disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation.
6+
7+
## Our standards
8+
9+
Examples of behavior that contributes to creating a positive environment include:
10+
11+
- Using welcoming and inclusive language
12+
- Being respectful of differing viewpoints and experiences
13+
- Gracefully accepting constructive criticism
14+
- Focusing on what is best for the community
15+
- Showing empathy towards other community members
16+
17+
Examples of unacceptable behavior by participants include:
18+
19+
- The use of sexualized language or imagery and unwelcome sexual attention or advances
20+
- Trolling, insulting/derogatory comments, and personal or political attacks
21+
- Public or private harassment
22+
- Publishing others' private information, such as a physical or electronic address, without explicit permission
23+
- Other conduct which could reasonably be considered inappropriate in a professional setting
24+
25+
## Our responsibilities
26+
27+
Project maintainers are responsible for clarifying the standards of acceptable behavior and are expected to take appropriate and fair corrective action in response to any instances of unacceptable behavior.
28+
29+
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, or to ban temporarily or permanently any contributor for other behaviors that they deem inappropriate, threatening, offensive, or harmful.
30+
31+
## Scope
32+
33+
This Code of Conduct applies within all project spaces, and it also applies when an individual is representing the project or its community in public spaces. Examples of representing a project or community include using an official project e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. Representation of a project may be further defined and clarified by project maintainers.
34+
35+
## Enforcement
36+
37+
Instances of abusive, harassing, or otherwise unacceptable behavior may be reported by contacting the project team at [[email protected]](mailto:[email protected]). All complaints will be reviewed and investigated and will result in a response that is deemed necessary and appropriate to the circumstances. The project team is obligated to maintain confidentiality with regard to the reporter of an incident. Further details of specific enforcement policies may be posted separately.
38+
39+
Project maintainers who do not follow or enforce the Code of Conduct in good faith may face temporary or permanent repercussions as determined by other members of the project's leadership.
40+
41+
## Attribution
42+
43+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html
44+
45+
[homepage]: https://www.contributor-covenant.org
46+
47+
For answers to common questions about this code of conduct, see https://www.contributor-covenant.org/faq

LICENCE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 Daniel Roe
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+116
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
# 🦄 magic-regexp
2+
3+
[![npm version][npm-version-src]][npm-version-href]
4+
[![npm downloads][npm-downloads-src]][npm-downloads-href]
5+
[![Github Actions][github-actions-src]][github-actions-href]
6+
[![Codecov][codecov-src]][codecov-href]
7+
8+
> A compiled-away, type-safe, readable RegExp alternative
9+
10+
- [ Changelog](https://github.com/danielroe/magic-regexp/blob/main/CHANGELOG.md)
11+
- [▶️  Online playground](https://stackblitz.com/github/danielroe/magic-regexp/tree/main/playground)
12+
13+
## Features
14+
15+
**⚠️ `magic-regexp` is currently a work in progress. ⚠️**
16+
17+
- Runtime is zero-dependency and ultra-minimal
18+
- Ships with transform for compiling runtime to pure RegExp
19+
- Supports automatically typed capture groups
20+
- Packed with useful utilities: `charIn`, `charNotIn`, `anyOf`, `char`, `word`, `digit`, `whitespace`, `letter`, `tab`, `linefeed`, `carriageReturn`, `not`, `maybe`, `exactly`
21+
- All chainable with `and`, `or`, `after`, `before`, `notAfter`, `notBefore`, `times`, `as`, `at`
22+
23+
**Future ideas**
24+
25+
- [ ] More TypeScript guard-rails
26+
- [ ] More complex RegExp features/syntax
27+
- [ ] Instrumentation for accurately getting coverage on RegExps
28+
- [ ] Hybrid/partially-compiled RegExps for better dynamic support
29+
30+
## Usage
31+
32+
Install package:
33+
34+
```sh
35+
# npm
36+
npm install magic-regexp
37+
38+
# yarn
39+
yarn add magic-regexp
40+
41+
# pnpm
42+
pnpm install magic-regexp
43+
```
44+
45+
```js
46+
import { createRegExp, exactly } from 'magic-regexp'
47+
48+
const regExp = createRegExp(exactly('foo/test.js').after('bar/'))
49+
console.log(regExp)
50+
51+
// /(?<=bar\/)foo\/test\.js/
52+
```
53+
54+
In order to statically transform magic-regexps at build time, you can use the included unplugin.
55+
56+
**Nuxt**:
57+
58+
```js
59+
import { defineNuxtConfig } from 'nuxt'
60+
61+
// https://v3.nuxtjs.org/api/configuration/nuxt.config
62+
export default defineNuxtConfig({
63+
// This will also enable auto-imports of magic-regexp helpers
64+
modules: ['magic-regexp/nuxt'],
65+
})
66+
```
67+
68+
**Vite**:
69+
70+
```js
71+
import { defineConfig } from 'vite'
72+
import { MagicRegExpTransformPlugin } from 'magic-regexp'
73+
74+
export default defineConfig({
75+
plugins: [MagicRegExpTransformPlugin.vite()],
76+
})
77+
```
78+
79+
**unbuild**:
80+
81+
```js
82+
import { defineBuildConfig } from 'unbuild'
83+
import { MagicRegExpTransformPlugin } from 'magic-regexp'
84+
85+
export default defineBuildConfig({
86+
hooks: {
87+
'rollup:options': (options, config) => {
88+
config.plugins.push(MagicRegExpTransformPlugin.rollup())
89+
},
90+
},
91+
})
92+
```
93+
94+
## 💻 Development
95+
96+
- Clone this repository
97+
- Enable [Corepack](https://github.com/nodejs/corepack) using `corepack enable` (use `npm i -g corepack` for Node.js < 16.10)
98+
- Install dependencies using `pnpm install`
99+
- Run interactive tests using `pnpm dev`
100+
101+
## License
102+
103+
Made with ❤️
104+
105+
Published under [MIT License](./LICENCE).
106+
107+
<!-- Badges -->
108+
109+
[npm-version-src]: https://img.shields.io/npm/v/magic-regexp?style=flat-square
110+
[npm-version-href]: https://npmjs.com/package/magic-regexp
111+
[npm-downloads-src]: https://img.shields.io/npm/dm/magic-regexp?style=flat-square
112+
[npm-downloads-href]: https://npmjs.com/package/magic-regexp
113+
[github-actions-src]: https://img.shields.io/github/workflow/status/unjs/magic-regexp/ci/main?style=flat-square
114+
[github-actions-href]: https://github.com/unjs/magic-regexp/actions?query=workflow%3Aci
115+
[codecov-src]: https://img.shields.io/codecov/c/gh/unjs/magic-regexp/main?style=flat-square
116+
[codecov-href]: https://codecov.io/gh/unjs/magic-regexp

0 commit comments

Comments
 (0)