-
-
Notifications
You must be signed in to change notification settings - Fork 249
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from abdullahchaudhry/dev_fixes
Dev fixes
- Loading branch information
Showing
7 changed files
with
2,788 additions
and
7,018 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
|
||
} |
Oops, something went wrong.