Skip to content

Commit

Permalink
Merge pull request #6 from abdullahchaudhry/dev_fixes
Browse files Browse the repository at this point in the history
Dev fixes
  • Loading branch information
RobertJGabriel authored Dec 31, 2021
2 parents 77c3e56 + cc89c47 commit d5e3b74
Show file tree
Hide file tree
Showing 7 changed files with 2,788 additions and 7,018 deletions.
13 changes: 0 additions & 13 deletions .babelrc

This file was deleted.

8 changes: 4 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ npm install -s @coffeeandfun/google-profanity-words

## Usage
```js
import { profanityEngine } from '@coffeeandfun/google-profanity-words';
import { ProfanityEngine } from '@coffeeandfun/google-profanity-words';

let profanity = new profanityEngine();
let profanity = new ProfanityEngine();

await profanity.all(); // returns all bad words as an array.
profanity.all(); // returns all bad words as an array.

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

```

Expand Down
25 changes: 16 additions & 9 deletions __tests__/words.test.js
Original file line number Diff line number Diff line change
@@ -1,21 +1,28 @@
import { profanityEngine } from '../index.js';
import { ProfanityEngine } from '../index.js';

let profanity = new profanityEngine();
let profanity = new ProfanityEngine({
test: true
});

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

it('Get all words in an array', async () => {
const allWords = await profanity.all();
expect(allWords.length).toEqual(453);
it('Should get all the profanity words in an array', () => {
const allWords = profanity.all();
expect(allWords.length).toEqual(451);
});

it('Search for the word Shit in list', async () => {
const searchWord = await profanity.search('shit');
it('Should return true for profanity words', () => {
const searchWord = profanity.search('shit');
expect(searchWord).toEqual(true);
});

it('Search for the word ka in list', async () => {
const searchWord = await profanity.search('ka');
it('Should return false for normal words', () => {
const searchWord = profanity.search('ka');
expect(searchWord).toEqual(false);
});

it('Should return false for any empty string', () => {
const searchWord = profanity.search('');
expect(searchWord).toEqual(false);
});
});
3 changes: 1 addition & 2 deletions data/list.txt
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,6 @@ gangbangs
gaylord
gaysex
goatse
God
god-dam
god-damned
goddamn
Expand Down Expand Up @@ -449,4 +448,4 @@ whore
willies
willy
xrated
xxx
xxx
37 changes: 15 additions & 22 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,31 +1,24 @@
import fs from 'fs';


export class profanityEngine {
constructor() {

this.terms = fs.readFileSync('data/list.txt', 'utf8').split('\n');

export class ProfanityEngine {
constructor(config) {
let path;
if (config && config.test) {
path = 'data/list.txt'
} else {
path = './node_modules/@coffeeandfun/google-profanity-words/data/list.txt';
}

this.terms = fs.readFileSync(`${path}`, 'utf8').split('\n');
}

async all() {
return new Promise(async (resolve, reject) => {
resolve(this.terms); // this.terms;
});
all() {
return this.terms
}

async search(term) {

return new Promise(async (resolve, reject) => {
let result = this.terms.indexOf(term);
if (result > -1) {
resolve(true);
} else {
resolve(false);
}
});


search(term) {
let result = this.terms.indexOf(term);
return result > -1 ? true : false
}

}
Loading

0 comments on commit d5e3b74

Please sign in to comment.