Socket
Socket
Sign inDemoInstall

tcomb

Package Overview
Dependencies
Maintainers
1
Versions
74
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tcomb - npm Package Compare versions

Comparing version 2.3.0 to 2.4.0

8

CHANGELOG.md

@@ -15,2 +15,10 @@ # Changelog

## v2.4.0
- **New Feature**
- unions
- added `update` function, #127
- the default `dispatch` implementation now handles unions of unions, #126
- show the offended union type in error messages
## v2.3.0

@@ -17,0 +25,0 @@

4

GUIDE.md

@@ -639,3 +639,3 @@ # Setup

### Removing a value form a dict
### Removing a value from a dict

@@ -758,2 +758,2 @@ ```js

t.stringify = String;
```
```

@@ -0,1 +1,9 @@

/*! @preserve
*
* The MIT License (MIT)
*
* Copyright (c) 2014 Giulio Canti
*
*/
'use strict';

@@ -56,2 +64,6 @@

function isUnion(x) {
return isType(x) && (x.meta.kind === 'union');
}
function isTypeName(name) {

@@ -396,2 +408,3 @@ return isNil(name) || isString(name);

assert(isType(type), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); });
path[path.length - 1] += '(' + getTypeName(type) + ')';
}

@@ -418,8 +431,19 @@

for (var i = 0, len = types.length; i < len; i++ ) {
if (is(x, types[i])) {
return types[i];
var type = types[i];
if (isUnion(type)) {
var t = type.dispatch(x);
if (!isNil(t)) {
return t;
}
}
else if (is(x, type)) {
return type;
}
}
};
Union.update = function (instance, spec) {
return Union(exports.update(instance, spec));
};
return Union;

@@ -704,4 +728,4 @@ }

if (process.env.NODE_ENV !== 'production') {
assert(isArray(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + displayName + ' (expected an array of ' + typeNameCache + ')'; });
path = path || [displayName];
assert(isArray(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/') + ' (expected an array of ' + typeNameCache + ')'; });
}

@@ -778,4 +802,4 @@

if (process.env.NODE_ENV !== 'production') {
assert(isObject(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + displayName; });
path = path || [displayName];
assert(isObject(value), function () { return 'Invalid value ' + exports.stringify(value) + ' supplied to ' + path.join('/'); });
}

@@ -782,0 +806,0 @@

{
"name": "tcomb",
"version": "2.3.0",
"version": "2.4.0",
"description": "Type checking and DDD for JavaScript",

@@ -5,0 +5,0 @@ "main": "index.js",

@@ -16,3 +16,3 @@ [![build status](https://img.shields.io/travis/gcanti/tcomb/master.svg?style=flat-square)](https://travis-ci.org/gcanti/tcomb)

// a user defined type
var Integer = t.subtype(t.Number, function (n) => { return n % 1 === 0; });
var Integer = t.subtype(t.Number, function (n) => { return n % 1 === 0; }, 'Integer'); // <= give a name for better debug messages

@@ -25,3 +25,3 @@ // a struct

tags: t.list(t.String) // a list of strings
});
}, 'Person'); // <= give a name for better debug messages

@@ -86,3 +86,3 @@ // methods are defined as usual

```js
[tcomb] Invalid argument value = undefined supplied to irreducible type Number
[tcomb] Invalid value undefined supplied to Person/age: Number
```

@@ -89,0 +89,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