Skip to content

Commit 3fd9c86

Browse files
Added formatter to release
1 parent 25a023e commit 3fd9c86

File tree

8 files changed

+78
-68
lines changed

8 files changed

+78
-68
lines changed

.github/workflows/npm-publish.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ jobs:
1616
with:
1717
node-version: 16
1818
- run: npm ci
19+
- run: npm run format
1920
- run: npm test
2021

2122
publish-npm:

.prettierrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,9 @@
1-
{}
1+
{
2+
"singleQuote": true,
3+
"trailingComma": "es5",
4+
"tabWidth": 2,
5+
"semi": true,
6+
"printWidth": 80,
7+
"arrowParens": "always",
8+
"endOfLine": "auto"
9+
}

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
![alt text](.github/readme.png "Logo Title Text 1")
1+
![alt text](.github/readme.png 'Logo Title Text 1')
22

33
## Description
44

@@ -19,11 +19,11 @@ npm install @coffeeandfun/google-profanity-words
1919
To use the `@coffeeandfun/google-profanity-words`, first, import the module and create an instance:
2020

2121
```javascript
22-
import { ProfanityEngine } from "@coffeeandfun/google-profanity-words";
22+
import { ProfanityEngine } from '@coffeeandfun/google-profanity-words';
2323

2424
// Pass the 'language' parameter to specify the language (optional).
2525
// Defaults to 'en' if no valid language code is provided.
26-
const profanity = new ProfanityEngine({ language: "es" });
26+
const profanity = new ProfanityEngine({ language: 'es' });
2727
```
2828

2929
The language parameter is optional and can be used to specify the language for the profanity list. It defaults to 'en' if no valid language code is provided. If the specified language file is not found, it will fall back to the 'en' language file and display a console warning.
@@ -43,7 +43,7 @@ const allWords = profanity.all();
4343
Checks if a given word is considered profane.
4444

4545
```javascript
46-
const searchWord = profanity.search("shit");
46+
const searchWord = profanity.search('shit');
4747
// Returns true if the word is profane, otherwise false.
4848
```
4949

@@ -52,7 +52,7 @@ const searchWord = profanity.search("shit");
5252
Checks if a given sentence contains any profanity words.
5353

5454
```javascript
55-
const sentence = "Do not use bad words like mierda or idiota.";
55+
const sentence = 'Do not use bad words like mierda or idiota.';
5656
const hasCurseWords = profanity.hasCurseWords(sentence);
5757
// Returns true if the sentence contains profanity words, otherwise false.
5858
```
@@ -62,8 +62,8 @@ const hasCurseWords = profanity.hasCurseWords(sentence);
6262
The `search` and `hasCurseWords` functions will return false for any empty string.
6363

6464
```javascript
65-
const searchWord = profanity.search("");
66-
const hasCurseWords = profanity.hasCurseWords("");
65+
const searchWord = profanity.search('');
66+
const hasCurseWords = profanity.hasCurseWords('');
6767
// Returns false for an empty string.
6868
```
6969

__tests__/engine.test.js

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,47 +1,47 @@
1-
import { ProfanityEngine } from "../index.js";
1+
import { ProfanityEngine } from '../index.js';
22

3-
const language = process.env.LANGUAGE || "en"; // Default to 'en' if the LANGUAGE environment variable is not set
3+
const language = process.env.LANGUAGE || 'en'; // Default to 'en' if the LANGUAGE environment variable is not set
44
let profanity;
55

6-
describe("ProfanityEngine Functions tests", () => {
6+
describe('ProfanityEngine Functions tests', () => {
77
beforeAll(async () => {
88
profanity = new ProfanityEngine({
9-
language: "en",
9+
language: 'en',
1010
testMode: true,
1111
});
1212
await profanity.initialize(); // Initialize the profanity instance with the English language
1313
});
1414

15-
it("Should get the correct language file path", async () => {
16-
const filePath = await profanity.getLanguageFilePath("es");
17-
expect(filePath).toContain("es.txt");
15+
it('Should get the correct language file path', async () => {
16+
const filePath = await profanity.getLanguageFilePath('es');
17+
expect(filePath).toContain('es.txt');
1818
});
1919

20-
it("Should return the default language file path for unknown language", async () => {
21-
const filePath = await profanity.getLanguageFilePath("fr");
22-
expect(filePath).toContain("en.txt");
20+
it('Should return the default language file path for unknown language', async () => {
21+
const filePath = await profanity.getLanguageFilePath('fr');
22+
expect(filePath).toContain('en.txt');
2323
});
2424

25-
it("Should check if a file exists and return true", async () => {
26-
const filePath = await profanity.getLanguageFilePath("en");
25+
it('Should check if a file exists and return true', async () => {
26+
const filePath = await profanity.getLanguageFilePath('en');
2727
const fileExists = await profanity.fileExists(filePath);
2828
expect(fileExists).toEqual(true);
2929
});
3030

31-
it("Should check if a file exists and return false", async () => {
32-
const filePath = "nonexistent.txt"; // Assume the file doesn't exist
31+
it('Should check if a file exists and return false', async () => {
32+
const filePath = 'nonexistent.txt'; // Assume the file doesn't exist
3333
const fileExists = await profanity.fileExists(filePath);
3434
expect(fileExists).toEqual(false);
3535
});
3636

37-
it("Should read and split the file content correctly", async () => {
38-
const filePath = await profanity.getLanguageFilePath("en");
37+
it('Should read and split the file content correctly', async () => {
38+
const filePath = await profanity.getLanguageFilePath('en');
3939
const terms = await profanity.readFileAndSplit(filePath);
4040
expect(terms.length).toBeGreaterThan(0);
4141
});
4242

43-
it("Should handle read error and set terms to the english terms", async () => {
44-
const filePath = "nonexistent.txt"; // Assume the file doesn't exist
43+
it('Should handle read error and set terms to the english terms', async () => {
44+
const filePath = 'nonexistent.txt'; // Assume the file doesn't exist
4545
await profanity.readFileAndSplit(filePath);
4646
let terms = await profanity.all();
4747
expect(terms.length).toEqual(959);

__tests__/english.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,45 @@
1-
import { ProfanityEngine } from "../index.js";
1+
import { ProfanityEngine } from '../index.js';
22

3-
const language = process.env.LANGUAGE || "en"; // Default to 'en' if the LANGUAGE environment variable is not set
3+
const language = process.env.LANGUAGE || 'en'; // Default to 'en' if the LANGUAGE environment variable is not set
44
let profanity;
55

6-
describe("English Profanity tests", () => {
6+
describe('English Profanity tests', () => {
77
beforeAll(async () => {
88
profanity = new ProfanityEngine({
9-
language: "en",
9+
language: 'en',
1010
testMode: true,
1111
});
1212
await profanity.initialize(); // Initialize the profanity instance with the English language
1313
});
1414

15-
it("Should get all the profanity words in an array", async () => {
15+
it('Should get all the profanity words in an array', async () => {
1616
const allWords = await profanity.all();
1717
expect(allWords.length).toEqual(959);
1818
});
1919

20-
it("Should return true for profanity words", async () => {
21-
const searchWord = await profanity.search("shit");
20+
it('Should return true for profanity words', async () => {
21+
const searchWord = await profanity.search('shit');
2222
expect(searchWord).toEqual(true);
2323
});
2424

25-
it("Should return false for normal words", async () => {
26-
const searchWord = await profanity.search("ka");
25+
it('Should return false for normal words', async () => {
26+
const searchWord = await profanity.search('ka');
2727
expect(searchWord).toEqual(false);
2828
});
2929

30-
it("Should return false for any empty string", async () => {
31-
const searchWord = await profanity.search("");
30+
it('Should return false for any empty string', async () => {
31+
const searchWord = await profanity.search('');
3232
expect(searchWord).toEqual(true);
3333
});
3434

35-
it("Should return true for a sentence containing a profanity word", async () => {
36-
const sentence = "Do not use bad words like shit or asshole.";
35+
it('Should return true for a sentence containing a profanity word', async () => {
36+
const sentence = 'Do not use bad words like shit or asshole.';
3737
const hasCurseWords = await profanity.hasCurseWords(sentence);
3838
expect(hasCurseWords).toEqual(true);
3939
});
4040

41-
it("Should return false for a sentence with no profanity word", async () => {
42-
const sentence = "This is a clean and polite sentence.";
41+
it('Should return false for a sentence with no profanity word', async () => {
42+
const sentence = 'This is a clean and polite sentence.';
4343
const hasCurseWords = await profanity.hasCurseWords(sentence);
4444
expect(hasCurseWords).toEqual(false);
4545
});

__tests__/spanish.test.js

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,44 @@
1-
import { ProfanityEngine } from "../index.js";
1+
import { ProfanityEngine } from '../index.js';
22

3-
const language = process.env.LANGUAGE || "en"; // Default to 'en' if the LANGUAGE environment variable is not set
3+
const language = process.env.LANGUAGE || 'en'; // Default to 'en' if the LANGUAGE environment variable is not set
44
let profanity;
55

6-
describe("Spanish Profanity tests", () => {
6+
describe('Spanish Profanity tests', () => {
77
beforeAll(async () => {
88
profanity = new ProfanityEngine({
9-
language: "es",
9+
language: 'es',
1010
testMode: true,
1111
});
1212
await profanity.initialize(); // Initialize the profanity instance with the English language
1313
});
14-
it("Should get all the profanity words in an array", async () => {
14+
it('Should get all the profanity words in an array', async () => {
1515
const allWords = await profanity.all();
1616
expect(allWords.length).toEqual(565);
1717
});
1818

19-
it("Should return true for profanity words", async () => {
20-
const searchWord = await profanity.search("labios");
19+
it('Should return true for profanity words', async () => {
20+
const searchWord = await profanity.search('labios');
2121
expect(searchWord).toEqual(true);
2222
});
2323

24-
it("Should return false for normal words", async () => {
25-
const searchWord = await profanity.search("ka");
24+
it('Should return false for normal words', async () => {
25+
const searchWord = await profanity.search('ka');
2626
expect(searchWord).toEqual(false);
2727
});
2828

29-
it("Should return false for any empty string", async () => {
30-
const searchWord = await profanity.search("");
29+
it('Should return false for any empty string', async () => {
30+
const searchWord = await profanity.search('');
3131
expect(searchWord).toEqual(true);
3232
});
3333

34-
it("Should return true for a sentence containing a profanity word", async () => {
35-
const sentence = "No deberías decir malas culo palabras como mierda.";
34+
it('Should return true for a sentence containing a profanity word', async () => {
35+
const sentence = 'No deberías decir malas culo palabras como mierda.';
3636
const hasCurseWords = await profanity.hasCurseWords(sentence);
3737
expect(hasCurseWords).toEqual(true);
3838
});
3939

40-
it("Should return false for a sentence with no profanity word", async () => {
41-
const sentence = "Esta es una oración limpia y educada.";
40+
it('Should return false for a sentence with no profanity word', async () => {
41+
const sentence = 'Esta es una oración limpia y educada.';
4242
const hasCurseWords = await profanity.hasCurseWords(sentence);
4343
expect(hasCurseWords).toEqual(false);
4444
});

index.js

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
import { readFile } from "fs/promises";
2-
import path from "path";
3-
import { fileURLToPath } from "url";
1+
import { readFile } from 'fs/promises';
2+
import path from 'path';
3+
import { fileURLToPath } from 'url';
44

55
export class ProfanityEngine {
66
constructor(config) {
77
this.isTestMode = config && config.testMode ? config.testMode : false;
8-
this.language = config && config.language ? config.language : "en";
8+
this.language = config && config.language ? config.language : 'en';
99
this.terms = [];
10-
this.filePath = "";
10+
this.filePath = '';
1111
}
1212

1313
async initialize() {
@@ -18,24 +18,24 @@ export class ProfanityEngine {
1818
} catch (err) {
1919
if (this.isTestMode === false) {
2020
let message = `Error reading file: ${err.message}`;
21-
console.warn("Profanity words issue:", message);
21+
console.warn('Profanity words issue:', message);
2222
}
2323
this.terms = [];
2424
}
2525
}
2626

2727
async getLanguageFilePath(language) {
2828
const currentFilePath = fileURLToPath(import.meta.url);
29-
const dataFolderPath = path.join(path.dirname(currentFilePath), "data");
29+
const dataFolderPath = path.join(path.dirname(currentFilePath), 'data');
3030
const languageFilePath = path.join(dataFolderPath, `${language}.txt`);
3131
const fileExists = await this.fileExists(languageFilePath);
3232

3333
if (!fileExists) {
3434
if (this.isTestMode === false) {
3535
let message = `Warning: The ${language} language file could not be found. Defaulting to 'en' language.`;
36-
console.warn("Profanity words issue:", message);
36+
console.warn('Profanity words issue:', message);
3737
}
38-
return path.join(dataFolderPath, "en.txt");
38+
return path.join(dataFolderPath, 'en.txt');
3939
}
4040

4141
return languageFilePath;
@@ -52,11 +52,11 @@ export class ProfanityEngine {
5252

5353
async readFileAndSplit(filePath) {
5454
try {
55-
const fileContent = await readFile(filePath, "utf8");
56-
return fileContent.split("\n");
55+
const fileContent = await readFile(filePath, 'utf8');
56+
return fileContent.split('\n');
5757
} catch (err) {
5858
if (this.isTestMode === false) {
59-
console.warn("Profanity words issue:", err);
59+
console.warn('Profanity words issue:', err);
6060
}
6161
return [];
6262
}

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
"main": "index.js",
66
"type": "module",
77
"scripts": {
8+
"format": "npx prettier . --write",
89
"test": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest",
910
"en": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest english.test.js",
1011
"es": "NODE_OPTIONS=--experimental-vm-modules NODE_NO_WARNINGS=1 jest spanish.test.js",

0 commit comments

Comments
 (0)