can-reflect
Advanced tools
Comparing version 0.0.2 to 0.0.3
{ | ||
"name": "can-reflect", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"description": "reflection on unknown data types", | ||
@@ -5,0 +5,0 @@ "homepage": "http://canjs.com", |
@@ -106,2 +106,14 @@ var QUnit = require('steal-qunit'); | ||
}); | ||
function ArrayLike() {} | ||
ArrayLike.prototype = new Array(); | ||
ArrayLike.prototype[canSymbol.iterator] = null; | ||
var noniterator = new ArrayLike(); | ||
noniterator.push("a"); | ||
shapeReflections.eachIndex(noniterator, function(value, index){ | ||
QUnit.equal(index, 0); | ||
QUnit.equal(value,"a"); | ||
}); | ||
}); | ||
@@ -108,0 +120,0 @@ |
@@ -18,10 +18,9 @@ var canSymbol = require("can-symbol"); | ||
eachIndex: function(list, callback, context){ | ||
var iter; | ||
var iter, iterator = list[canSymbol.iterator]; | ||
if(Array.isArray(list)) { | ||
// do nothing | ||
} else if(typeReflections.isIteratorLike(list)) { | ||
// we are looping through an interator | ||
// we are looping through an iterator | ||
iter = list; | ||
} else { | ||
var iterator = list[canSymbol.iterator]; | ||
} else if(iterator) { | ||
iter = iterator.call(list); | ||
@@ -28,0 +27,0 @@ } |
@@ -40,4 +40,8 @@ var QUnit = require('steal-qunit'); | ||
}), "object with 0 length"); | ||
var symboled = {}; | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isListLike"), false); | ||
ok(!typeReflections.isListLike(symboled), "!@@can.isListLike"); | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isListLike"), true); | ||
ok(typeReflections.isListLike(symboled), "@@can.isListLike"); | ||
if(typeof document !== "undefined") { | ||
@@ -56,2 +60,7 @@ var ul = document.createElement("ul"); | ||
ok(typeReflections.isMapLike([]), "Array"); | ||
var symboled = {}; | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isMapLike"), false); | ||
ok(!typeReflections.isMapLike(symboled), "!@@can.isMapLike"); | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isMapLike"), true); | ||
ok(typeReflections.isMapLike(symboled), "@@can.isMapLike"); | ||
@@ -87,2 +96,8 @@ ok(!typeReflections.isMapLike("String"), "String"); | ||
ok(typeReflections.isValueLike(obj), "symboled"); | ||
var symboled = {}; | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isValueLike"), false); | ||
ok(!typeReflections.isValueLike(symboled), "!@@can.isValueLike"); | ||
getSetReflections.setKeyValue(symboled, canSymbol.for("can.isValueLike"), true); | ||
ok(typeReflections.isValueLike(symboled), "@@can.isValueLike"); | ||
}); | ||
@@ -89,0 +104,0 @@ |
@@ -48,5 +48,10 @@ var canSymbol = require("can-symbol"); | ||
function isValueLike(obj) { | ||
var symbolValue; | ||
if(isPrimitive(obj)) { | ||
return true; | ||
} | ||
symbolValue = obj[canSymbol.for("can.isValueLike")]; | ||
if( typeof symbolValue !== "undefined") { | ||
return symbolValue; | ||
} | ||
var value = obj[canSymbol.for("can.getValue")]; | ||
@@ -59,5 +64,10 @@ if(value !== undefined) { | ||
function isMapLike(obj) { | ||
var symbolValue; | ||
if(isPrimitive(obj)) { | ||
return false; | ||
} | ||
symbolValue = obj[canSymbol.for("can.isMapLike")]; | ||
if( typeof symbolValue !== "undefined") { | ||
return symbolValue; | ||
} | ||
var value = obj[canSymbol.for("can.getKeyValue")]; | ||
@@ -82,3 +92,4 @@ if(value !== undefined) { | ||
function isListLike( list ) { | ||
var type = typeof list; | ||
var symbolValue, | ||
type = typeof list; | ||
if(type === "string") { | ||
@@ -90,2 +101,6 @@ return true; | ||
} | ||
symbolValue = list[canSymbol.for("can.isListLike")]; | ||
if( typeof symbolValue !== "undefined") { | ||
return symbolValue; | ||
} | ||
var value = list[canSymbol.iterator]; | ||
@@ -92,0 +107,0 @@ if(value !== undefined) { |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
40162
990
1