diff --git a/api.js b/api.js index 43795a2..3e41c00 100644 --- a/api.js +++ b/api.js @@ -1,88 +1,99 @@ -!function(scope) { - var latin = "abcdefghijklmnopqrstuvwxyz" - var bet = latin - var join = "".join - var split = "".split - var lower = "".toLowerCase - var digit = /^\d+$/ - var round = Math.round - var repeating = /^(.)\1+$/ - var glyph = /[\u0300-\u036f]/g - var norm = "".normalize - var base = norm ? bass : basic +!function(esta) { + var api = create() + var nombre = "numerologia" + typeof module != "undefined" && module.exports + ? module.exports = api + : esta[nombre] = api - function bass(txt) { - return norm.call(txt, "NFD").replace(glyph, "") - } + function create(bet) { + var latin = "abcdefghijklmnopqrstuvwxyz" + var join = "".join + var split = "".split + var lower = "".toLowerCase + var digit = /^\d+$/ + var round = Math.round + var repeating = /^(.)\1+$/ + var glyph = /[\u0300-\u036f]/g + var norm = "".normalize + var base = norm ? bass : basic + bet = bet ? lower.call(bet) : latin - function basic(txt) { - return "" + txt - } + function bass(txt) { + return norm.call(txt, "NFD").replace(glyph, "") + } - function key(n) { - return modulo(digit.test(n) ? n : place(n)) - } + function basic(txt) { + return "" + txt + } - function modulo(n) { - return +n ? n % 9 || 9 : 0 - } + function key(n) { + return modulo(digit.test(n) ? n : place(n)) + } - function place(letter) { - letter = base(lower.call(letter)) - return bet.indexOf(letter) + 1 - } + function modulo(n) { + return +n ? n % 9 || 9 : 0 + } - function stack(txt) { - var how = txt instanceof Array ? join : split - return how.call(txt, "") - } + function place(letter) { + letter = base(lower.call(letter)) + return bet.indexOf(letter) + 1 + } - function suma(txt) { - txt = stack(txt) - var i = txt.length - var suma = 0 - var next - while (i--) { - next = txt[i] - next = key(next) - suma += next > 0 ? +next : 0 + function stack(txt) { + var how = txt instanceof Array ? join : split + return how.call(txt, "") } - return round(suma) - } - function raiz(txt) { - var n = suma(txt) - return n < 10 ? n : raiz(n) - } + function suma(txt) { + txt = stack(txt) + var i = txt.length + var suma = 0 + var next + while (i--) { + next = txt[i] + next = key(next) + suma += next > 0 ? +next : 0 + } + return round(suma) + } - function numero(txt) { - var n = suma(txt) - return n < 10 || rep(n) ? n : numero(n) - } + function raiz(txt) { + var n = suma(txt) + return n < 10 ? n : raiz(n) + } - function rep(dig) { - return repeating.test(dig) - } + function numero(txt) { + var n = suma(txt) + return n < 10 || rep(n) ? n : numero(n) + } - function api(method, txt) { - return api[method](txt) - } + function rep(dig) { + return repeating.test(dig) + } - api.base = base - api.bass = bass - api.basic = basic - api.key = key - api.modulo = modulo - api.num = numero - api.numero = numero - api.place = place - api.raiz = raiz - api.rep = rep - api.root = raiz - api.sum = suma - api.suma = suma + function rep(dig) { + return repeating.test(dig) + } - typeof module != "undefined" && module.exports - ? module.exports = api - : scope.numerologia = api + function api(method, txt) { + return api[method](txt) + } + + api.base = base + api.bass = bass + api.basic = basic + api.create = create + api.key = key + api.modulo = modulo + api.num = numero + api.numero = numero + api.place = place + api.raiz = raiz + api.rep = rep + api.root = raiz + api.sum = suma + api.suma = suma + + return api + } }(this) diff --git a/test.js b/test.js index 7f86deb..c76f13e 100644 --- a/test.js +++ b/test.js @@ -63,6 +63,7 @@ assert.ok(api.suma === api.sum) console.log("ok alias") assert.ok(api("raiz", 11) === api.raiz("11")) +assert.ok(api.create("!@#").raiz("!!") === 2) console.log("ok api") console.log("=)\n") diff --git a/www.js b/www.js index 8d94ad7..707ae1b 100644 --- a/www.js +++ b/www.js @@ -1,5 +1,5 @@ -!function(scope) { - var api = scope.numerologia +!function(esta) { + var api = esta.numerologia var form = document.getElementById("formulario") var key = "_" var text = form[key]