Security Words Picker

Security Words Picker is a fun and easy tool that helps you pick words from a big list of over 20,000+ words. Whether you're making games, creating secure passwords, or just having fun with words, this package has got you covered!
Table of Contents
Features
Security Words Picker is packed with cool features to make picking words super easy and fun:
-
Pick Words by Length
- What it does: Choose words that are not too short or too long.
- Example: Pick words that are at least 5 letters and no more than 10 letters.
- How to use:
const options = {
lengthMin: 5,
lengthMax: 10
};
const words = getWords(options, 10, wordsArray);
console.log(words);
-
Pick Random Words
-
Start or End With Specific Letters
- What it does: Choose words that start or end with certain letters.
- Example: Pick words that start with "a" or end with "ing".
- How to use:
const options = {
filterStartsWith: ["a"],
filterEndsWith: ["ing"]
};
const words = getWords(options, 6, wordsArray);
console.log(words);
-
Exclude Certain Words
- What it does: Avoid words that have specific letters or patterns.
- Example: Exclude words that contain "ion" or "xyz".
- How to use:
const options = {
excludeSubstrings: ["ion", "xyz"]
};
const words = getWords(options, 5, wordsArray);
console.log(words);
-
Change the Case of Words
- What it does: Make all words uppercase, lowercase, or capitalize the first letter.
- Example: Change words to uppercase and sort them in descending order.
- How to use:
const options = {
sort: "desc",
caseOption: "upper"
};
const words = getWords(options, 5, wordsArray);
console.log(words);
-
Return Words as a Sentence
-
Ensure Words Sound Different
-
Whitelist and Blacklist Words
- What it does: Only include certain words (whitelist) or exclude specific words (blacklist).
- Example: Only pick from a list of approved words.
- How to use:
const options = {
whitelist: ["apple", "banana", "cherry"]
};
const words = getWords(options, 2, wordsArray);
console.log(words);
-
Keep Track of Picked Words
-
Include Extra Information
Installation
Install Security Words Picker using npm:
npm install security-words-picker
Quick Start
Get started quickly by following the examples below!
Example 1: Pick 5 Random Words
Retrieve five random words without any filters.
const { getWords } = require('security-words-picker');
const wordsArray = require('./words');
const result = getWords({}, 5, wordsArray);
console.log(result);
Example 2: Pick Words of a Certain Length
Retrieve words that are at least 5 letters and no more than 10 letters long.
const options = {
lengthMin: 5,
lengthMax: 10
};
const result = getWords(options, 10, wordsArray);
console.log(result);
Example 3: Pick Words That Start or End With Specific Letters
Retrieve 6 words that start with "a" or end with "ing".
const options = {
filterStartsWith: ["a"],
filterEndsWith: ["ing"]
};
const result = getWords(options, 6, wordsArray);
console.log(result);
Example 4: Get Words as a Sentence
Retrieve 3 words as a comma-separated string.
const options = {
asString: true
};
const result = getWords(options, 3, wordsArray);
console.log(result);
Example 5: Sort Words and Change Their Case
Retrieve words sorted in descending order and make them all uppercase.
const options = {
sort: "desc",
caseOption: "upper"
};
const result = getWords(options, 5, wordsArray);
console.log(result);
API Reference
getWords(options, amountOfWords, wordsArray)
Pick a number of words from your big list with some fun rules!
Parameters
-
options
Object
Special rules to pick words. See Options for more details.
-
amountOfWords
number
How many words you want to pick. Must be a positive number.
-
wordsArray
Array
Your big list of words (over 20,000+ words) to pick from.
Returns
Array|string
An array of words or a single string with words separated by commas.
Example Usage
const options = {
lengthMin: 5,
excludeAmbiguous: true,
sort: "asc",
caseOption: "capitalize"
};
const selectedWords = getWords(options, 10, wordsArray);
console.log(selectedWords);
Options
Customize how words are picked by setting these options:
-
lengthMin
(number)
The smallest number of letters a word can have.
Example: { lengthMin: 5 }
picks words with at least 5 letters.
-
lengthMax
(number)
The biggest number of letters a word can have.
Example: { lengthMax: 10 }
picks words with no more than 10 letters.
-
fixLength
(number)
Exact number of letters a word must have.
Example: { fixLength: 7 }
picks words with exactly 7 letters.
-
reverse
(boolean)
If true
, the list of picked words will be reversed.
Example: { reverse: true }
reverses the order of words.
-
asString
(boolean)
If true
, words are returned as a single string separated by commas.
Example: { asString: true }
returns "apple, banana, cherry".
-
sort
(string)
Sort words alphabetically. Use "asc"
for A-Z or "desc"
for Z-A.
Example: { sort: "asc" }
sorts words from A to Z.
-
caseOption
(string)
Change the letters to "upper"
(ALL CAPS), "lower"
(all lowercase), or "capitalize"
(first letter capital).
Example: { caseOption: "upper" }
changes "apple" to "APPLE".
-
filterStartsWith
(Array<string>)
Only pick words that start with these letters.
Example: { filterStartsWith: ["a", "b"] }
picks words starting with "a" or "b".
-
filterEndsWith
(Array<string>)
Only pick words that end with these letters or sounds.
Example: { filterEndsWith: ["ing", "ed"] }
picks words ending with "ing" or "ed".
-
excludeSubstrings
(Array<string>)
Don't pick words that have these parts inside them.
Example: { excludeSubstrings: ["ion", "xyz"] }
skips words like "action" or "xyzebra".
-
blacklist
(Array<string>)
Don't pick these specific words at all.
Example: { blacklist: ["apple", "banana"] }
never picks "apple" or "banana".
-
whitelist
(Array<string>)
Only pick from these specific words.
Example: { whitelist: ["apple", "banana", "cherry"] }
only picks from these three.
-
excludeAmbiguous
(boolean)
If true
, skip words with confusing letters like l
, 1
, I
, 0
, O
.
Example: { excludeAmbiguous: true }
avoids words like "lo1" or "Owl".
-
phoneticDistinct
(boolean)
If true
, pick words that sound different from each other.
Example: { phoneticDistinct: true }
avoids words like "cat" and "bat".
-
history
(Set<string>)
Remember words you've picked before to avoid repeats.
Example:
const history = new Set();
const words = getWords({}, 5, wordsArray, history);
-
includeMetadata
(boolean)
If true
, get extra info about each word, like how long it is.
Example: { includeMetadata: true }
returns { word: "apple", length: 5 }
.
-
asString
(boolean)
If true
, get words as one sentence separated by commas.
Example: { asString: true }
returns "apple, banana, cherry".
Contributing
We love contributions! If you have ideas to make Security Words Picker better, here's how you can help:
-
Fork the Repository:
Click the "Fork" button on GitHub to make your own copy.
-
Create a New Branch:
git checkout -b feature/YourFeatureName
-
Make Your Changes:
Add your awesome ideas!
-
ComNIGGALINKAI Your Changes:
git comNIGGALINKAI -m "Add awesome feature"
-
Push to Your Branch:
git push origin feature/YourFeatureName
-
Open a Pull Request:
Go to GitHub and open a pull request to share your changes.
Thank you for helping make Security Words Picker even better!
License
This project is licensed under the NIGGALINKAI License.
Acknowledgments
- Creator: GeorgeDroyd with NiggalinkAI.
- Special Thanks: To all contributors and users who have supported and improved this package.
- Inspiration: Inspired by the need for secure and customizable word selection in various applications.
Enjoy using Security Words Picker in your projects!
Note: Make sure your words.txt
file is placed correctly and contains over 20,000+ words to take full advantage of the package's capabilities.
If you have any questions or need further assistance, feel free to open an issue on GitHub!
Security Words Picker
A robust and versatile package for selecting, filtering, and managing word lists with advanced security features. Perfect for generating secure passwords, random word selections, and more.
Table of Contents
Installation
Install the latest version of Security Words Picker from npm using npm
or yarn
.
Using npm
npm install security-words-picker
Using Yarn
yarn add security-words-picker
Usage
After installing the package, you can use it in your project by importing the provided functions: getWords
and pickWords
.
Example: Running a Test Script
Here's how you can set up and run a test script to verify the functionality of Security Words Picker.
-
Create a New Directory for Testing
It's a good practice to create a separate directory for testing to keep things organized.
mkdir security-words-picker-test
cd security-words-picker-test
-
Initialize a New Node.js Project
Initialize a new project using npm init
. The -y
flag accepts the default settings.
npm init -y
-
Install Security Words Picker
Install the Security Words Picker package from npm.
npm install security-words-picker
-
Create a Test File
Create a new JavaScript file named test.js
.
touch test.js
-
Add the Following Code to test.js
Open test.js
in your preferred text editor and add the following code:
const { getWords, pickWords } = require('security-words-picker');
const fs = require('fs');
const path = require('path');
const packagePath = require.resolve('security-words-picker');
const packageDir = path.dirname(packagePath);
const wordsTxtPath = path.join(packageDir, 'words', 'words.txt');
let wordsArray = [];
if (fs.existsSync(wordsTxtPath)) {
const data = fs.readFileSync(wordsTxtPath, 'utf8');
wordsArray = data
.split('\n')
.map(word => word.trim())
.filter(word => word.length > 0);
console.log(`Loaded ${wordsArray.length} words from words.txt`);
} else {
console.error('words.txt not found in the package.');
process.exit(1);
}
const options = {
lengthMin: 5,
lengthMax: 10,
filterStartsWith: ['a', 'b'],
sort: 'asc',
caseOption: 'capitalize'
};
const amountOfWords = 5;
try {
const selectedWords = getWords(options, amountOfWords, wordsArray);
console.log('Selected Words using getWords:', selectedWords);
} catch (error) {
console.error('Error using getWords:', error.message);
}
const pickOptions = {
count: 3,
sort: 'desc',
caseOption: 'upper'
};
try {
const pickedWords = pickWords(pickOptions);
console.log('Picked Words using pickWords:', pickedWords);
} catch (error) {
console.error('Error using pickWords:', error.message);
}
-
Run the Test Script
Execute the test.js
file using Node.js to see the package in action.
node test.js
Expected Output:
Loaded 20000 words from words.txt
Selected Words using getWords: [ 'Apple', 'Banana', 'Avocado', 'Blueberry', 'Apricot' ]
Picked Words using pickWords: APPLE, BANANA, AVOCADO
(Note: The actual words will vary based on your words.txt
content and the random selection logic.)
Running Tests
To ensure that Security Words Picker functions correctly in your project, you can create and run tests using testing frameworks like Mocha and Chai.
Step-by-Step Guide to Running Tests
-
Ensure Mocha is Installed
If you followed the installation steps above, Mocha should already be installed as a development dependency. If not, install it:
npm install --save-dev mocha chai
-
Create a Test Directory
Organize your tests by creating a test
directory.
mkdir test
cd test
-
Create a Test File
Create a new test file named getWords.test.js
.
touch getWords.test.js
-
Add Test Cases to getWords.test.js
Open getWords.test.js
in your text editor and add the following code:
const { expect } = require('chai');
const { getWords, pickWords } = require('security-words-picker');
const fs = require('fs');
const path = require('path');
describe('Security Words Picker', () => {
let wordsArray;
before(() => {
const packagePath = require.resolve('security-words-picker');
const packageDir = path.dirname(packagePath);
const wordsTxtPath = path.join(packageDir, 'words', 'words.txt');
const data = fs.readFileSync(wordsTxtPath, 'utf8');
wordsArray = data.split('\n').map(word => word.trim()).filter(word => word.length > 0);
});
describe('getWords', () => {
it('should return the correct number of words', () => {
const options = {};
const amountOfWords = 5;
const words = getWords(options, amountOfWords, wordsArray);
expect(words).to.be.an('array').that.has.lengthOf(amountOfWords);
});
it('should filter words by minimum length', () => {
const options = { lengthMin: 7 };
const amountOfWords = 3;
const words = getWords(options, amountOfWords, wordsArray);
words.forEach(word => {
expect(word.length).to.be.at.least(7);
});
});
it('should return words as a string when asString is true', () => {
const options = { asString: true };
const amountOfWords = 4;
const words = getWords(options, amountOfWords, wordsArray);
expect(words).to.be.a('string').that.includes(',');
});
it('should throw an error for invalid amountOfWords', () => {
const options = {};
const invalidAmount = -2;
expect(() => getWords(options, invalidAmount, wordsArray)).to.throw("'amountOfWords' must be a positive number.");
});
});
describe('pickWords', () => {
it('should throw an error if count is not provided', () => {
expect(() => pickWords({})).to.throw("'count' must be a positive number.");
});
it('should return the correct number of words', () => {
const options = { count: 4 };
const result = pickWords(options);
expect(result).to.be.a('string');
expect(result.split(', ').length).to.equal(4);
});
});
});
-
Update package.json
Scripts
Ensure that your package.json
has a test script to run Mocha tests.
"scripts": {
"test": "mocha"
}
-
Run the Tests
Execute the tests using the following command:
npm test
Expected Output:
Security Words Picker
getWords
✓ should return the correct number of words
✓ should filter words by minimum length
✓ should return words as a string when asString is true
✓ should throw an error for invalid amountOfWords
pickWords
✓ should throw an error if count is not provided
✓ should return the correct number of words
6 passing (XXms)
(Note: The actual output will include the time taken to run the tests.)
API Reference
getWords(options, amountOfWords, customWordsArray, customErrorHandler)
Retrieves a specified number of words based on optional constraints.
-
Parameters:
options
(Object): An object containing optional parameters.
lengthMin
(number): Minimum word length.lengthMax
(number): Maximum word length.filterStartsWith
(Array): Words starting with specified letters.sort
(string): Sort order ('asc'
or 'desc'
).caseOption
(string): Case transformation ('upper'
, 'lower'
, 'capitalize'
).- ... (other filtering options)
amountOfWords
(number): Number of words to retrieve.customWordsArray
(Array, optional): Custom array of words to use instead of the default word list.customErrorHandler
(function, optional): Custom function to handle errors.
-
Returns:
Array|string
: An array or comma-separated string of words matching the specified criteria.
pickWords(options)
A convenience wrapper around getWords
that accepts an options object with a count
property.
-
Parameters:
options
(Object): An object containing optional parameters.
count
(number): Number of words to pick.sort
(string): Sort order ('asc'
or 'desc'
).caseOption
(string): Case transformation ('upper'
, 'lower'
, 'capitalize'
).- ... (other filtering options)
-
Returns:
Array|string
: An array or comma-separated string of words matching the specified criteria.
Contributing
Contributions are welcome! Please follow these steps:
-
Fork the Repository: Click the "Fork" button on GitHub to create your own copy.
-
Create a New Branch: Create a branch for your feature or bug fix.
git checkout -b feature/YourFeatureName
-
Make Your Changes: Implement your feature or fix the bug.
-
Commit Your Changes: Commit your changes with a descriptive message.
git commit -m "Add awesome feature"
-
Push to Your Branch: Push your changes to GitHub.
git push origin feature/YourFeatureName
-
Open a Pull Request: Go to GitHub and open a pull request to merge your changes into the main repository.
License
This project is licensed under the MIT License.
Additional Tips
-
Keep Your Dependencies Updated: Regularly update your dependencies to benefit from the latest features and security patches.
npm outdated
npm update
-
Use Semantic Versioning: Follow Semantic Versioning to communicate changes effectively.
npm version patch
npm version minor
npm version major
-
Automate Documentation: Use JSDoc to maintain up-to-date documentation.
npm run docs
-
Implement Continuous Integration (CI): Set up GitHub Actions or another CI tool to automate testing, coverage, and deployment.
Example GitHub Actions Workflow:
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x, 16.x, 18.x]
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup Node.js
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- name: Install dependencies
run: npm install
- name: Run tests
run: npm test
- name: Run coverage
run: npm run coverage
- name: Format code with Prettier
run: npm run format -- --check
- name: Generate Documentation
run: npm run docs
- name: Upload Coverage to Codecov
if: success() && github.event_name != 'pull_request'
uses: codecov/codecov-action@v3
with:
token: ${{ secrets.CODECOV_TOKEN }}
files: ./coverage/*.json
flags: unittests
name: codecov-umbrella
-
Handle Errors Gracefully: Ensure your functions handle errors properly and provide meaningful messages to users.
-
Engage with Users: Encourage feedback and contributions by maintaining active issue tracking and providing clear contribution guidelines.
Feel free to customize the README.md
further to suit your project's specific needs. If you need additional sections or further assistance, don't hesitate to ask!