Skip to content
This repository was archived by the owner on Feb 16, 2021. It is now read-only.

v1.1.0

Choose a tag to compare

@gcanti gcanti released this 12 Aug 10:27
  • New Feature
    • (backport from v2.1) added alias for basic types and changed built-in irreducible names accordingly:

      • String for Str
      • Number for Num
      • Boolean for Bool
      • Array for Arr
      • Object for Obj
      • Function for Func
      • Error for Err
      • RegExp for Re
      • Date for Dat

      This means you can define, for example, a struct with:

      var t = require('tcomb');
      
      var Point = t.struct({
        x: t.Number, // <- new aliases
        y: t.Number
      }, 'Point');
    • better error messages for assert failures in nested structures.

      The messages have the following general form:

      Invalid value <value> supplied to <context>
      

      where context is a slash-separated array with the following properties:

      • the first element is the name of the "root"
      • the following elements have the form: <field name>: <field type>

      Example

      var Person = t.struct({
        name: t.String
      }, 'Person');
      
      var User = t.struct({
        email: t.String,
        profile: Person
      }, 'User');
      
      var mynumber = t.Number('a');
      // => invalid value "a" supplied to Num
      
      var myuser = User({ email: 1 });
      // => Invalid value 1 supplied to User/email: Str
      
      myuser = User({ email: 'email', profile: { name: 2 } });
      // => Invalid value 2 supplied to User/profile: Person/name: Str