From 2cff42a1041ad2ec3600e23df200e792415ba1ce Mon Sep 17 00:00:00 2001 From: Kokororin Date: Tue, 20 Sep 2016 13:15:10 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=EF=B8=8FFirst=20Commit?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .eslintrc | 10 +++++++ .gitignore | 1 + LICENSE | 21 +++++++++++++++ README.md | 33 +++++++++++++++++++++++ cli.js | 44 +++++++++++++++++++++++++++++++ convert.js | 68 +++++++++++++++++++++++++++++++++++++++++++++++ kaomojify.js | 74 ++++++++++++++++++++++++++++++++++++++++++++++++++++ package.json | 34 ++++++++++++++++++++++++ 8 files changed, 285 insertions(+) create mode 100644 .eslintrc create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100755 cli.js create mode 100644 convert.js create mode 100644 kaomojify.js create mode 100644 package.json diff --git a/.eslintrc b/.eslintrc new file mode 100644 index 0000000..2031742 --- /dev/null +++ b/.eslintrc @@ -0,0 +1,10 @@ +{ + "extends": "crocodile", + "parserOptions": { + "ecmaFeatures": { + "jsx": true, + "es6": true, + "node": true + } + } +} \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b512c09 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +node_modules \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..ccdecf0 --- /dev/null +++ b/LICENSE @@ -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. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..f9b07de --- /dev/null +++ b/README.md @@ -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 -o +``` + +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) \ No newline at end of file diff --git a/cli.js b/cli.js new file mode 100755 index 0000000..c84700f --- /dev/null +++ b/cli.js @@ -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); + } +}); diff --git a/convert.js b/convert.js new file mode 100644 index 0000000..9d9b702 --- /dev/null +++ b/convert.js @@ -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|356)\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; + +} diff --git a/kaomojify.js b/kaomojify.js new file mode 100644 index 0000000..9c6d8cf --- /dev/null +++ b/kaomojify.js @@ -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|356)\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; diff --git a/package.json b/package.json new file mode 100644 index 0000000..130b2cc --- /dev/null +++ b/package.json @@ -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" + } +}