Skip to content

Commit

Permalink
Merge pull request #18 from carvilsi/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
carvilsi authored May 9, 2024
2 parents 640da54 + 208c820 commit bc7f3f3
Show file tree
Hide file tree
Showing 7 changed files with 52 additions and 14 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Changelog

# [v1.4.1](https://github.com/carvilsi/facetxt/releases/tag/v1.4.1) (2024-05-09)

- added moar faces
- fixes repeated not showing on like and likes

# [v1.4.0](https://github.com/carvilsi/facetxt/releases/tag/v1.4.0) (2024-04-29)

- added 210 new faces :-)
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<p>Have a random text face, or the one that you choose, on your command line or in your project.</p>
<p></p>
<p></p>
<p>Now with 754 awesome faces! o_O</p>
<p>Now with 765 awesome faces! o_O</p>
</div>

## Usage
Expand Down
14 changes: 7 additions & 7 deletions benchmark/report.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
┌─────────┬──────────────────────────────────────┬──────────────┬────────────────────┬──────────┬─────────┐
│ (index) │ Task Name │ ops/sec │ Average Time (ns) │ Margin │ Samples │
├─────────┼──────────────────────────────────────┼──────────────┼────────────────────┼──────────┼─────────┤
│ 0 │ 'random face' │ '1,132,887' │ 882.6998208121295 │ '±2.41%' │ 113289
│ 1 │ 'random face with description' │ '888,523' │ 1125.4625955230447 │ '±3.46%' │ 88853
│ 2 │ 'get array with all the faces' │ '6,361' │ 157201.19309262166 │ '±0.82%' │ 637
│ 3 │ 'get all the faces for pretty print' │ '11,622,904' │ 86.03701568705623 │ '±0.87%' │ 1162291
│ 4 │ 'get one by name; more than one' │ '13,077' │ 76467.84633027107 │ '±0.80%' │ 1308
│ 5 │ 'get one by name; just one' │ '13,686' │ 73065.91818846014 │ '±0.97%' │ 1369
│ 6 │ 'get array of faces by name' │ '12,887' │ 77593.82544608272 │ '±1.22%' │ 1289
│ 0 │ 'random face' │ '1,147,603' │ 871.3809220904542 │ '±2.29%' │ 114761
│ 1 │ 'random face with description' │ '860,302' │ 1162.3823389240104 │ '±3.67%' │ 86031
│ 2 │ 'get array with all the faces' │ '5,501' │ 181774.9655797145 │ '±3.08%' │ 552
│ 3 │ 'get all the faces for pretty print' │ '10,178,463' │ 98.24665691409682 │ '±0.88%' │ 1017847
│ 4 │ 'get one by name; more than one' │ '12,492' │ 80050.38239999686 │ '±1.24%' │ 1250
│ 5 │ 'get one by name; just one' │ '13,407' │ 74585.24235644552 │ '±1.19%' │ 1341
│ 6 │ 'get array of faces by name' │ '12,763' │ 78351.33281128126 │ '±1.21%' │ 1277
└─────────┴──────────────────────────────────────┴──────────────┴────────────────────┴──────────┴─────────┘
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "facetxt",
"version": "1.4.0",
"version": "1.4.1",
"description": "",
"main": "./src/index.js",
"type": "module",
Expand Down
9 changes: 7 additions & 2 deletions src/faces.js
Original file line number Diff line number Diff line change
Expand Up @@ -324,7 +324,13 @@ const customs = {
greedy: [ '$_$' ],
confusion: [ '?_?' ],
shyness: [ '6_6' ],
surprise_shock: [ '!_!' ]
surprise_shock: [ '!_!' ],
wink: [ '^_~', '~_^', '^_-', '-_^' ],
rustaceans_print_all: [ '{:?}' ],
rustaceans_pretty_print_all: [ '{:#?}' ],
rurouni_kenshin_himura: [ '((^_^x))' ],
cabbit: [ ' (_/=^_^=\\_)' ],
owl: [ '(^v^)', '(OvO)', '(0v0)', '(-v-)' ]
},
asciimoji: {
acid: [ '⊂(◉‿◉)つ' ],
Expand Down Expand Up @@ -367,7 +373,6 @@ const customs = {
dunno: [ '¯\\(°_o)/¯' ],
eeriemob: [ '(-(-_-(-_(-_(-_-)_-)-_-)_-)_-)-)' ],
endure: [ '(҂◡_◡) ᕤ' ],
envelope_letter: [ '✉︎' ],
evillenny: [ '(͠≖ ͜ʖ͠≖)' ],
execution: [ '(⌐■_■)︻╦╤─ (╥﹏╥)' ],
facebook: [ '(╯°□°)╯︵ ʞooqǝɔɐɟ' ],
Expand Down
21 changes: 19 additions & 2 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,26 @@ function collectFacesToArray(obj) {
}
}

// for the faces (property) from object (obj) that
// exists at reducedFaces:
// - removes from the object (obj)
// - concatenates to the array on reducedFaces
function cleanRepeatedFaces(obj) {
for (const property in obj) {
if (Object.hasOwn(reducedFaces, property)) {
reducedFaces[property] = reducedFaces[property]
.concat(obj[property]);
delete obj[property];
}
}
return obj;
}

function reduceFacesObject(obj) {
for (const property in obj) {
if (!Array.isArray(obj) && Array.isArray(obj[property])) {
reducedFaces = { ...reducedFaces, ...obj };
const cleanedObj = cleanRepeatedFaces(obj);
reducedFaces = { ...reducedFaces, ...cleanedObj };
break;
}
if (typeof obj[property] === 'object') {
Expand Down Expand Up @@ -105,6 +121,7 @@ const facetxt = {
};

// get the reduced object with faces for random and like functions
reduceFacesObject(faces);
const facesObj = structuredClone(faces);
reduceFacesObject(facesObj);

export default facetxt;
13 changes: 12 additions & 1 deletion tests/main.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import test from 'ava';
import facetxt from '../src/index.js';

const TOTAL_FACES = 754;
const TOTAL_FACES = 765;
const WHOLE_EMBARRASSED_FACES = [
':$', '://)',
'://3', '(^^ゞ',
Expand All @@ -14,6 +14,11 @@ const WHOLE_EMBARRASSED_FACES = [
'(#^.^#)', '(^ ^;)',
'(⁄⁄•⁄ω⁄•⁄⁄)'
];
const WHOLE_ZOIDBERG_FACES = [
'(V) (;, ;) (V)',
'(V)(°, °)(V)',
'(V) (°,,,,°) (V)'
];

let arrayOfFaces = null;
let face = null;
Expand Down Expand Up @@ -71,6 +76,12 @@ test('should retrieve the array related with name', (t) => {
t.like(faces, WHOLE_EMBARRASSED_FACES);
});

test('should retrieve the array related with zoidberg', (t) => {
const faces = facetxt.likes('zoidberg');

t.like(faces, WHOLE_ZOIDBERG_FACES);
});

test('should not retrieve the array related with name, because does not exists', (t) => {
const faces = facetxt.likes('foz');

Expand Down

0 comments on commit bc7f3f3

Please sign in to comment.