Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

create pattern #29

Merged
merged 2 commits into from
Jul 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 84 additions & 73 deletions api.js
Original file line number Diff line number Diff line change
@@ -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)
ryanve marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 2 additions & 2 deletions www.js
Original file line number Diff line number Diff line change
@@ -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]
Expand Down