Skip to content

Commit d5e3b74

Browse files
Merge pull request #6 from abdullahchaudhry/dev_fixes
Dev fixes
2 parents 77c3e56 + cc89c47 commit d5e3b74

File tree

7 files changed

+2788
-7018
lines changed

7 files changed

+2788
-7018
lines changed

.babelrc

Lines changed: 0 additions & 13 deletions
This file was deleted.

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,13 +14,13 @@ npm install -s @coffeeandfun/google-profanity-words
1414

1515
## Usage
1616
```js
17-
import { profanityEngine } from '@coffeeandfun/google-profanity-words';
17+
import { ProfanityEngine } from '@coffeeandfun/google-profanity-words';
1818

19-
let profanity = new profanityEngine();
19+
let profanity = new ProfanityEngine();
2020

21-
await profanity.all(); // returns all bad words as an array.
21+
profanity.all(); // returns all bad words as an array.
2222

23-
await profanity.search('bad word'); // returns true if the word is found in the list.
23+
profanity.search('bad word'); // returns true if the word is found in the list.
2424

2525
```
2626

__tests__/words.test.js

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,28 @@
1-
import { profanityEngine } from '../index.js';
1+
import { ProfanityEngine } from '../index.js';
22

3-
let profanity = new profanityEngine();
3+
let profanity = new ProfanityEngine({
4+
test: true
5+
});
46

57
describe('Profanity tests', () => {
68

7-
it('Get all words in an array', async () => {
8-
const allWords = await profanity.all();
9-
expect(allWords.length).toEqual(453);
9+
it('Should get all the profanity words in an array', () => {
10+
const allWords = profanity.all();
11+
expect(allWords.length).toEqual(451);
1012
});
1113

12-
it('Search for the word Shit in list', async () => {
13-
const searchWord = await profanity.search('shit');
14+
it('Should return true for profanity words', () => {
15+
const searchWord = profanity.search('shit');
1416
expect(searchWord).toEqual(true);
1517
});
1618

17-
it('Search for the word ka in list', async () => {
18-
const searchWord = await profanity.search('ka');
19+
it('Should return false for normal words', () => {
20+
const searchWord = profanity.search('ka');
21+
expect(searchWord).toEqual(false);
22+
});
23+
24+
it('Should return false for any empty string', () => {
25+
const searchWord = profanity.search('');
1926
expect(searchWord).toEqual(false);
2027
});
2128
});

data/list.txt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,6 @@ gangbangs
208208
gaylord
209209
gaysex
210210
goatse
211-
God
212211
god-dam
213212
god-damned
214213
goddamn
@@ -449,4 +448,4 @@ whore
449448
willies
450449
willy
451450
xrated
452-
xxx
451+
xxx

index.js

Lines changed: 15 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,24 @@
11
import fs from 'fs';
22

33

4-
export class profanityEngine {
5-
constructor() {
6-
7-
this.terms = fs.readFileSync('data/list.txt', 'utf8').split('\n');
8-
4+
export class ProfanityEngine {
5+
constructor(config) {
6+
let path;
7+
if (config && config.test) {
8+
path = 'data/list.txt'
9+
} else {
10+
path = './node_modules/@coffeeandfun/google-profanity-words/data/list.txt';
11+
}
12+
13+
this.terms = fs.readFileSync(`${path}`, 'utf8').split('\n');
914
}
1015

11-
async all() {
12-
return new Promise(async (resolve, reject) => {
13-
resolve(this.terms); // this.terms;
14-
});
16+
all() {
17+
return this.terms
1518
}
1619

17-
async search(term) {
18-
19-
return new Promise(async (resolve, reject) => {
20-
let result = this.terms.indexOf(term);
21-
if (result > -1) {
22-
resolve(true);
23-
} else {
24-
resolve(false);
25-
}
26-
});
27-
28-
20+
search(term) {
21+
let result = this.terms.indexOf(term);
22+
return result > -1 ? true : false
2923
}
30-
3124
}

0 commit comments

Comments
 (0)