diff --git a/Gruntfile.coffee b/Gruntfile.coffee index 1234ff8..d711587 100644 --- a/Gruntfile.coffee +++ b/Gruntfile.coffee @@ -8,8 +8,7 @@ module.exports = -> /*! <%= package.name %> - v<%= package.version %> - <%= grunt.template.today('yyyy-mm-dd') %> \ ** https://<%= package.homepage %> \ ** Copyright (c) <%= grunt.template.today('yyyy') %> <%= package.author %>; Licensed under <%= package.license %> license. */\ - \ - + """ convert: @@ -41,7 +40,7 @@ module.exports = -> options: js: indentChar: " " - indentSize: 2 + indentSize: 4 jshint: dist: ['dist/asciibots.js', 'dist/jquery/asciibots.js'] diff --git a/dist/asciibots.js b/dist/asciibots.js index 4a46bf8..987bfd8 100644 --- a/dist/asciibots.js +++ b/dist/asciibots.js @@ -1,124 +1,114 @@ -/*! asciibots.js - v0.9 - 2014-08-21 +/*! asciibots.js - v1.0 - 2014-08-31 ** https://walsh9.github.io/asciibots ** Copyright (c) 2014 Matthew Walsh; Licensed under MIT license. */ - var Asciibots = (function() { - - robots = { - "templates": { - "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", - "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", - "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", - "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", - "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", - "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", - "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", - "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", - "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", - "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", - "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", - "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", - "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", - "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", - "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", - "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " - }, - "spareParts": { - "eyes": { - "0": "o o", - "1": "p q", - "2": "q p", - "3": "d b", - "4": "b d", - "5": "ooo", - "6": "[o]", - "7": "9 9", - "8": "6=6", - "9": "u u", - "a": "n n", - "b": "q q", - "c": "d d", - "d": "- -", - "e": "0 0", - "f": "O O" - }, - "mouths": { - "0": "-", - "1": "=", - "2": "o", - "3": "O", - "4": "0", - "5": "#", - "6": "u", - "7": "v", - "8": "n", - "9": "r", - "a": "`", - "b": "^", - "c": "A", - "d": "@", - "e": "e", - "f": "E" - } - } - }; - - var idHelper = { - - isValid: function(id, minlength, maxlength, radix) { - var range = ""; - if (radix < 2 || radix > 36) { - throw "RangeError: radix must be an integer at least 2 and no greater than 36"; - } else if (radix <= 10) { - range = "0-" + String(radix - 1); - } else { - range = "0-9a-" + (radix - 1).toString(radix); - } - var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); - return (id && re.test(id.toLowerCase())); - }, - - random: function(length, radix) { - var id = ""; - for (var i = length; i > 0; i--) { - id = id + Math.floor(Math.random() * radix).toString(radix); - } - return id; - } - - }; - - function oneBot(id) { - var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), - botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; - if (botIdDigits.length >= 4) { - botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); - } - if (botIdDigits.length >= 5) { - botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); - } - return botString; - } - - function replaceParts(id, botString, parts, x, y) { - lines = botString.split("\n"); - newPart = parts[id]; - lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); - return lines.join("\n"); - } - - function botSplit(botString) { - var splitBot = []; - splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; - splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; - splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); - return splitBot; - } - - return { - bot: oneBot - }; - + robots = { + "templates": { + "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", + "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", + "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", + "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", + "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", + "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", + "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", + "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", + "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", + "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", + "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", + "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", + "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", + "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", + "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", + "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " + }, + "spareParts": { + "eyes": { + "0": "o o", + "1": "p q", + "2": "q p", + "3": "d b", + "4": "b d", + "5": "ooo", + "6": "[o]", + "7": "9 9", + "8": "6=6", + "9": "u u", + "a": "n n", + "b": "q q", + "c": "d d", + "d": "- -", + "e": "0 0", + "f": "O O" + }, + "mouths": { + "0": "-", + "1": "=", + "2": "o", + "3": "O", + "4": "0", + "5": "#", + "6": "u", + "7": "v", + "8": "n", + "9": "r", + "a": "`", + "b": "^", + "c": "A", + "d": "@", + "e": "e", + "f": "E" + } + } + }; + var idHelper = { + isValid: function(id, minlength, maxlength, radix) { + var range = "", + idPattern; + if (radix < 2 || radix > 36) { + throw new RangeError("radix must be an integer at least 2 and no greater than 36"); + } else if (radix <= 10) { + range = "0-" + String(radix - 1); + } else { + range = "0-9a-" + (radix - 1).toString(radix); + } + idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); + return (id && idPattern.test(id.toLowerCase())); + }, + random: function(length, radix) { + var id = ""; + for (var i = length; i > 0; i--) { + id = id + Math.floor(Math.random() * radix).toString(radix); + } + return id; + } + }; + var oneBot = function(id) { + var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), + botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; + if (botIdDigits.length >= 4) { + botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); + } + if (botIdDigits.length >= 5) { + botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); + } + return botString; + }; + var replaceParts = function(id, botString, parts, x, y) { + var lines = botString.split("\n"), + newPart = parts[id]; + lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); + return lines.join("\n"); + }; + var botSplit = function(botString) { + var splitBot = []; + splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; + splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; + splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); + return splitBot; + }; + return { + bot: oneBot + }; })(); diff --git a/dist/asciibots.min.js b/dist/asciibots.min.js index 1534ce1..cb13d7a 100644 --- a/dist/asciibots.min.js +++ b/dist/asciibots.min.js @@ -1 +1 @@ -var Asciibots=function(){function a(a){var e=d.isValid(a,3,5,16)?a.split(""):d.random(5,16).split(""),f=c(robots.templates[e[e.length-3]])[0]+c(robots.templates[e[e.length-2]])[1]+c(robots.templates[e[e.length-1]])[2];return e.length>=4&&(f=b(e[e.length-4],f,robots.spareParts.eyes,6,1)),e.length>=5&&(f=b(e[e.length-5],f,robots.spareParts.mouths,7,2)),f}function b(a,b,c,d,e){return lines=b.split("\n"),newPart=c[a],lines[e]=lines[e].slice(0,d)+newPart+lines[e].slice(d+newPart.length),lines.join("\n")}function c(a){var b=[];return b[0]=a.split("\n").slice(0,3).join("\n")+"\n",b[1]=a.split("\n").slice(3,5).join("\n")+"\n",b[2]=a.split("\n").slice(5,7).join("\n"),b}robots={templates:{0:" ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",1:" \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",2:" o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",3:" T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",4:" )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",5:' |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n " |___| " \n .". \n |_| ',6:" .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",7:" Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",8:" .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",9:" _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",a:" .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",b:' .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=" (___) "=o\n (_|_) \n (o|o) ',c:' ,_,_, \n \\9 9/ \n /_-_\\ \n ,"|+ |". \n _\\|+__|/_ \n / | \n _\\ |_ ',d:' .===./` \n /.n n.\\ \n "\\_=_/" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ',e:" __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",f:" _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "},spareParts:{eyes:{0:"o o",1:"p q",2:"q p",3:"d b",4:"b d",5:"ooo",6:"[o]",7:"9 9",8:"6=6",9:"u u",a:"n n",b:"q q",c:"d d",d:"- -",e:"0 0",f:"O O"},mouths:{0:"-",1:"=",2:"o",3:"O",4:"0",5:"#",6:"u",7:"v",8:"n",9:"r",a:"`",b:"^",c:"A",d:"@",e:"e",f:"E"}}};var d={isValid:function(a,b,c,d){var e="";if(2>d||d>36)throw"RangeError: radix must be an integer at least 2 and no greater than 36";e=10>=d?"0-"+String(d-1):"0-9a-"+(d-1).toString(d);var f=new RegExp("^["+e+"]{"+b+","+c+"}$");return a&&f.test(a.toLowerCase())},random:function(a,b){for(var c="",d=a;d>0;d--)c+=Math.floor(Math.random()*b).toString(b);return c}};return{bot:a}}(); \ No newline at end of file +var Asciibots=function(){robots={templates:{0:" ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",1:" \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",2:" o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",3:" T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",4:" )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",5:' |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n " |___| " \n .". \n |_| ',6:" .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",7:" Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",8:" .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",9:" _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",a:" .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",b:' .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=" (___) "=o\n (_|_) \n (o|o) ',c:' ,_,_, \n \\9 9/ \n /_-_\\ \n ,"|+ |". \n _\\|+__|/_ \n / | \n _\\ |_ ',d:' .===./` \n /.n n.\\ \n "\\_=_/" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ',e:" __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",f:" _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "},spareParts:{eyes:{0:"o o",1:"p q",2:"q p",3:"d b",4:"b d",5:"ooo",6:"[o]",7:"9 9",8:"6=6",9:"u u",a:"n n",b:"q q",c:"d d",d:"- -",e:"0 0",f:"O O"},mouths:{0:"-",1:"=",2:"o",3:"O",4:"0",5:"#",6:"u",7:"v",8:"n",9:"r",a:"`",b:"^",c:"A",d:"@",e:"e",f:"E"}}};var a={isValid:function(a,b,c,d){var e,f="";if(2>d||d>36)throw new RangeError("radix must be an integer at least 2 and no greater than 36");return f=10>=d?"0-"+String(d-1):"0-9a-"+(d-1).toString(d),e=new RegExp("^["+f+"]{"+b+","+c+"}$"),a&&e.test(a.toLowerCase())},random:function(a,b){for(var c="",d=a;d>0;d--)c+=Math.floor(Math.random()*b).toString(b);return c}},b=function(b){var e=a.isValid(b,3,5,16)?b.split(""):a.random(5,16).split(""),f=d(robots.templates[e[e.length-3]])[0]+d(robots.templates[e[e.length-2]])[1]+d(robots.templates[e[e.length-1]])[2];return e.length>=4&&(f=c(e[e.length-4],f,robots.spareParts.eyes,6,1)),e.length>=5&&(f=c(e[e.length-5],f,robots.spareParts.mouths,7,2)),f},c=function(a,b,c,d,e){var f=b.split("\n"),g=c[a];return f[e]=f[e].slice(0,d)+g+f[e].slice(d+g.length),f.join("\n")},d=function(a){var b=[];return b[0]=a.split("\n").slice(0,3).join("\n")+"\n",b[1]=a.split("\n").slice(3,5).join("\n")+"\n",b[2]=a.split("\n").slice(5,7).join("\n"),b};return{bot:b}}(); \ No newline at end of file diff --git a/dist/jquery/asciibots.js b/dist/jquery/asciibots.js index 4ced694..a0469c2 100644 --- a/dist/jquery/asciibots.js +++ b/dist/jquery/asciibots.js @@ -1,126 +1,117 @@ -/*! asciibots.js - v0.9 - 2014-08-21 +/*! asciibots.js - v1.0 - 2014-08-31 ** https://walsh9.github.io/asciibots ** Copyright (c) 2014 Matthew Walsh; Licensed under MIT license. */ - (function($) { - - $.fn.asciibot = function(botId) { - return this.each(function() { - $(this).text(oneBot(botId)); - return this; - }); - }; - - robots = { - "templates": { - "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", - "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", - "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", - "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", - "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", - "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", - "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", - "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", - "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", - "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", - "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", - "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", - "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", - "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", - "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", - "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " - }, - "spareParts": { - "eyes": { - "0": "o o", - "1": "p q", - "2": "q p", - "3": "d b", - "4": "b d", - "5": "ooo", - "6": "[o]", - "7": "9 9", - "8": "6=6", - "9": "u u", - "a": "n n", - "b": "q q", - "c": "d d", - "d": "- -", - "e": "0 0", - "f": "O O" - }, - "mouths": { - "0": "-", - "1": "=", - "2": "o", - "3": "O", - "4": "0", - "5": "#", - "6": "u", - "7": "v", - "8": "n", - "9": "r", - "a": "`", - "b": "^", - "c": "A", - "d": "@", - "e": "e", - "f": "E" - } - } - }; - - var idHelper = { - - isValid: function(id, minlength, maxlength, radix) { - var range = ""; - if (radix < 2 || radix > 36) { - throw "RangeError: radix must be an integer at least 2 and no greater than 36"; - } else if (radix <= 10) { - range = "0-" + String(radix - 1); - } else { - range = "0-9a-" + (radix - 1).toString(radix); - } - var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); - return (id && re.test(id.toLowerCase())); - }, - - random: function(length, radix) { - var id = ""; - for (var i = length; i > 0; i--) { - id = id + Math.floor(Math.random() * radix).toString(radix); - } - return id; - } - - }; - - function oneBot(id) { - var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), - botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; - if (botIdDigits.length >= 4) { - botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); - } - if (botIdDigits.length >= 5) { - botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); - } - return botString; - } - - function replaceParts(id, botString, parts, x, y) { - lines = botString.split("\n"); - newPart = parts[id]; - lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); - return lines.join("\n"); - } - - function botSplit(botString) { - var splitBot = []; - splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; - splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; - splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); - return splitBot; - } + $.fn.asciibot = function(botId) { + return this.each(function() { + $(this).text(oneBot(botId)); + return this; + }); + }; + robots = { + "templates": { + "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", + "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", + "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", + "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", + "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", + "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", + "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", + "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", + "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", + "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", + "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", + "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", + "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", + "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", + "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", + "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " + }, + "spareParts": { + "eyes": { + "0": "o o", + "1": "p q", + "2": "q p", + "3": "d b", + "4": "b d", + "5": "ooo", + "6": "[o]", + "7": "9 9", + "8": "6=6", + "9": "u u", + "a": "n n", + "b": "q q", + "c": "d d", + "d": "- -", + "e": "0 0", + "f": "O O" + }, + "mouths": { + "0": "-", + "1": "=", + "2": "o", + "3": "O", + "4": "0", + "5": "#", + "6": "u", + "7": "v", + "8": "n", + "9": "r", + "a": "`", + "b": "^", + "c": "A", + "d": "@", + "e": "e", + "f": "E" + } + } + }; + var idHelper = { + isValid: function(id, minlength, maxlength, radix) { + var range = "", + idPattern; + if (radix < 2 || radix > 36) { + throw new RangeError("radix must be an integer at least 2 and no greater than 36"); + } else if (radix <= 10) { + range = "0-" + String(radix - 1); + } else { + range = "0-9a-" + (radix - 1).toString(radix); + } + idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); + return (id && idPattern.test(id.toLowerCase())); + }, + random: function(length, radix) { + var id = ""; + for (var i = length; i > 0; i--) { + id = id + Math.floor(Math.random() * radix).toString(radix); + } + return id; + } + }; + var oneBot = function(id) { + var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), + botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; + if (botIdDigits.length >= 4) { + botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); + } + if (botIdDigits.length >= 5) { + botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); + } + return botString; + }; + var replaceParts = function(id, botString, parts, x, y) { + var lines = botString.split("\n"), + newPart = parts[id]; + lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); + return lines.join("\n"); + }; + var botSplit = function(botString) { + var splitBot = []; + splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; + splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; + splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); + return splitBot; + }; }(jQuery)); diff --git a/dist/jquery/asciibots.min.js b/dist/jquery/asciibots.min.js index 657c2cf..b3749b2 100644 --- a/dist/jquery/asciibots.min.js +++ b/dist/jquery/asciibots.min.js @@ -1 +1 @@ -!function(a){function b(a){var b=e.isValid(a,3,5,16)?a.split(""):e.random(5,16).split(""),f=d(robots.templates[b[b.length-3]])[0]+d(robots.templates[b[b.length-2]])[1]+d(robots.templates[b[b.length-1]])[2];return b.length>=4&&(f=c(b[b.length-4],f,robots.spareParts.eyes,6,1)),b.length>=5&&(f=c(b[b.length-5],f,robots.spareParts.mouths,7,2)),f}function c(a,b,c,d,e){return lines=b.split("\n"),newPart=c[a],lines[e]=lines[e].slice(0,d)+newPart+lines[e].slice(d+newPart.length),lines.join("\n")}function d(a){var b=[];return b[0]=a.split("\n").slice(0,3).join("\n")+"\n",b[1]=a.split("\n").slice(3,5).join("\n")+"\n",b[2]=a.split("\n").slice(5,7).join("\n"),b}a.fn.asciibot=function(c){return this.each(function(){return a(this).text(b(c)),this})},robots={templates:{0:" ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",1:" \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",2:" o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",3:" T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",4:" )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",5:' |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n " |___| " \n .". \n |_| ',6:" .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",7:" Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",8:" .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",9:" _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",a:" .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",b:' .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=" (___) "=o\n (_|_) \n (o|o) ',c:' ,_,_, \n \\9 9/ \n /_-_\\ \n ,"|+ |". \n _\\|+__|/_ \n / | \n _\\ |_ ',d:' .===./` \n /.n n.\\ \n "\\_=_/" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ',e:" __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",f:" _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "},spareParts:{eyes:{0:"o o",1:"p q",2:"q p",3:"d b",4:"b d",5:"ooo",6:"[o]",7:"9 9",8:"6=6",9:"u u",a:"n n",b:"q q",c:"d d",d:"- -",e:"0 0",f:"O O"},mouths:{0:"-",1:"=",2:"o",3:"O",4:"0",5:"#",6:"u",7:"v",8:"n",9:"r",a:"`",b:"^",c:"A",d:"@",e:"e",f:"E"}}};var e={isValid:function(a,b,c,d){var e="";if(2>d||d>36)throw"RangeError: radix must be an integer at least 2 and no greater than 36";e=10>=d?"0-"+String(d-1):"0-9a-"+(d-1).toString(d);var f=new RegExp("^["+e+"]{"+b+","+c+"}$");return a&&f.test(a.toLowerCase())},random:function(a,b){for(var c="",d=a;d>0;d--)c+=Math.floor(Math.random()*b).toString(b);return c}}}(jQuery); \ No newline at end of file +!function(a){a.fn.asciibot=function(b){return this.each(function(){return a(this).text(c(b)),this})},robots={templates:{0:" ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ",1:" \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ",2:" o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ",3:" T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ",4:" )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ",5:' |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n " |___| " \n .". \n |_| ',6:" .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ",7:" Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .",8:" .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ",9:" _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ",a:" .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ",b:' .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=" (___) "=o\n (_|_) \n (o|o) ',c:' ,_,_, \n \\9 9/ \n /_-_\\ \n ,"|+ |". \n _\\|+__|/_ \n / | \n _\\ |_ ',d:' .===./` \n /.n n.\\ \n "\\_=_/" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ',e:" __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ",f:" _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ "},spareParts:{eyes:{0:"o o",1:"p q",2:"q p",3:"d b",4:"b d",5:"ooo",6:"[o]",7:"9 9",8:"6=6",9:"u u",a:"n n",b:"q q",c:"d d",d:"- -",e:"0 0",f:"O O"},mouths:{0:"-",1:"=",2:"o",3:"O",4:"0",5:"#",6:"u",7:"v",8:"n",9:"r",a:"`",b:"^",c:"A",d:"@",e:"e",f:"E"}}};var b={isValid:function(a,b,c,d){var e,f="";if(2>d||d>36)throw new RangeError("radix must be an integer at least 2 and no greater than 36");return f=10>=d?"0-"+String(d-1):"0-9a-"+(d-1).toString(d),e=new RegExp("^["+f+"]{"+b+","+c+"}$"),a&&e.test(a.toLowerCase())},random:function(a,b){for(var c="",d=a;d>0;d--)c+=Math.floor(Math.random()*b).toString(b);return c}},c=function(a){var c=b.isValid(a,3,5,16)?a.split(""):b.random(5,16).split(""),f=e(robots.templates[c[c.length-3]])[0]+e(robots.templates[c[c.length-2]])[1]+e(robots.templates[c[c.length-1]])[2];return c.length>=4&&(f=d(c[c.length-4],f,robots.spareParts.eyes,6,1)),c.length>=5&&(f=d(c[c.length-5],f,robots.spareParts.mouths,7,2)),f},d=function(a,b,c,d,e){var f=b.split("\n"),g=c[a];return f[e]=f[e].slice(0,d)+g+f[e].slice(d+g.length),f.join("\n")},e=function(a){var b=[];return b[0]=a.split("\n").slice(0,3).join("\n")+"\n",b[1]=a.split("\n").slice(3,5).join("\n")+"\n",b[2]=a.split("\n").slice(5,7).join("\n"),b}}(jQuery); \ No newline at end of file diff --git a/package.json b/package.json index 0cd256c..50fd78d 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "asciibots.js", - "version": "0.9", + "version": "1.0", "description": "ASCII Robots", "main": "dist/asciibots.js", "scripts": { diff --git a/src/idhelper.js b/src/idhelper.js index 41a0fc5..6dae655 100644 --- a/src/idhelper.js +++ b/src/idhelper.js @@ -1,25 +1,22 @@ - var idHelper = { - - isValid: function (id, minlength, maxlength, radix) { - var range = ""; - if (radix < 2 || radix > 36) { - throw "RangeError: radix must be an integer at least 2 and no greater than 36"; - } else if (radix <= 10) { - range = "0-" + String(radix - 1); - } else { - range = "0-9a-" + (radix - 1).toString(radix); + isValid: function(id, minlength, maxlength, radix) { + var range = "", + idPattern; + if (radix < 2 || radix > 36) { + throw new RangeError("radix must be an integer at least 2 and no greater than 36"); + } else if (radix <= 10) { + range = "0-" + String(radix - 1); + } else { + range = "0-9a-" + (radix - 1).toString(radix); + } + idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); + return (id && idPattern.test(id.toLowerCase())); + }, + random: function(length, radix) { + var id = ""; + for (var i = length; i > 0; i--) { + id = id + Math.floor(Math.random() * radix).toString(radix); + } + return id; } - var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); - return ( id && re.test(id.toLowerCase()) ); - }, - - random: function (length, radix) { - var id = ""; - for (var i = length; i > 0; i--) { - id = id + Math.floor(Math.random() * radix).toString(radix); - } - return id; - } - }; \ No newline at end of file diff --git a/src/jquery-intro.js b/src/jquery-intro.js index d3a3b6a..fd07e73 100644 --- a/src/jquery-intro.js +++ b/src/jquery-intro.js @@ -1,9 +1,7 @@ (function ($) { - - $.fn.asciibot = function( botId ) { - return this.each( function() { - $( this ).text( oneBot(botId) ); - return this; - }); - }; - \ No newline at end of file + $.fn.asciibot = function(botId) { + return this.each(function () { + $(this).text(oneBot(botId)); + return this; + }); + }; \ No newline at end of file diff --git a/src/shared.js b/src/shared.js index 15eb859..5a1d701 100644 --- a/src/shared.js +++ b/src/shared.js @@ -1,28 +1,26 @@ - function oneBot(id) { - var botIdDigits = idHelper.isValid(id,3,5,16) ? id.split("") : idHelper.random (5,16).split(""), - botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; - if (botIdDigits.length >= 4) { +var oneBot = function(id) { + var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), + botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; + if (botIdDigits.length >= 4) { botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); - } - if (botIdDigits.length >= 5) { + } + if (botIdDigits.length >= 5) { botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); - } + } return botString; - } - - function replaceParts(id, botString, parts, x, y) { - lines = botString.split("\n"); - newPart = parts[id]; +}; +var replaceParts = function(id, botString, parts, x, y) { + var lines = botString.split("\n"), + newPart = parts[id]; lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); return lines.join("\n"); - } - - function botSplit(botString) { +}; +var botSplit = function(botString) { var splitBot = []; splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); return splitBot; - } \ No newline at end of file +}; \ No newline at end of file diff --git a/src/vanilla-intro.js b/src/vanilla-intro.js index 8ec9ebb..96440d7 100644 --- a/src/vanilla-intro.js +++ b/src/vanilla-intro.js @@ -1,2 +1 @@ -var Asciibots = (function () { - \ No newline at end of file +var Asciibots = (function () { \ No newline at end of file diff --git a/src/vanilla-outro.js b/src/vanilla-outro.js index e2860ce..5410b98 100644 --- a/src/vanilla-outro.js +++ b/src/vanilla-outro.js @@ -1,6 +1,4 @@ - - return { - bot: oneBot - }; - + return { + bot: oneBot + }; })(); \ No newline at end of file diff --git a/www/dl/asciibots.zip b/www/dl/asciibots.zip index 5d80a87..afc6eac 100644 Binary files a/www/dl/asciibots.zip and b/www/dl/asciibots.zip differ diff --git a/www/dl/jquery/asciibots.zip b/www/dl/jquery/asciibots.zip index 6c019d7..c0474fd 100644 Binary files a/www/dl/jquery/asciibots.zip and b/www/dl/jquery/asciibots.zip differ diff --git a/www/js/asciibots.js b/www/js/asciibots.js index 4a46bf8..987bfd8 100644 --- a/www/js/asciibots.js +++ b/www/js/asciibots.js @@ -1,124 +1,114 @@ -/*! asciibots.js - v0.9 - 2014-08-21 +/*! asciibots.js - v1.0 - 2014-08-31 ** https://walsh9.github.io/asciibots ** Copyright (c) 2014 Matthew Walsh; Licensed under MIT license. */ - var Asciibots = (function() { - - robots = { - "templates": { - "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", - "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", - "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", - "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", - "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", - "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", - "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", - "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", - "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", - "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", - "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", - "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", - "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", - "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", - "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", - "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " - }, - "spareParts": { - "eyes": { - "0": "o o", - "1": "p q", - "2": "q p", - "3": "d b", - "4": "b d", - "5": "ooo", - "6": "[o]", - "7": "9 9", - "8": "6=6", - "9": "u u", - "a": "n n", - "b": "q q", - "c": "d d", - "d": "- -", - "e": "0 0", - "f": "O O" - }, - "mouths": { - "0": "-", - "1": "=", - "2": "o", - "3": "O", - "4": "0", - "5": "#", - "6": "u", - "7": "v", - "8": "n", - "9": "r", - "a": "`", - "b": "^", - "c": "A", - "d": "@", - "e": "e", - "f": "E" - } - } - }; - - var idHelper = { - - isValid: function(id, minlength, maxlength, radix) { - var range = ""; - if (radix < 2 || radix > 36) { - throw "RangeError: radix must be an integer at least 2 and no greater than 36"; - } else if (radix <= 10) { - range = "0-" + String(radix - 1); - } else { - range = "0-9a-" + (radix - 1).toString(radix); - } - var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); - return (id && re.test(id.toLowerCase())); - }, - - random: function(length, radix) { - var id = ""; - for (var i = length; i > 0; i--) { - id = id + Math.floor(Math.random() * radix).toString(radix); - } - return id; - } - - }; - - function oneBot(id) { - var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), - botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; - if (botIdDigits.length >= 4) { - botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); - } - if (botIdDigits.length >= 5) { - botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); - } - return botString; - } - - function replaceParts(id, botString, parts, x, y) { - lines = botString.split("\n"); - newPart = parts[id]; - lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); - return lines.join("\n"); - } - - function botSplit(botString) { - var splitBot = []; - splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; - splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; - splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); - return splitBot; - } - - return { - bot: oneBot - }; - + robots = { + "templates": { + "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", + "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", + "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", + "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", + "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", + "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", + "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", + "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", + "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", + "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", + "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", + "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", + "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", + "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", + "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", + "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " + }, + "spareParts": { + "eyes": { + "0": "o o", + "1": "p q", + "2": "q p", + "3": "d b", + "4": "b d", + "5": "ooo", + "6": "[o]", + "7": "9 9", + "8": "6=6", + "9": "u u", + "a": "n n", + "b": "q q", + "c": "d d", + "d": "- -", + "e": "0 0", + "f": "O O" + }, + "mouths": { + "0": "-", + "1": "=", + "2": "o", + "3": "O", + "4": "0", + "5": "#", + "6": "u", + "7": "v", + "8": "n", + "9": "r", + "a": "`", + "b": "^", + "c": "A", + "d": "@", + "e": "e", + "f": "E" + } + } + }; + var idHelper = { + isValid: function(id, minlength, maxlength, radix) { + var range = "", + idPattern; + if (radix < 2 || radix > 36) { + throw new RangeError("radix must be an integer at least 2 and no greater than 36"); + } else if (radix <= 10) { + range = "0-" + String(radix - 1); + } else { + range = "0-9a-" + (radix - 1).toString(radix); + } + idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); + return (id && idPattern.test(id.toLowerCase())); + }, + random: function(length, radix) { + var id = ""; + for (var i = length; i > 0; i--) { + id = id + Math.floor(Math.random() * radix).toString(radix); + } + return id; + } + }; + var oneBot = function(id) { + var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), + botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; + if (botIdDigits.length >= 4) { + botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); + } + if (botIdDigits.length >= 5) { + botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); + } + return botString; + }; + var replaceParts = function(id, botString, parts, x, y) { + var lines = botString.split("\n"), + newPart = parts[id]; + lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); + return lines.join("\n"); + }; + var botSplit = function(botString) { + var splitBot = []; + splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; + splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; + splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); + return splitBot; + }; + return { + bot: oneBot + }; })(); diff --git a/www/js/jquery/asciibots.js b/www/js/jquery/asciibots.js index 4ced694..a0469c2 100644 --- a/www/js/jquery/asciibots.js +++ b/www/js/jquery/asciibots.js @@ -1,126 +1,117 @@ -/*! asciibots.js - v0.9 - 2014-08-21 +/*! asciibots.js - v1.0 - 2014-08-31 ** https://walsh9.github.io/asciibots ** Copyright (c) 2014 Matthew Walsh; Licensed under MIT license. */ - (function($) { - - $.fn.asciibot = function(botId) { - return this.each(function() { - $(this).text(oneBot(botId)); - return this; - }); - }; - - robots = { - "templates": { - "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", - "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", - "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", - "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", - "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", - "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", - "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", - "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", - "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", - "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", - "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", - "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", - "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", - "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", - "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", - "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " - }, - "spareParts": { - "eyes": { - "0": "o o", - "1": "p q", - "2": "q p", - "3": "d b", - "4": "b d", - "5": "ooo", - "6": "[o]", - "7": "9 9", - "8": "6=6", - "9": "u u", - "a": "n n", - "b": "q q", - "c": "d d", - "d": "- -", - "e": "0 0", - "f": "O O" - }, - "mouths": { - "0": "-", - "1": "=", - "2": "o", - "3": "O", - "4": "0", - "5": "#", - "6": "u", - "7": "v", - "8": "n", - "9": "r", - "a": "`", - "b": "^", - "c": "A", - "d": "@", - "e": "e", - "f": "E" - } - } - }; - - var idHelper = { - - isValid: function(id, minlength, maxlength, radix) { - var range = ""; - if (radix < 2 || radix > 36) { - throw "RangeError: radix must be an integer at least 2 and no greater than 36"; - } else if (radix <= 10) { - range = "0-" + String(radix - 1); - } else { - range = "0-9a-" + (radix - 1).toString(radix); - } - var re = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); - return (id && re.test(id.toLowerCase())); - }, - - random: function(length, radix) { - var id = ""; - for (var i = length; i > 0; i--) { - id = id + Math.floor(Math.random() * radix).toString(radix); - } - return id; - } - - }; - - function oneBot(id) { - var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), - botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + - botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; - if (botIdDigits.length >= 4) { - botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); - } - if (botIdDigits.length >= 5) { - botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); - } - return botString; - } - - function replaceParts(id, botString, parts, x, y) { - lines = botString.split("\n"); - newPart = parts[id]; - lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); - return lines.join("\n"); - } - - function botSplit(botString) { - var splitBot = []; - splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; - splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; - splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); - return splitBot; - } + $.fn.asciibot = function(botId) { + return this.each(function() { + $(this).text(oneBot(botId)); + return this; + }); + }; + robots = { + "templates": { + "0": " ___T_ \n | o o | \n |__-__| \n /| []|\\ \n ()/|___|\\() \n |_|_| \n /_|_\\ ", + "1": " \\.===./ \n | b d | \n \\_=_/ \n o==|ooo|==o \n |___| \n .'._.'. \n |_| |_| ", + "2": " o___o \n //0-0\\\\ \n |\\_-_/| \n /|(\\)|\\ \n d |___| b \n . \\_/ . \n . .:::.. . ", + "3": " T___ \n |[o]| \n \\_-_/ \n 7--|=0=|--< \n |___| \n // \\\\ \n _\\\\ //_ ", + "4": " )_( \n |ooo| \n |_#_| \n .-._/___\\_.-. \n ; \\___/ ; \n ( ) \n __) (__ ", + "5": " |---| \n |6=6| \n |_o_| \n}-. /\\--o/\\ .-{\n \" |___| \" \n .\". \n |_| ", + "6": " .---. \n } - - { \n \\_0_/ \n .=[::+]=. \n ]=' [___] '=[ \n /| |\\ \n [_] [_] ", + "7": " Y__ \n _/o o\\_ \n \\_o_/ \n )=o=|L88|=o=( \n )=o=|___|=o=( \n . /___\\ . \n. ..:::::::. .", + "8": " .===. \n //d d\\\\ \n \\\\_u_// \n ,=|x|=. \n 'c/_\\ 'c \n /| |\\ \n (0) (0) ", + "9": " _._._ \n -)o o(- \n \\_=_/ \n()ooo|\\=/|ooo()\n |___| \n |_| \n (ooo) ", + "a": " .=._,=. \n ' (q q) ` \n _)-(_ \n.'c .\"|_|\". n`.\n'--' /_\\ `--'\n _// \\\\_ \n /_o| |o_\\ ", + "b": " .-. \n ._(u u)_. \n (_-_) \n .=(+++)=. \no=\" (___) \"=o\n (_|_) \n (o|o) ", + "c": " ,_,_, \n \\9 9/ \n /_-_\\ \n ,\"|+ |\". \n _\\|+__|/_ \n / | \n _\\ |_ ", + "d": " .===./` \n /.n n.\\ \n \"\\_=_/\" \n (m9\\:::/\\ \n /___\\6 \n [] [] \n /:] [:\\ ", + "e": " __i \n [p q] \n ]-[ \n >===]__o[===< \n [o__] \n ]| |[ \n [_| |_] ", + "f": " _ _,_,_ _ \n \\( q p )/ \n \\_\"_/ \n .==|>o<|==:=L\n '=c|___| \n /7 [| \n \\/7 [|_ " + }, + "spareParts": { + "eyes": { + "0": "o o", + "1": "p q", + "2": "q p", + "3": "d b", + "4": "b d", + "5": "ooo", + "6": "[o]", + "7": "9 9", + "8": "6=6", + "9": "u u", + "a": "n n", + "b": "q q", + "c": "d d", + "d": "- -", + "e": "0 0", + "f": "O O" + }, + "mouths": { + "0": "-", + "1": "=", + "2": "o", + "3": "O", + "4": "0", + "5": "#", + "6": "u", + "7": "v", + "8": "n", + "9": "r", + "a": "`", + "b": "^", + "c": "A", + "d": "@", + "e": "e", + "f": "E" + } + } + }; + var idHelper = { + isValid: function(id, minlength, maxlength, radix) { + var range = "", + idPattern; + if (radix < 2 || radix > 36) { + throw new RangeError("radix must be an integer at least 2 and no greater than 36"); + } else if (radix <= 10) { + range = "0-" + String(radix - 1); + } else { + range = "0-9a-" + (radix - 1).toString(radix); + } + idPattern = new RegExp("^[" + range + "]{" + minlength + "," + maxlength + "}$"); + return (id && idPattern.test(id.toLowerCase())); + }, + random: function(length, radix) { + var id = ""; + for (var i = length; i > 0; i--) { + id = id + Math.floor(Math.random() * radix).toString(radix); + } + return id; + } + }; + var oneBot = function(id) { + var botIdDigits = idHelper.isValid(id, 3, 5, 16) ? id.split("") : idHelper.random(5, 16).split(""), + botString = botSplit(robots.templates[botIdDigits[botIdDigits.length - 3]])[0] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 2]])[1] + + botSplit(robots.templates[botIdDigits[botIdDigits.length - 1]])[2]; + if (botIdDigits.length >= 4) { + botString = replaceParts(botIdDigits[botIdDigits.length - 4], botString, robots.spareParts.eyes, 6, 1); + } + if (botIdDigits.length >= 5) { + botString = replaceParts(botIdDigits[botIdDigits.length - 5], botString, robots.spareParts.mouths, 7, 2); + } + return botString; + }; + var replaceParts = function(id, botString, parts, x, y) { + var lines = botString.split("\n"), + newPart = parts[id]; + lines[y] = lines[y].slice(0, x) + newPart + lines[y].slice(x + newPart.length); + return lines.join("\n"); + }; + var botSplit = function(botString) { + var splitBot = []; + splitBot[0] = botString.split("\n").slice(0, 3).join("\n") + "\n"; + splitBot[1] = botString.split("\n").slice(3, 5).join("\n") + "\n"; + splitBot[2] = botString.split("\n").slice(5, 7).join("\n"); + return splitBot; + }; }(jQuery));