diff --git a/README.md b/README.md index 0d4b2c7..4528278 100644 --- a/README.md +++ b/README.md @@ -3,20 +3,19 @@ Special text converter for easy converting text to something like this: ``` -🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 -🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🎱🎱🎱🙈🙈🙈🙈🙈🙈🙈 -🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈🙈 -🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈🙈 -🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈 -🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈 -🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 -🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 -🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🎱🎱🙈🙈 -🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈 -🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈 -🙈🙈🙈🙈🙈🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈 -🙈🙈🙈🙈🙈🙈🙈🙈🎱🎱🙈🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈 -🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 +🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 +🙈🎱🙈🙈🎱🙈🎱🎱🎱🎱🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🎱🙈🙈🙈🙈🙈🙈🙈 +🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈 +🙈🎱🎱🎱🎱🙈🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈 +🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🙈 +🙈🎱🙈🙈🎱🙈🎱🎱🎱🎱🙈🎱🎱🎱🎱🙈🎱🎱🎱🎱🙈🙈🎱🎱🙈🙈🎱🙈🙈🙈🙈 +🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 +🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🙈🙈🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈🎱🎱🎱🙈🙈 +🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🎱🙈🙈🎱🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈 +🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🎱🙈🙈🎱🙈🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈 +🙈🙈🙈🙈🙈🙈🎱🎱🎱🎱🙈🎱🙈🙈🎱🙈🎱🙈🎱🙈🙈🎱🙈🙈🙈🙈🎱🙈🙈🎱🙈 +🙈🙈🙈🙈🙈🙈🙈🎱🎱🙈🙈🙈🎱🎱🙈🙈🎱🙈🙈🎱🙈🎱🎱🎱🎱🙈🎱🎱🎱🙈🙈 +🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈 ``` ## Installing diff --git a/package.json b/package.json index 3ff15ce..bb70d46 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "text2smiles", - "version": "1.0.3", + "version": "1.1.0", "description": "Converting text to smiles", "keywords": [ "emoji", @@ -15,7 +15,8 @@ "transpile-es2015": "babel src -d lib", "test": "./node_modules/mocha/bin/mocha --compilers js:babel-core/register ./src/tests", "test-all": "npm run lint && npm run test", - "preinstall": "npm run transpile-es2015" + "preinstall": "npm run transpile-es2015", + "deploy": "npm run test-all && npm publish" }, "author": "Evgeni Korsunov<5345043@gmail.com>", "dependencies": { diff --git a/src/index.js b/src/index.js index cf97527..f70180d 100644 --- a/src/index.js +++ b/src/index.js @@ -2,14 +2,16 @@ import { ABC, LETTER_WIDTH, LETTER_HEIGHT } from './serift'; const STRING_LENGTH = 8; -export default function convertText2Smiles(text = '', symb1 = '🤘', symb2 = '💀', strLength = STRING_LENGTH) { +export default function convertText2Smiles(text = '', bgSymbol = '🤘', textSymbol = '💀', strLength = STRING_LENGTH) { if (!text.length) return text; function getLetter(symb, lineIndex) { let letter; + const POSITION = lineIndex * LETTER_WIDTH; switch (symb) { case "'": + case '"': letter = ABC.quote; break; default: @@ -20,30 +22,30 @@ export default function convertText2Smiles(text = '', symb1 = '🤘', symb2 = ' letter = ABC[' ']; } - return letter.slice((lineIndex * LETTER_WIDTH), (lineIndex * LETTER_WIDTH) + LETTER_WIDTH); + return letter.slice(POSITION, POSITION + (LETTER_WIDTH - 1)); } - function generateLine(str, result = '') { + function generateLine(str, result = '', secondLine = false) { let currentResult = result; const currentString = str.slice(0, strLength); const surplusString = str.slice(strLength); - for (let lineIndex = 0; lineIndex < LETTER_HEIGHT; lineIndex += 1) { + for (let lineIndex = secondLine ? 1 : 0; lineIndex < LETTER_HEIGHT; lineIndex += 1) { for (let letterIndex = 0; letterIndex < currentString.length; letterIndex += 1) { const letter = currentString[letterIndex]; currentResult += getLetter(letter, lineIndex); } - currentResult += '\n'; + currentResult += `${bgSymbol}\n`; } if (surplusString.length > 0) { - return generateLine(surplusString, currentResult); + return generateLine(surplusString, currentResult, true); } return currentResult; } - return generateLine(text.toLowerCase()).replace(/\./g, symb1).replace(/\*/g, symb2); + return generateLine(text.toLowerCase()).replace(/\./g, bgSymbol).replace(/\*/g, textSymbol); } diff --git a/src/serift.js b/src/serift.js index d67b0d6..bff40e5 100644 --- a/src/serift.js +++ b/src/serift.js @@ -140,11 +140,11 @@ const N = ` const O = ` ...... -.****. +..**.. .*..*. .*..*. .*..*. -.****. +..**.. ...... `; @@ -242,7 +242,7 @@ const Y = ` ...... .*..*. .*..*. -.****. +..***. ....*. .****. ...... diff --git a/src/tests/index.spec.js b/src/tests/index.spec.js index 718eefb..a86a453 100644 --- a/src/tests/index.spec.js +++ b/src/tests/index.spec.js @@ -61,7 +61,7 @@ describe('Converting text to smiles:', () => { describe('Testing with 4 arguments, text with symbols: X and Y', () => { const LETTERS_IN_ROW = 1; const TEXT = 'ok'; - const ROWS_COUNT = ((TEXT.length / LETTERS_IN_ROW) * LETTER_HEIGHT) + 1; + const ROWS_COUNT = ((TEXT.length / LETTERS_IN_ROW) * LETTER_HEIGHT); beforeEach(() => { result = convertText2Smiles('ok', 'X', 'Y', LETTERS_IN_ROW); @@ -81,8 +81,21 @@ describe('Converting text to smiles:', () => { }); it('result should be equal template', () => { - let template = 'XXXXXX\nXYYYYX\nXYXXYX\nXYXXYX\nXYXXYX\nXYYYYX\nXXXXXX\n'; - template += 'XXXXXX\nXYXXYX\nXYXYXX\nXYYXXX\nXYXYXX\nXYXXYX\nXXXXXX\n'; + let template = ''; + + template += 'XXXXXX\n'; + template += 'XXYYXX\n'; + template += 'XYXXYX\n'; + template += 'XYXXYX\n'; + template += 'XYXXYX\n'; + template += 'XXYYXX\n'; + template += 'XXXXXX\n'; + template += 'XYXXYX\n'; + template += 'XYXYXX\n'; + template += 'XYYXXX\n'; + template += 'XYXYXX\n'; + template += 'XYXXYX\n'; + template += 'XXXXXX\n'; assert.equal(result, template); }); @@ -92,34 +105,31 @@ describe('Converting text to smiles:', () => { it('result should be equal template', () => { let template = ''; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,@@,,,,@,,,,@,,,,,@,,,,\n'; - template += ',,@@,,,,@,,,,@,,,,,@,,,,\n'; - template += ',,@@,,,,,,,,,@,,,,,@,,,,\n'; - template += ',,@@,,,,,,,,,@,,,,,@,,,,\n'; - template += ',,@@,,,,,,,,,@@@@,,@@@@,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,@@@,,,@@@@,,,,,,,\n'; - template += ',,,,,,,@,,@,,@,,,,,,,,,,\n'; - template += ',,,,,,,@@@,,,@@@,,,,,,,,\n'; - template += ',,,,,,,@,,@,,@,,,,,,,,,,\n'; - template += ',,,,,,,@@@,,,@@@@,,,,,,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',@@@,,,,@@,,,,@@@,,@,,@,\n'; - template += ',@,,@,,@,,@,,@,,,,,@,@,,\n'; - template += ',@@@,,,@@@@,,@,,,,,@@,,,\n'; - template += ',@,,@,,@,,@,,@,,,,,@,@,,\n'; - template += ',@@@,,,@,,@,,,@@@,,@,,@,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,,@@,,,,@@,,,,@@,,\n'; - template += ',,,,,,,,@@,,,,@@,,,,@@,,\n'; - template += ',,,,,,,,@@,,,,@@,,,,@@,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; - template += ',,,,,,,,@@,,,,@@,,,,@@,,\n'; - template += ',,,,,,,,,,,,,,,,,,,,,,,,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; + template += ',,@@,,,@,,,@,,,,@,,,,\n'; + template += ',,@@,,,@,,,@,,,,@,,,,\n'; + template += ',,@@,,,,,,,@,,,,@,,,,\n'; + template += ',,@@,,,,,,,@,,,,@,,,,\n'; + template += ',,@@,,,,,,,@@@@,@@@@,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; + template += ',,,,,,@@@,,@@@@,,,,,,\n'; + template += ',,,,,,@,,@,@,,,,,,,,,\n'; + template += ',,,,,,@@@,,@@@,,,,,,,\n'; + template += ',,,,,,@,,@,@,,,,,,,,,\n'; + template += ',,,,,,@@@,,@@@@,,,,,,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; + template += ',@@@,,,@@,,,@@@,@,,@,\n'; + template += ',@,,@,@,,@,@,,,,@,@,,\n'; + template += ',@@@,,@@@@,@,,,,@@,,,\n'; + template += ',@,,@,@,,@,@,,,,@,@,,\n'; + template += ',@@@,,@,,@,,@@@,@,,@,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; + template += ',,,,,,,@@,,,@@,,,@@,,\n'; + template += ',,,,,,,@@,,,@@,,,@@,,\n'; + template += ',,,,,,,@@,,,@@,,,@@,,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; + template += ',,,,,,,@@,,,@@,,,@@,,\n'; + template += ',,,,,,,,,,,,,,,,,,,,,\n'; result = convertText2Smiles('I\'LL BE BACK^!!!', ',', '@', 4);