Skip to content

Commit 32bb5c9

Browse files
committed
feat: first commit 🎉
1 parent 2574833 commit 32bb5c9

File tree

13 files changed

+9674
-2
lines changed

13 files changed

+9674
-2
lines changed

.github/SPONSORS.yml

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# These are supported funding model platforms
2+
3+
github: mesqueeb
4+
patreon: # Replace with a single Patreon username
5+
open_collective: # Replace with a single Open Collective username
6+
ko_fi: # Replace with a single Ko-fi username
7+
tidelift: # Replace with a single Tidelift platform-name/package-name e.g., npm/babel
8+
community_bridge: # Replace with a single Community Bridge project-name e.g., cloud-foundry
9+
liberapay: # Replace with a single Liberapay username
10+
issuehunt: # Replace with a single IssueHunt username
11+
otechie: # Replace with a single Otechie username
12+
custom: # Replace with up to 4 custom sponsorship URLs e.g., ['link1', 'link2']

.github/workflows/test.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Test
2+
on:
3+
push:
4+
branches: main
5+
paths:
6+
- src/**
7+
- test/**
8+
- '*.js'
9+
- '*.ts'
10+
- '*.json'
11+
- .github/workflows/test.yml
12+
pull_request:
13+
branches: main
14+
paths:
15+
- src/**
16+
- test/**
17+
- '*.js'
18+
- '*.ts'
19+
- '*.json'
20+
- .github/workflows/test.yml
21+
concurrency:
22+
group: test-${{ github.ref }}
23+
cancel-in-progress: true
24+
jobs:
25+
test:
26+
strategy:
27+
matrix:
28+
node-version: ['18', '20']
29+
runs-on: ubuntu-latest
30+
steps:
31+
- uses: actions/checkout@v4
32+
- uses: actions/setup-node@v4
33+
with:
34+
node-version: ${{ matrix.node-version }}
35+
cache: npm
36+
- run: npm ci
37+
- run: npm test

.prettierrc.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import prettier from "@cycraft/eslint/prettier"
2+
3+
export default prettier

.vscode/settings.json

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"editor.formatOnSave": true,
3+
"editor.defaultFormatter": "esbenp.prettier-vscode",
4+
"editor.tabSize": 2,
5+
"editor.insertSpaces": true,
6+
"files.insertFinalNewline": true,
7+
"files.trimFinalNewlines": true,
8+
"files.trimTrailingWhitespace": true,
9+
"javascript.preferences.importModuleSpecifierEnding": "js",
10+
"typescript.preferences.importModuleSpecifierEnding": "js"
11+
}

README.md

Lines changed: 87 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,87 @@
1-
# replace-regex
2-
📂 TS compatible modern nodeJS find-and-replace in files with Regex & Glob support
1+
# replace-regex 📂
2+
3+
<a href="https://www.npmjs.com/package/replace-regex"><img src="https://img.shields.io/npm/v/replace-regex.svg" alt="Total Downloads"></a>
4+
<a href="https://www.npmjs.com/package/replace-regex"><img src="https://img.shields.io/npm/dw/replace-regex.svg" alt="Latest Stable Version"></a>
5+
6+
📂 TS compatible modern nodeJS find-and-replace in files with Regex & Glob support.
7+
8+
```
9+
npm i replace-regex
10+
```
11+
12+
## Features
13+
14+
- **Glob Support**: Use glob patterns to specify files.
15+
- **Regex Support**: Replace text using regular expressions.
16+
- **Dry Run**: Preview changes without modifying files.
17+
- **Counts**: Count matches and replacements.
18+
- **Customizable**: Pass custom options to fine-tune behavior.
19+
20+
## Usage
21+
22+
### Basic Usage
23+
24+
```ts
25+
import { replaceRegex } from 'replace-regex'
26+
27+
const results = await replaceRegex({
28+
files: 'src/**/*.js',
29+
from: /foo/g,
30+
to: 'bar',
31+
dry: false,
32+
countMatches: true,
33+
})
34+
35+
console.log(results)
36+
```
37+
38+
### Options
39+
40+
- `files` (string or string[]): Glob patterns or file paths to process.
41+
- `from` (string | RegExp | (file: string) => string | RegExp): The pattern to search for.
42+
- `to` (string | (match: string, file: string) => string): The replacement string or function.
43+
- `dry` (boolean, optional): If true, no files will be overwritten. Default is `false`.
44+
- `ignore` (string[], optional): An array of glob patterns to exclude matches.
45+
- `disableGlobs` (boolean, optional): If true, disables glob pattern matching. Default is `false`.
46+
- `fastGlobOptions` (object, optional): Options to pass to fast-glob.
47+
- `countMatches` (boolean, optional): If true, counts the number of matches and replacements. Default is `false`.
48+
49+
### Examples
50+
51+
**Replace text in JavaScript files**
52+
53+
```ts
54+
replaceRegex({
55+
files: 'src/**/*.js',
56+
from: /console\.log/g,
57+
to: 'logger.log',
58+
dry: false,
59+
countMatches: true,
60+
})
61+
```
62+
63+
**Dry Run**
64+
65+
```ts
66+
const result = await replaceRegex({
67+
files: 'src/**/*.js',
68+
from: /foo/g,
69+
to: 'bar',
70+
dry: true, // No files will be overwritten
71+
countMatches: true,
72+
})
73+
74+
console.log(`result → `, result)
75+
```
76+
77+
**Custom Replacement Function**
78+
79+
```ts
80+
replaceRegex({
81+
files: 'src/**/*.js',
82+
from: /foo/g,
83+
to: (match, file) => `${match.toUpperCase()} in ${file}`,
84+
dry: false,
85+
countMatches: true,
86+
})
87+
```

eslint.config.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import config from '@cycraft/eslint/config'
2+
3+
export default config

0 commit comments

Comments
 (0)