Comparing version 0.0.8 to 0.0.9
139
lang-mini.js
@@ -116,2 +116,4 @@ let are_equal = require('deep-equal'); | ||
//let node_err = new Error(); | ||
// may change to the jq_type code. | ||
@@ -133,2 +135,4 @@ let tof = (obj, t1) => { | ||
//console.log('typeof obj ' + typeof obj); | ||
@@ -161,3 +165,5 @@ //console.log('obj === null ' + (obj === null)); | ||
if (obj instanceof RegExp) res = 'regex'; | ||
if (obj instanceof Error) { | ||
res = 'error'; | ||
} else if (obj instanceof RegExp) res = 'regex'; | ||
@@ -209,6 +215,6 @@ // For running inside Node. | ||
let is_defined = (value) => { | ||
// tof or typeof | ||
// tof or typeof | ||
return typeof (value) != 'undefined'; | ||
}, | ||
return typeof (value) != 'undefined'; | ||
}, | ||
isdef = is_defined; | ||
@@ -1771,11 +1777,7 @@ | ||
}); | ||
fn.apply(this, a); | ||
}) | ||
} | ||
} | ||
return fn_res; | ||
} | ||
@@ -1787,4 +1789,4 @@ | ||
Object.defineProperty(this, '_bound_events', { | ||
value: {} | ||
}); | ||
value: {} | ||
}); | ||
} | ||
@@ -1801,3 +1803,5 @@ | ||
if (sig == '[s]') { | ||
//console.log('sig', sig); | ||
if (sig === '[s]') { | ||
let target = this; | ||
@@ -1831,3 +1835,3 @@ let event_name = a[0]; | ||
if (sig == '[s,a]') { | ||
if (sig === '[s,a]') { | ||
let be = this._bound_events; | ||
@@ -1857,3 +1861,3 @@ | ||
if (sig == '[s,B]') { | ||
if (sig === '[s,B]') { | ||
let be = this._bound_events; | ||
@@ -1882,3 +1886,3 @@ let bgh = this._bound_general_handler; | ||
if (sig == '[s,b]') { | ||
if (sig === '[s,b]') { | ||
let be = this._bound_events; | ||
@@ -1907,3 +1911,3 @@ let bgh = this._bound_general_handler; | ||
if (sig == '[s,n]') { | ||
if (sig === '[s,n]') { | ||
let be = this._bound_events; | ||
@@ -1932,3 +1936,3 @@ let bgh = this._bound_general_handler; | ||
if (sig == '[s,o]') { | ||
if (sig === '[s,o]' || sig === '[s,?]') { | ||
let be = this._bound_events; | ||
@@ -2093,2 +2097,87 @@ let bgh = this._bound_general_handler; | ||
var vectorify = n_fn => { | ||
let fn_res = fp(function (a, sig) { | ||
//console.log('vectorified sig ' + sig); | ||
if (a.l > 2) { | ||
var res = a[0]; | ||
for (var c = 1, l = a.l; c < l; c++) { | ||
res = fn_res(res, a[c]); | ||
// console.log('res ' + res); | ||
} | ||
return res; | ||
} else { | ||
if (sig == '[n,n]') { | ||
return n_fn(a[0], a[1]); | ||
} else { | ||
// will need go through the first array, and the 2nd... but | ||
// will need to compare them. | ||
var ats = atof(a); | ||
//console.log('ats ' + stringify(ats)); | ||
if (ats[0] == 'array') { | ||
if (ats[1] == 'number') { | ||
var res = [], | ||
n = a[1], l = a[0].length, c; | ||
for (c = 0; c < l; c++) { | ||
res.push(fn_res(a[0][c], n)); | ||
} | ||
//each(a[0], (v, i) => { | ||
// res.push(fn_res(v, n)); | ||
//}); | ||
return res; | ||
} | ||
if (ats[1] == 'array') { | ||
if (ats[0].length != ats[1].length) { | ||
throw 'vector array lengths mismatch'; | ||
} else { | ||
var arr2 = a[1], l = a[0].length, c, res = new Array(l); | ||
for (c = 0; c < l; c++) { | ||
res[c] = fn_res(a[0][c], arr2[c]); | ||
} | ||
//each(a[0], (v, i) => { | ||
// res.push(fn_res(v, arr2[i])); | ||
//}); | ||
return res; | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
}); | ||
return fn_res; | ||
}; | ||
const n_add = (n1, n2) => n1 + n2, | ||
n_subtract = (n1, n2) => n1 - n2, | ||
n_multiply = (n1, n2) => n1 * n2, | ||
n_divide = (n1, n2) => n1 / n2; | ||
const v_add = vectorify(n_add), | ||
v_subtract = vectorify(n_subtract), | ||
v_multiply = vectorify(n_multiply), | ||
v_divide = vectorify(n_divide); | ||
var vector_magnitude = function (vector) { | ||
// may calculate magnitudes of larger dimension vectors too. | ||
// alert(tof(vector[0])); | ||
// alert(vector[0] ^ 2); | ||
var res = Math.sqrt((Math.pow(vector[0], 2)) + (Math.pow(vector[1], 2))); | ||
return res; | ||
}; | ||
var distance_between_points = function (points) { | ||
var offset = v_subtract(points[1], points[0]); | ||
//console.log('offset ' + stringify(offset)); | ||
return vector_magnitude(offset); | ||
} | ||
var p = Evented_Class.prototype; | ||
@@ -2100,2 +2189,6 @@ p.raise = p.raise_event; | ||
// Nice if this had some vector manipulation functions. | ||
// lang-plus | ||
let lang_mini = { | ||
@@ -2150,5 +2243,17 @@ 'each': each, | ||
'prom': prom, | ||
'Evented_Class': Evented_Class | ||
'Evented_Class': Evented_Class, | ||
'vectorify': vectorify, | ||
'v_add': v_add, | ||
'v_subtract': v_subtract, | ||
'v_multiply': v_multiply, | ||
'v_divide': v_divide, | ||
'vector_magnitude': vector_magnitude, | ||
'distance_between_points': distance_between_points | ||
// v_add v_subtract v_multiply v_divide | ||
}; | ||
module.exports = lang_mini; |
@@ -17,3 +17,3 @@ { | ||
}, | ||
"version": "0.0.8" | ||
"version": "0.0.9" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
55638
1797