Skip to content

Commit 5445b6e

Browse files
authored
Merge pull request #72 from 2Toad/jp-issue-71
Add benchmarking
2 parents 8dc9bc4 + 8899377 commit 5445b6e

8 files changed

Lines changed: 233 additions & 32 deletions

File tree

README.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66

77
A JavaScript profanity filter (with TypeScript support)
88

9-
## Getting Started 🚀
9+
## Getting Started
1010

1111
Install the package
1212

1313
```Shell
1414
npm i @2toad/profanity
1515
```
1616

17-
>If you're using Node 11.x or older, you'll need to install [Profanity 1.x](https://github.com/2Toad/Profanity/releases) (e.g., `npm i @2toad/profanity@1.4.1`)
17+
>If you're using Node 11.x or older, you'll need to install [Profanity 1.x](https://github.com/2Toad/Profanity/releases)
1818
19-
## Usage 📚
19+
## Usage
2020

2121
```JavaScript
2222
import { profanity, CensorType } from '@2toad/profanity';
@@ -38,7 +38,7 @@ profanity.censor('I like big butts (aka arses) and I cannot lie', CensorType.Fir
3838
// I like big *utts (aka *rses) and I cannot lie
3939
```
4040

41-
## Options ⚙️
41+
## Options
4242
Create an instance of the Profanity class to change the default options:
4343

4444
```JavaScript
@@ -51,7 +51,7 @@ const profanity = new Profanity({
5151
});
5252
```
5353

54-
### wholeWord 🔤
54+
### wholeWord
5555

5656
By default, this is set to `true` so profanity only matches on whole words:
5757
```JavaScript
@@ -82,7 +82,7 @@ profanity.exists("Don't be an arsenic-monster");
8282
// true (matched on arse)
8383
```
8484

85-
### grawlix 💥
85+
### grawlix
8686

8787
By default this is set to `@#$%&!`:
8888
```JavaScript
@@ -96,7 +96,7 @@ profanity.censor('I like big butts and I cannot lie');
9696
// I like big **** and I cannot lie
9797
```
9898

99-
### grawlixChar 💲
99+
### grawlixChar
100100

101101
When specifying a `CensorType` other than `CensorType.Word`, this is the character used by the `censor` function.
102102

@@ -113,7 +113,7 @@ profanity.censor('I like big butts and I cannot lie', CensorType.AllVowels);
113113
```
114114

115115

116-
## Customize the word list 📝
116+
## Customize the word list
117117

118118
Add words:
119119
```JavaScript
@@ -125,7 +125,7 @@ Remove words:
125125
profanity.removeWords(['butt', 'arse']);
126126
```
127127

128-
## Whitelist
128+
## Whitelist
129129
The whitelist allows you to specify words that are always ignored by the profanity filter.
130130

131131
>This can be useful if you want to enable partial word matching (`wholeWord = false`), so combined words are caught (e.g., arselicker), while specific words you add to the whitelist are ignored (e.g., arsenic).
@@ -140,6 +140,10 @@ Remove words from the whitelist:
140140
profanity.whitelist.removeWords(['arsenic', 'buttress']);
141141
```
142142

143+
## Benchmarking ⏱️
144+
145+
To see how Profanity performs, check out our [benchmark results](./src/benchmark/results.md).
146+
143147
## Contributing 🤝
144148

145149
So you want to contribute to the Profanity project? Fantastic! Please read the [Contribute](./contribute.md) doc to get started.

contribute.md

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
Thank you for wanting to contribute to the Profanity project. With your contributions we can ensure Profanity remains a leading solution for filtering profanity within JavaScript projects
44

5-
## Steps for success
5+
## Steps for success
66

77
1. [Issues](https://github.com/2Toad/Profanity/issues):
88
1. Always work off of an Issue. Please do not submit a Pull Request that is not associated with an Issue (create the Issue if necessary).
@@ -19,35 +19,35 @@ Thank you for wanting to contribute to the Profanity project. With your contribu
1919
2. Make sure your PR is targeting the correct branch (see Step 2.ii)
2020
3. At the top of your PR description write: "Fixes #_n_". Where _n_ is the number of the Issue your PR is fixing (e.g., `Fixes #33`). This will tell GitHub to associate your PR with the Issue.
2121

22-
## Development 💻
22+
## Development
2323

24-
### Prerequisites 📝
24+
### Prerequisites
2525

2626
- `master` branch: [Node 20+](https://nodejs.org)
2727
- `1.x.x` branch: [Node 10.23.0](https://nodejs.org)
2828

29-
### Source Code 🔠
29+
### Source Code
3030

3131
1. Clone the repo
3232
2. Change directories: `cd Profanity`
3333
3. Install dependencies: `npm i`
3434

35-
### Workflow 🔁
35+
### Workflow
3636

3737
Start app in watch mode: `npm run local`
3838

3939
> When file changes are detected, the app will automatically rebuild/restart
4040
41-
#### Linting 🧹
41+
#### Linting
4242

4343
- Check lint rules: `npm run lint`
4444
- Fix lint errors: `npm run lint:fix`
4545
- Check formatting rules: `npm run prettier`
4646
- Fix formatting errors: `npm run prettier:fix`
4747

48-
## Appendix 📚
48+
## Appendix
4949

50-
### Dev Tools 🛠️
50+
### Dev Tools
5151

5252
The following section includes optional dev tools that enhance the Profanity development experience, but are not necessary.
5353

@@ -67,38 +67,41 @@ The Profanity project includes an .nvmrc file, so you can run `nvm use` to switc
6767

6868
The Profanity project includes Husky for running Git Hooks. Running `git commit` will trigger `lint-staged` which will lint all files currently staged in Git. If linting fails, the commit will be cancelled
6969

70-
### Dependencies 📦
70+
### Dependencies
7171

7272
- `chai`: we must use v4.x because v5.x is pure ESM, and we require CommonJS modules
7373

74-
### Deployments 🚀
74+
### Deployment
7575

76-
Deployments to Prod consist of building and publishing the Profanity lib to NPM, and are automated through our Continous Deployment workflow.
76+
Deploying to Prod consist of building and publishing the Profanity lib to NPM, and are automated through our Continuous Deployment workflow.
7777

78-
#### 1. Change Version
79-
1. Checkout `master`
80-
2. Increment version (semantic) in package.json (e.g., 1.1.0)
81-
3. Rebuild package-lock (to pick up new version ): `npm i --package-lock-only`
82-
4. Push changes:
78+
#### 1. Create New Version
79+
1. Checkout `master`.
80+
2. Increment the version in package.json, using semantic versioning (e.g., `1.1.0`).
81+
3. Perform benchmarking:
82+
1. Run the script: `npm run benchmark`.
83+
2. Record the results in [benchmark/results.md](./src/benchmark/results.md), for the new version.
84+
4. Rebuild package-lock, to pick up the new version number: `npm i --package-lock-only`.
85+
5. Push changes:
8386
```
8487
git add .
85-
git commmit -m "Bump version to 1.1.0"
88+
git commit -m "Bump version to 1.1.0"
8689
git push
8790
```
8891

8992
#### 2. Verify Checks
90-
1. Navigate to the [CI](https://github.com/2Toad/Profanity/actions/workflows/ci.yml) workflow
91-
2. Ensure the run for the above "Bump version" commit succeeds
93+
1. Navigate to the [CI](https://github.com/2Toad/Profanity/actions/workflows/ci.yml) workflow.
94+
2. Ensure the build checks for this push succeed.
9295

9396
#### 3. Publish GitHub Release
94-
1. Navigate to [Profanity's releases](https://github.com/2Toad/Profanity/releases)
95-
2. Click "Draft a new release"
97+
1. Navigate to [Profanity's releases](https://github.com/2Toad/Profanity/releases).
98+
2. Click "Draft a new release":
9699
- **Choose a tag**: enter version (e.g., `v1.1.0`) and click "Create new tag"
97100
- **Target**: `master`
98101
- **Previous tag**: `auto`
99102
- **Release title**: (e.g., `1.1.0`)
100-
- **Description**: click the "Genereate release notes"
103+
- **Description**: click the "Generate release notes"
101104
- [x] **Set as the latest release**
102-
3. Click "Publish release"
105+
3. Click "Publish release".
103106

104107
> This will trigger the [CDP](https://github.com/2Toad/Profanity/actions/workflows/cdp.yml) workflow, which will build and deploy the package to NPM: https://www.npmjs.com/package/@2toad/profanity

package-lock.json

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
"pretest": "npm run build",
1818
"test": "mocha -r ts-node/register tests/**/*.spec.ts",
1919
"test:watch": "npm run test -- --watch",
20+
"benchmark": "ts-node src/benchmark/benchmark.ts",
2021
"lint": "eslint . --cache",
2122
"lint:fix": "eslint . --cache --fix",
2223
"prettier": "prettier --check **/*.ts",
@@ -50,11 +51,13 @@
5051
"filter"
5152
],
5253
"devDependencies": {
54+
"@types/benchmark": "^2.1.5",
5355
"@types/chai": "^4.3.19",
5456
"@types/mocha": "^10.0.7",
5557
"@types/node": "^22.5.2",
5658
"@typescript-eslint/eslint-plugin": "^8.3.0",
5759
"@typescript-eslint/parser": "^8.3.0",
60+
"benchmark": "^2.1.4",
5861
"chai": "^4.5.0",
5962
"concurrently": "^8.2.2",
6063
"eslint": "^8.57.0",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
export interface VersionData {
2+
version: number;
3+
smallCleanText: string;
4+
smallProfaneText: string;
5+
largeCleanText: string;
6+
largeProfaneText: string;
7+
}
8+
9+
export interface TestData {
10+
comment1: string;
11+
comment2: string;
12+
versions: VersionData[];
13+
}

0 commit comments

Comments
 (0)