fix num validation & upgrade jesse's path check

This commit is contained in:
Mark Nadal 2015-10-23 08:43:58 -07:00
parent 13b8ff9ada
commit ba5dc00b6a
2 changed files with 16 additions and 3 deletions

5
gun.js
View File

@ -476,7 +476,8 @@
var gun = this.chain();
cb = cb || function(){};
opt = opt || {};
if((path !== null && !path) || !Gun.text.is(path = path.join? path.join('.') : path + '')){ return }
if(!Gun.text.is(path = Gun.text.is(path)? path || null : Gun.num.is(path)? (path + '') : Gun.list.is(path)? path.join('.') : path)){ return cb.call(gun, {err: Gun.log("Invalid path '" + path + "'!")}), gun }
//if((path !== null && !path) || !Gun.text.is(path = path.join? path.join('.') : path + '')){ return }
if(!gun.back._.at){ return cb.call(gun, {err: Gun.log("No context!")}), gun }
gun.back.on(function($, node){
@ -764,7 +765,7 @@
Util.bi.is = function(b){ return (b instanceof Boolean || typeof b == 'boolean')? true : false }
Util.num = {};
Util.num.is = function(n){
return ((n===0)? true : (!isNaN(n) && !Util.bi.is(n) && !Util.list.is(n) && !Util.text.is(n))? true : false );
return !Util.list.is(n) && (Infinity === n || n - parseFloat(n) + 1 >= 0); // jquery doesn't check for Infinity.
}
Util.text = {};
Util.text.is = function(t){ return typeof t == 'string'? true : false }

View File

@ -9,7 +9,7 @@ describe('Gun', function(){
var t = {};
describe('Utility', function(){
var u;
/* // causes logger to no longer log.
it('verbose console.log debugging', function(done) {
@ -38,6 +38,8 @@ describe('Gun', function(){
it('binary', function(){
expect(Gun.bi.is(false)).to.be(true);
expect(Gun.bi.is(true)).to.be(true);
expect(Gun.bi.is(u)).to.be(false);
expect(Gun.bi.is(null)).to.be(false);
expect(Gun.bi.is('')).to.be(false);
expect(Gun.bi.is('a')).to.be(false);
expect(Gun.bi.is(0)).to.be(false);
@ -52,6 +54,8 @@ describe('Gun', function(){
expect(Gun.num.is(0)).to.be(true);
expect(Gun.num.is(1)).to.be(true);
expect(Gun.num.is(Infinity)).to.be(true);
expect(Gun.num.is(u)).to.be(false);
expect(Gun.num.is(null)).to.be(false);
expect(Gun.num.is(NaN)).to.be(false);
expect(Gun.num.is('')).to.be(false);
expect(Gun.num.is('a')).to.be(false);
@ -66,6 +70,8 @@ describe('Gun', function(){
it('text',function(){
expect(Gun.text.is('')).to.be(true);
expect(Gun.text.is('a')).to.be(true);
expect(Gun.text.is(u)).to.be(false);
expect(Gun.text.is(null)).to.be(false);
expect(Gun.text.is(false)).to.be(false);
expect(Gun.text.is(true)).to.be(false);
expect(Gun.text.is(0)).to.be(false);
@ -79,6 +85,8 @@ describe('Gun', function(){
it('list',function(){
expect(Gun.list.is([])).to.be(true);
expect(Gun.list.is([1])).to.be(true);
expect(Gun.list.is(u)).to.be(false);
expect(Gun.list.is(null)).to.be(false);
expect(Gun.list.is(0)).to.be(false);
expect(Gun.list.is(1)).to.be(false);
expect(Gun.list.is('')).to.be(false);
@ -92,6 +100,8 @@ describe('Gun', function(){
it('obj',function(){
expect(Gun.obj.is({})).to.be(true);
expect(Gun.obj.is({a:1})).to.be(true);
expect(Gun.obj.is(u)).to.be(false);
expect(Gun.obj.is(null)).to.be(false);
expect(Gun.obj.is(0)).to.be(false);
expect(Gun.obj.is(1)).to.be(false);
expect(Gun.obj.is('')).to.be(false);
@ -104,6 +114,8 @@ describe('Gun', function(){
});
it('fns',function(){
expect(Gun.fns.is(function(){})).to.be(true);
expect(Gun.fns.is(u)).to.be(false);
expect(Gun.fns.is(null)).to.be(false);
expect(Gun.fns.is('')).to.be(false);
expect(Gun.fns.is('a')).to.be(false);
expect(Gun.fns.is(0)).to.be(false);