New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

can-type

Package Overview
Dependencies
Maintainers
4
Versions
38
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

can-type - npm Package Compare versions

Comparing version 1.0.0-pre.3 to 1.0.0-pre.4

test-ie.html

12

can-type-test.js

@@ -18,3 +18,5 @@ var canSymbol = require("can-symbol");

function isNaN(assert, result) {
assert.ok(Number.isNaN(result), "Is NaN value");
// result !== result is used because Number.isNaN doesn’t exist in IE11
// result !== result works because NaN is the only value not equal to itself in JS
assert.ok(result !== result, "Is NaN value");
}

@@ -170,3 +172,5 @@

QUnit.test("type.late(fn) takes a function to define the type later", function(assert) {
var theType = type.late(() => type.convert(Number));
var theType = type.late(function() {
return type.convert(Number);
});
var result = canReflect.convert("45", theType);

@@ -177,3 +181,5 @@ assert.equal(result, 45, "Defined late but then converted");

dev.devOnlyTest("type.late(fn) where the underlying type value is a builtin becomes a strict type", function(assert) {
var typeType = type.late(() => Number);
var typeType = type.late(function() {
return Number;
});
var result = canReflect.convert(45, typeType);

@@ -180,0 +186,0 @@ assert.equal(result, 45, "works with numbers");

@@ -10,4 +10,7 @@ var canReflect = require("can-reflect");

var primitives = new Map();
[Number, String, Boolean].forEach(function(Type) {
var typeString = Type.name.toLowerCase();
canReflect.each({
"boolean": Boolean,
"number": Number,
"string": String
}, function(Type, typeString) {
primitives.set(Type, {

@@ -120,3 +123,3 @@ isMember: function(val) {

function check(Type, val) {
throw new Error(`Type value ${typeof val === "string" ? '"' + val + '"' : val} is not of type ${canReflect.getName(Type)}.`);
throw new Error('Type value ' + typeof val === "string" ? '"' + val + '"' : val + ' is not of type ' + canReflect.getName(Type) + '.' );
}

@@ -123,0 +126,0 @@

@@ -13,3 +13,3 @@ @module {Object} can-type

Use can-type to define rules around types to handle type checking and type conversion. Works well with [can-define], [can-define-object], and [can-stache-define-element].
Use can-type to define rules around types to handle type checking and type conversion. Works well with [can-define], [can-observable-object], and [can-stache-element].

@@ -23,3 +23,3 @@ can-type specifies the following type functions:

```js
import { Reflect, type } from "can/everything";
import { Reflect, type } from "can";

@@ -46,3 +46,3 @@ const NumberType = type.maybe(Number);

```js
import { Reflect, type } from "can/everything";
import { Reflect, type } from "can";

@@ -61,3 +61,3 @@ const NumberType = type.convert(Number);

```js
import { Reflect, type } from "can/everything";
import { Reflect, type } from "can";

@@ -87,3 +87,3 @@ const DateType = type.maybeConvert(Date);

```js
import { Reflect, type } from "can/everything";
import { Reflect, type } from "can";

@@ -101,8 +101,8 @@ const StringType = type.check(String);

can-type is useful for creating typed properties in [can-define-object]. You might want to use stricter type checking for some properties or classes and looser type checking for others. The following creates properties with various properties and type methods:
can-type is useful for creating typed properties in [can-observable-object]. You might want to use stricter type checking for some properties or classes and looser type checking for others. The following creates properties with various properties and type methods:
```js
import { DefineObject, type } from "can/everything";
import { ObservableObject, type } from "can";
class Person extends DefineObject {
class Person extends ObservableObject {
static define = {

@@ -128,12 +128,12 @@ first: type.check(String), // type checking is the default behavior

> Note: as mentioned in the comment above, type checking is the default behavior of [can-define-object], so `first: type.check(String)` could be written as `first: String`.
> Note: as mentioned in the comment above, type checking is the default behavior of [can-observable-object], so `first: type.check(String)` could be written as `first: String`.
When creating models with [can-rest-model] you might want to be loose in the typing of properties, especially when working with external services you do not have control over.
On the other hand, when creating ViewModels for components, such as with [can-stache-define-element] you might want to be stricter about how properties are passed, to prevent mistakes.
On the other hand, when creating ViewModels for components, such as with [can-stache-element] you might want to be stricter about how properties are passed, to prevent mistakes.
```js
import { StacheDefineElement, type } from "can/everything";
import { StacheElement, type } from "can";
class Progress extends StacheDefineElement {
class Progress extends StacheElement {
static define = {

@@ -183,3 +183,3 @@ value: {

See [can-stache-define-element] and [can-define-object] for more on these APIs.
See [can-stache-element] and [can-observable-object] for more on these APIs.

@@ -186,0 +186,0 @@ ## How it works

{
"name": "can-type",
"version": "1.0.0-pre.3",
"version": "1.0.0-pre.4",
"description": "Type definitions",

@@ -15,3 +15,5 @@ "homepage": "https://canjs.com/doc/can-type.html",

},
"browserslist": "ie 11",
"scripts": {
"ci": "npm run test && node test-saucelabs.js",
"preversion": "npm test",

@@ -21,2 +23,3 @@ "postpublish": "git push --tags && git push",

"test": "npm run jshint && npm run testee",
"http-server": "http-server -p 3000 --silent",
"jshint": "jshint ./*.js --config",

@@ -39,2 +42,3 @@ "release:patch": "npm version patch && npm publish",

"can-test-helpers": "^1.1.4",
"http-server": "^0.11.1",
"jshint": "^2.9.1",

@@ -44,2 +48,3 @@ "steal": "^2.1.6",

"steal-tools": "^2.0.9",
"test-saucelabs": "0.0.6",
"testee": "^0.9.1"

@@ -46,0 +51,0 @@ },

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc