Skip to content

Commit

Permalink
⚡️First Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
kokororin committed Sep 20, 2016
0 parents commit 2cff42a
Show file tree
Hide file tree
Showing 8 changed files with 285 additions and 0 deletions.
10 changes: 10 additions & 0 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
"extends": "crocodile",
"parserOptions": {
"ecmaFeatures": {
"jsx": true,
"es6": true,
"node": true
}
}
}
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2016 Kokororin (https://kotori.love)

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.
33 changes: 33 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
# kaomojify (≧∀≦*)

[![GitHub issues](https://img.shields.io/github/issues/kokororin/pixiv.moe.svg)](https://github.com/kokororin/kaomojify/issues)
[![npm version](https://badge.fury.io/js/pixiv.moe.svg)](https://badge.fury.io/js/kaomojify)
![Dependency Tracker](https://img.shields.io/david/kokororin/kaomojify.svg "Dependency Tracker") ![Dependency Tracker](https://img.shields.io/david/dev/kokororin/kaomojify.svg "Dependency Tracker")

Convert Javascript code to Japanese kawaii kaomoji(かわいい顔文字).
The converter is powered by [utf-8.jp](http://utf-8.jp/public/aaencode.html).

## Installation
```bash
$ npm install -g kaomojify
```

## Usage
```bash
kaomojify <input> -o <output>
```

example:
```bash
# single file
kaomojify src/main.js -o dist/

# use glob definition in input
kaomojify src/*.js -o dist/
```

## Contribute
Feel free to contribute (PR-s and issues welcomed).

## License
[MIT license](http://opensource.org/licenses/mit-license.php)
44 changes: 44 additions & 0 deletions cli.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env node
'use strict';

const glob = require('glob');
const yargs = require('yargs');
const fs = require('fs');
const path = require('path');
const sh = require('shelljs');
const convert = require('./convert');

const argv = yargs.argv;

if (!argv._[0]) {
console.error('ERROR: Invalid arguments');
process.exit(1);
}

const input = argv._[0];

const convertAndWrite = (file) => {

let output = fs.readFileSync(file, 'utf8');
output = convert(output);
if (!argv.o) {
console.error('ERROR: Invalid -o');
process.exit(1);
}
const outputPath = path.join(sh.pwd(), '/' + argv.o);
if (!fs.existsSync(outputPath)) {
console.log(outputPath);
fs.mkdirSync(outputPath);
}
fs.writeFileSync(outputPath + path.basename(file), output);
};

glob(input, (err, files) => {
if (err) {
console.error('ERROR: Invalid glob definition');
process.exit(1);
}
for (let file of files) {
convertAndWrite(file);
}
});
68 changes: 68 additions & 0 deletions convert.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
'use strict';

module.exports = (text) => {
let t;
const b = [
"(c^_^o)",
"(゚Θ゚)",
"((o^_^o) - (゚Θ゚))",
"(o^_^o)",
"(゚ー゚)",
"((゚ー゚) + (゚Θ゚))",
"((o^_^o) +(o^_^o))",
"((゚ー゚) + (o^_^o))",
"((゚ー゚) + (゚ー゚))",
"((゚ー゚) + (゚ー゚) + (゚Θ゚))",
"(゚Д゚) .゚ω゚ノ",
"(゚Д゚) .゚Θ゚ノ",
"(゚Д゚) ['c']",
"(゚Д゚) .゚ー゚ノ",
"(゚Д゚) .゚Д゚ノ",
"(゚Д゚) [゚Θ゚]"
];
let r = "゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); ";

if (/×(365|)\s*[!]/.test(text)) {
r += "X=_=3; ";
r += "\r\n\r\n X / _ / X < \"来週も見てくださいね!\";\r\n\r\n";
}
r += "(゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);" +
"(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] " +
",゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] " +
",゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];" +
"(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];" +
"(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];" +
"(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + " +
"((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+" +
"((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+" +
"((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+" +
"((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];" +
"(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+" +
"((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+" +
"((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; " +
"(゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\\\'; " +
"(゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];" +
"(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];" +
"(゚Д゚) [゚o゚]='\\\"';" +
"(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+";
r += "(゚Д゚)[゚o゚]+ ";
for (let i = 0; i < text.length; i++) {
const n = text.charCodeAt(i);
t = "(゚Д゚)[゚ε゚]+";
if (n <= 127) {
t += n.toString(8).replace(/[0-7]/g, (c) => {
return b[c] + "+ ";
});
} else {
const m = /[0-9a-f]{4}$/.exec("000" + n.toString(16))[0];
t += "(o゚ー゚o)+ " + m.replace(/[0-9a-f]/gi, (c) => {
return b[parseInt(c, 16)] + "+ ";
});
}
r += t;

}
r += "(゚Д゚)[゚o゚]) (゚Θ゚)) ('_');";
return r;

}
74 changes: 74 additions & 0 deletions kaomojify.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
'use strict';

class Kaomojify {

static convert(text) {
let t;
const b = [
"(c^_^o)",
"(゚Θ゚)",
"((o^_^o) - (゚Θ゚))",
"(o^_^o)",
"(゚ー゚)",
"((゚ー゚) + (゚Θ゚))",
"((o^_^o) +(o^_^o))",
"((゚ー゚) + (o^_^o))",
"((゚ー゚) + (゚ー゚))",
"((゚ー゚) + (゚ー゚) + (゚Θ゚))",
"(゚Д゚) .゚ω゚ノ",
"(゚Д゚) .゚Θ゚ノ",
"(゚Д゚) ['c']",
"(゚Д゚) .゚ー゚ノ",
"(゚Д゚) .゚Д゚ノ",
"(゚Д゚) [゚Θ゚]"
];
let r = "゚ω゚ノ= /`m´)ノ ~┻━┻ //*´∇`*/ ['_']; o=(゚ー゚) =_=3; c=(゚Θ゚) =(゚ー゚)-(゚ー゚); ";

if (/×(365|)\s*[!]/.test(text)) {
r += "X=_=3; ";
r += "\r\n\r\n X / _ / X < \"来週も見てくださいね!\";\r\n\r\n";
}
r += "(゚Д゚) =(゚Θ゚)= (o^_^o)/ (o^_^o);" +
"(゚Д゚)={゚Θ゚: '_' ,゚ω゚ノ : ((゚ω゚ノ==3) +'_') [゚Θ゚] " +
",゚ー゚ノ :(゚ω゚ノ+ '_')[o^_^o -(゚Θ゚)] " +
",゚Д゚ノ:((゚ー゚==3) +'_')[゚ー゚] }; (゚Д゚) [゚Θ゚] =((゚ω゚ノ==3) +'_') [c^_^o];" +
"(゚Д゚) ['c'] = ((゚Д゚)+'_') [ (゚ー゚)+(゚ー゚)-(゚Θ゚) ];" +
"(゚Д゚) ['o'] = ((゚Д゚)+'_') [゚Θ゚];" +
"(゚o゚)=(゚Д゚) ['c']+(゚Д゚) ['o']+(゚ω゚ノ +'_')[゚Θ゚]+ ((゚ω゚ノ==3) +'_') [゚ー゚] + " +
"((゚Д゚) +'_') [(゚ー゚)+(゚ー゚)]+ ((゚ー゚==3) +'_') [゚Θ゚]+" +
"((゚ー゚==3) +'_') [(゚ー゚) - (゚Θ゚)]+(゚Д゚) ['c']+" +
"((゚Д゚)+'_') [(゚ー゚)+(゚ー゚)]+ (゚Д゚) ['o']+" +
"((゚ー゚==3) +'_') [゚Θ゚];(゚Д゚) ['_'] =(o^_^o) [゚o゚] [゚o゚];" +
"(゚ε゚)=((゚ー゚==3) +'_') [゚Θ゚]+ (゚Д゚) .゚Д゚ノ+" +
"((゚Д゚)+'_') [(゚ー゚) + (゚ー゚)]+((゚ー゚==3) +'_') [o^_^o -゚Θ゚]+" +
"((゚ー゚==3) +'_') [゚Θ゚]+ (゚ω゚ノ +'_') [゚Θ゚]; " +
"(゚ー゚)+=(゚Θ゚); (゚Д゚)[゚ε゚]='\\\\'; " +
"(゚Д゚).゚Θ゚ノ=(゚Д゚+ ゚ー゚)[o^_^o -(゚Θ゚)];" +
"(o゚ー゚o)=(゚ω゚ノ +'_')[c^_^o];" +
"(゚Д゚) [゚o゚]='\\\"';" +
"(゚Д゚) ['_'] ( (゚Д゚) ['_'] (゚ε゚+";
r += "(゚Д゚)[゚o゚]+ ";
for (let i = 0; i < text.length; i++) {
const n = text.charCodeAt(i);
t = "(゚Д゚)[゚ε゚]+";
if (n <= 127) {
t += n.toString(8).replace(/[0-7]/g, (c) => {
return b[c] + "+ ";
});
} else {
const m = /[0-9a-f]{4}$/.exec("000" + n.toString(16))[0];
t += "(o゚ー゚o)+ " + m.replace(/[0-9a-f]/gi, (c) => {
return b[parseInt(c, 16)] + "+ ";
});
}
r += t;

}
r += "(゚Д゚)[゚o゚]) (゚Θ゚)) ('_');";
return r;

}

}

module.exports = Kaomojify;
34 changes: 34 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "kaomojify",
"version": "0.1.0",
"description": "Kaomojify Javascript code",
"main": "",
"bin": {
"kaomojify": "./cli.js"
},
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"lint": "eslint ./"
},
"repository": {
"type": "git",
"url": "git+https://github.com/kokororin/kaomojify.git"
},
"keywords": [
"library"
],
"author": "kokororin",
"license": "MIT",
"bugs": {
"url": "https://github.com/kokororin/kaomojify/issues"
},
"homepage": "https://github.com/kokororin/kaomojify#readme",
"devDependencies": {
"eslint": "^3.5.0",
"eslint-config-crocodile": "^1.0.0"
},
"dependencies": {
"glob": "^7.0.6",
"yargs": "^5.0.0"
}
}

0 comments on commit 2cff42a

Please sign in to comment.