How to use the tcomb.maybe function in tcomb

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 gcanti / tom / lib / Session.js View on Github external
function getDeafultPatch(State) {
  debug('using default `Patch` constructor');
  return t.struct({
    token: t.maybe(State),
    spec: t.Obj
  }, 'Patch');
}
github root-systems / feathers-action / src / reducer.js View on Github external
})
  const DataWithMaybeId = Data.extend({
    [idField]: Tc.maybe(Id)
  })

  const actionIds = createActionIds(options)
  const actionTypes = createActionTypes(options)
  const actions = createActions(options)

  const StartPayload = sectionUnion(serviceName, actionTypes, 'start')
  const SuccessPayload = sectionUnion(serviceName, actionTypes, 'success')
  const ErrorPayload = sectionUnion(serviceName, actionTypes, 'error')

  const Records = Tc.dict(Id, DataWithMaybeId, 'Records')
  const PendingStartPayload = StartPayload.extend({
    previousData: Tc.maybe(DataWithId)
  }, 'PendingStartPayload')
  const Pending = Tc.dict(Cid, PendingStartPayload, 'Pending')
  const Success = Tc.dict(Cid, SuccessPayload, 'Success')
  const Error = Tc.dict(Cid, ErrorPayload, 'Error')

  const State = Tc.struct({
    records: Records,
    pending: Pending,
    success: Success,
    error: Error,
  }, {
    name: `${ServiceName}State`,
    defaultProps: {
      records: {},
      pending: {},
      success: {},
github goodmind / cycle-telegram / src / runtime-types / types.ts View on Github external
description: string
  photo: m.TcombPhotoSize[],
  text?: string
  text_entities?: TcombMessageEntity[],
  animation?: m.TcombAnimation
}

export const Message = t.declare('Message')
Message.define(t.struct({
  message_id: t.Number,
  from: t.maybe(User),
  edit_date: t.maybe(t.Number),
  date: t.Number,
  chat: Chat,
  forward_from: t.maybe(User),
  forward_from_chat: t.maybe(Chat),
  forward_date: t.maybe(t.Number),
  reply_to_message: t.maybe(Message),
  text: t.maybe(t.String),
  entities: t.maybe(t.list(MessageEntity)),
  audio: t.maybe(m.Audio),
  document: t.maybe(m.Document),
  game: t.maybe(Game),
  photo: t.maybe(t.list(m.PhotoSize)),
  sticker: t.maybe(m.Sticker),
  video: t.maybe(m.Video),
  voice: t.maybe(m.Voice),
  caption: t.maybe(t.String),
  contact: t.maybe(m.Contact),
  location: t.maybe(m.Location),
  venue: t.maybe(m.Venue),
  new_chat_member: t.maybe(User),
github adamgruber / mochawesome-report-generator / src / bin / types.js View on Github external
mochawesome: t.struct({
    options: t.Object,
    version: t.String
  }),
  marge: t.struct({
    options: t.Object,
    version: t.String
  })
});

const Test = t.struct({
  title: t.String,
  fullTitle: t.String,
  timedOut: t.maybe(t.Boolean),
  duration: Duration,
  state: t.maybe(TestState),
  speed: t.maybe(TestSpeed),
  pass: t.Boolean,
  fail: t.Boolean,
  pending: t.Boolean,
  code: t.String,
  err: t.Object,
  uuid: Uuid,
  parentUUID: t.maybe(Uuid),
  skipped: t.Boolean,
  context: t.maybe(t.String),
  isHook: t.Boolean,
});

const Suite = t.declare('Suite');
Suite.define(
  t.struct({

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