Skip to content

Commit

Permalink
Merge pull request #6 from farisj/custom-parts
Browse files Browse the repository at this point in the history
Add Ability to use Custom Characters
  • Loading branch information
xxczaki authored Apr 17, 2018
2 parents f2cc004 + e57a6e8 commit b782741
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ npm i -g oji

Just type `oji` to start interactive emoticon creator! Works on every platform :unicorn:

### :sparkles: Make it your own! :sparkles:

You can add custom characters for each part by creating an optional `~/.oji` directory in your root path. Add new characters to each section by creating a `~/.oji/{file}.txt` with any of the corresponding filenames:

`'arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'`

## :package: npm Dependencies [![Known Vulnerabilities](https://snyk.io/test/github/xxczaki/oji/badge.svg)](https://snyk.io/test/github/xxczaki/oji)

- [inquirer](https://www.npmjs.com/package/inquirer)
Expand Down
17 changes: 13 additions & 4 deletions lib/functions.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,20 @@ const getRandomIndex = length => {
return Math.floor(Math.random() * length);
};

const getParts = () => {
return ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName => {
let parts = fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n');
const customParts = fs.existsSync(`${homeDir}/.oji/${fileName}.txt`) && fs.readFileSync(`${homeDir}/.oji/${fileName}.txt`, 'utf8').split('\n');
if (customParts) {
parts = parts.concat(customParts);
}
return parts;
});
};

// Create emoji!
module.exports.create = () => {
const parts = ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName =>
fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n'));
const parts = getParts();
return inquirer.prompt([
{
type: 'list',
Expand Down Expand Up @@ -106,8 +116,7 @@ module.exports.create = () => {

// Create random emoji!
module.exports.random = () => {
const parts = ['arms_symmetric', 'arms_left', 'bodies_symmetric', 'bodies_left', 'cheeks', 'eyes', 'mouths_noses', 'bodies_right', 'arms_right'].map(fileName =>
fs.readFileSync(`${__dirname}/parts/${fileName}.txt`, 'utf8').split('\n'));
const parts = getParts();
// Combine random parts
const leftarmIndex = getRandomIndex([...parts[1], ...parts[0]].length);
const rightarmIndex = getRandomIndex([...parts[8], ...parts[0]].length);
Expand Down

0 comments on commit b782741

Please sign in to comment.