How to use tcomb - 10 common examples

To help you get started, we’ve selected a few tcomb examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bitshares / bitshares-ui / app / stores / tcomb_structs.js View on Github external
encrypted_brainkey: maybe(Str),
        brainkey_pubkey: Str,
        brainkey_sequence: Num,
        brainkey_backup_date: maybe(Dat),
        deposit_keys: maybe(Obj),
        // password_checksum: Str,
        chain_id: Str
    },
    "WalletTcomb"
);

let PrivateKeyTcomb = struct(
    {
        id: maybe(Num),
        pubkey: Str,
        label: maybe(Str),
        import_account_names: maybe(Arr),
        brainkey_sequence: maybe(Num),
        encrypted_key: Str
    },
    "PrivateKeyTcomb"
);

export {WalletTcomb, PrivateKeyTcomb};
github gcanti / tcomb-doc / test / index.js View on Github external
test('maybe', function (assert) {
  assert.plan(1);
  var expected = {
    kind: 'irreducible',
    required: false,
    name: 'String',
    predicate: t.String.meta.predicate
  };
  var actual = toObject(t.maybe(t.String));
  assert.deepEqual(actual, expected);
});
github gcanti / babel-plugin-tcomb / test / fixtures / import-require / expected.js View on Github external
function foo(x: ?tc.String) {
  tc.assert(tc.maybe(tc.String).is(x), 'Invalid argument x (expected a ' + tc.getTypeName(tc.maybe(tc.String)) + ')');

  return x || 'Empty';
}
github root-systems / feathers-action / test / types.js View on Github external
const Tc = require('tcomb')

const Thing = Tc.struct({
  name: Tc.String,
  description: Tc.maybe(Tc.String),
}, 'Thing')

const Things = Tc.list(Thing, 'Things')

module.exports = {
  Resource: Things
}
github gcanti / redux-tcomb / lib / createUnion.js View on Github external
var t = require('tcomb');

var Type = t.irreducible('Type', t.isType);
var ActionDictionary = t.dict(t.String, Type);
var ActionStruct = t.subtype(t.Object, function (x) {
  return t.String.is(x.type);
});
var Name = t.maybe(t.String);

function values(actions) {
  return Object.keys(actions).map(function (type) {
    return actions[type];
  });
}

function createUnion(actions, name) {

  if (process.env.NODE_ENV !== 'production') {
    t.assert(ActionDictionary.is(actions), function () { return 'Invalid argument action ' + t.stringify(actions) + ' supplied to createUnion(actions, name) function (expected a dictionary String -> Type)'; });
    t.assert(Name.is(name), function () { return 'Invalid argument name ' + t.stringify(name) + ' supplied to createUnion(actions, name) function (expected a string)'; });
  }

  name = name || 'Action';
github gcanti / tcomb-json-schema / index.js View on Github external
object: function(s) {
    var props = {};
    var hasProperties = false;
    var required = {};
    if (s.required) {
      s.required.forEach(function(k) {
        required[k] = true;
      });
    }
    for (var k in s.properties) {
      if (s.properties.hasOwnProperty(k)) {
        hasProperties = true;
        var type = transform(s.properties[k]);
        props[k] = required[k] || type === t.Boolean ? type : t.maybe(type);
      }
    }
    return hasProperties ? t.struct(props, s.description) : t.Object;
  },
github goodmind / cycle-telegram / lib / runtime-types / inline-types.js View on Github external
var BaseInlineQuery = function (props, name) {
    if (name === void 0) { name = 'Unknown'; }
    return t.struct(Object.assign({}, {
        type: t.String,
        id: t.String,
        reply_markup: t.maybe(k.InlineKeyboardMarkup),
        input_message_content: t.maybe(exports.InputMessageContent)
    }, props), name);
};
exports.InlineQueryResultCachedAudio = BaseInlineQuery({
github gcanti / tom / lib / Response.js View on Github external
'use strict';

var t = require('tcomb');

var Response = t.struct({
  redirect: t.Func,
  render: t.Func
}, 'Response');

module.exports = Response;
github goodmind / cycle-telegram / src / runtime-types / inline-types.ts View on Github external
const BaseInlineQuery = function (props: any, name: string = 'Unknown') {
  return t.struct(
    Object.assign(
      {},
      {
        type: t.String,
        id: t.String,
        reply_markup: t.maybe(k.InlineKeyboardMarkup),
        input_message_content: t.maybe(InputMessageContent)
      },
      props),
    name)
}
export interface BaseInlineQueryResult {
github gcanti / tom / lib / ParallelEffect.js View on Github external
var t = require('tcomb');
var Rx = require('rx');

var ParallelEffect = t.struct({
  effects: t.list(t.Any)
}, 'ParallelEffect');

ParallelEffect.prototype.toObservable = function(store) {
  return Rx.Observable.merge(this.effects.map(function (effect) {
    return effect.toObservable(store);
  }));
};

module.exports = ParallelEffect;

tcomb

Type checking and DDD for JavaScript

MIT
Latest version published 5 years ago

Package Health Score

61 / 100
Full package analysis

Popular tcomb functions