Skip to content

Commit

Permalink
create converter
Browse files Browse the repository at this point in the history
  • Loading branch information
sensone committed Feb 12, 2017
0 parents commit 0e564d5
Show file tree
Hide file tree
Showing 10 changed files with 778 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"presets": ["es2015"]
}
7 changes: 7 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"extends": "airbnb",
"env": {
"node": true,
"mocha": true
}
}
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
logs
*.log
npm-debug.log*
lib
node_modules
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
logs
*.log
npm-debug.log*
node_modules
22 changes: 22 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
(The MIT License)

Copyright (c) 2015 Evgeni Korsunov <5345043@gmail.com>

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
'Software'), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# Text 2 smiles

Special text converter for easy converting text to something like this:

```
🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈
🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🎱🎱🎱🙈🙈🙈🙈🙈🙈🙈
🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈🙈
🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🙈🙈
🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈
🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🙈🙈
🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈
🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈
🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🎱🎱🙈🙈
🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈
🙈🙈🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈
🙈🙈🙈🙈🙈🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🙈🎱🙈🙈🙈🎱🙈🙈🙈🙈🙈🎱🙈🙈🎱🙈
🙈🙈🙈🙈🙈🙈🙈🙈🎱🎱🙈🙈🙈🎱🎱🎱🎱🙈🙈🎱🙈🙈🎱🙈🙈🎱🎱🎱🎱🙈🙈🎱🎱🎱🙈🙈
🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈🙈
```

## Installing

```
npm install text2smiles --save
```

### How to use

```javascript
convertText2Smiles(text, [backgroundSmile = '🤘', textSmile = '💀', countSymbolsOnTheRow = 8]);

```
### Example

```javascript
// var convertText2Smiles = require('text2smiles').default;
import convertText2Smiles from 'text-of-smiles';

// should display the text above
console.log(convertText2Smiles('hello, world', '🙈', '🎱', 6));

```

## License

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details
38 changes: 38 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
"name": "text2smiles",
"version": "1.0.3",
"description": "Converting text to smiles",
"keywords": [
"emoji",
"smiles",
"text to emoji",
"text to symbols",
"converting text"
],
"main": "./lib/index.js",
"scripts": {
"lint": "./node_modules/.bin/eslint ./src",
"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"
},
"author": "Evgeni Korsunov<5345043@gmail.com>",
"dependencies": {
"babel-core": "^6.22.1",
"babel-preset-es2015": "^6.22.0"
},
"devDependencies": {
"eslint": "^3.15.0",
"eslint-config-airbnb": "^14.1.0",
"eslint-plugin-import": "^2.2.0",
"eslint-plugin-jsx-a11y": "^3.0.2",
"eslint-plugin-react": "^6.9.0",
"mocha": "^3.2.0"
},
"license": "MIT",
"repository": {
"type": "git",
"url" : "https://github.com/sensone/text2smiles.git"
}
}
49 changes: 49 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { ABC, LETTER_WIDTH, LETTER_HEIGHT } from './serift';

const STRING_LENGTH = 8;

export default function convertText2Smiles(text = '', symb1 = '🤘', symb2 = '💀', strLength = STRING_LENGTH) {
if (!text.length) return text;

function getLetter(symb, lineIndex) {
let letter;

switch (symb) {
case "'":
letter = ABC.quote;
break;
default:
letter = ABC[symb];
}

if (!letter) {
letter = ABC[' '];
}

return letter.slice((lineIndex * LETTER_WIDTH), (lineIndex * LETTER_WIDTH) + LETTER_WIDTH);
}

function generateLine(str, result = '') {
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 letterIndex = 0; letterIndex < currentString.length; letterIndex += 1) {
const letter = currentString[letterIndex];

currentResult += getLetter(letter, lineIndex);
}

currentResult += '\n';
}

if (surplusString.length > 0) {
return generateLine(surplusString, currentResult);
}

return currentResult;
}

return generateLine(text.toLowerCase()).replace(/\./g, symb1).replace(/\*/g, symb2);
}
Loading

0 comments on commit 0e564d5

Please sign in to comment.