Comparing version 1.1.1 to 1.1.2
@@ -200,3 +200,6 @@ var canReflect = require("can-reflect"); | ||
Integer[newSymbol] = function(value) { | ||
return parseInt(value); | ||
// parseInt(notANumber) returns NaN | ||
// Since we always want an integer returned | ||
// using |0 instead. | ||
return value | 0; | ||
}; | ||
@@ -208,3 +211,3 @@ Integer[isMemberSymbol] = function(value) { | ||
}; | ||
Integer[getSchemaSymbol] = makeSchema([Integer]); | ||
Integer[getSchemaSymbol] = makeSchema([Number]); | ||
canReflect.setName(Integer, "Integer"); | ||
@@ -211,0 +214,0 @@ |
@@ -17,3 +17,3 @@ @module {Object} can-type | ||
{ | ||
// Create a type that throws ifa value of another type | ||
// Create a type that throws if a value of another type | ||
// is passed. | ||
@@ -56,3 +56,3 @@ check( Type ), | ||
### Prevent wrong types from being passed | ||
### Prevent incorrect types from being passed | ||
@@ -79,2 +79,4 @@ Using [can-type/check] you can ensure that properties of the wrong type are not passed to your components. If a value of any other type is passed it will throw (in development mode) and let the developer know the mistake they made. | ||
> Note: Instead of using `name: type.check(String)` above, `name: String` could be used. If a type is provided (example: `type: Date`), `type.check()` is performed by default (example: `type: type.check(Date)`). | ||
### Convert a value to a type | ||
@@ -84,3 +86,3 @@ | ||
In the following example we have a text input, which will always have a string value, bound to a property of type `type.maybe(Number)`. This converts that value to a [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number): | ||
In the following example we have a text input, which will always have a string value, bound to a property of type `type.convert(Number)`. This converts that value to a [Number](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number): | ||
@@ -87,0 +89,0 @@ ```js |
{ | ||
"name": "can-type", | ||
"version": "1.1.1", | ||
"version": "1.1.2", | ||
"description": "Type definitions", | ||
@@ -41,2 +41,3 @@ "homepage": "https://canjs.com/doc/can-type.html", | ||
"devDependencies": { | ||
"can-query-logic": "^1.2.2", | ||
"can-test-helpers": "^1.1.4", | ||
@@ -43,0 +44,0 @@ "http-server": "^0.11.1", |
@@ -6,2 +6,3 @@ var canSymbol = require("can-symbol"); | ||
var dev = require("can-test-helpers").dev; | ||
var QueryLogic = require("can-query-logic"); | ||
@@ -433,1 +434,33 @@ var newSymbol = canSymbol.for("can.new"); | ||
}); | ||
QUnit.test("Integer works with can-query-logic", function(assert) { | ||
var schema = { | ||
type: "map", | ||
identity: [], | ||
keys: { | ||
int: type.Integer | ||
} | ||
}; | ||
var ql = new QueryLogic(schema); | ||
var ism = ql.isMember( | ||
{ filter: { int: {$gte: 5} } }, | ||
{int: 5} | ||
); | ||
assert.equal(ism, true, "numbers are integers"); | ||
}); | ||
QUnit.test("Integer able to convert non-numbers", function(assert) { | ||
var res = canReflect.convert({}, type.Integer); | ||
assert.equal(res, 0, "converts to 0"); | ||
res = canReflect.convert(33.3, type.Integer); | ||
assert.equal(res, 33, "converts numbers right still"); | ||
res = canReflect.convert("33", type.Integer); | ||
assert.equal(res, 33, "converts strings"); | ||
res = canReflect.convert(NaN, type.Integer); | ||
assert.equal(res, 0, "defaults to 0"); | ||
}); |
54851
735
9