How to use the io-ts.number function in io-ts

To help you get started, we’ve selected a few io-ts 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 teamdigitale / io-functions / lib / api / definitions / ExtendedProfile.ts View on Github external
import * as t from "io-ts";
import { strictInterfaceWithOptionals } from "../../utils/types";

// required attributes
const ExtendedProfileR = t.interface({});

// optional attributes
const ExtendedProfileO = t.partial({
  email: EmailAddress,

  preferred_languages: PreferredLanguages,

  is_inbox_enabled: IsInboxEnabled,

  version: t.number
});

export const ExtendedProfile = strictInterfaceWithOptionals(
  ExtendedProfileR.props,
  ExtendedProfileO.props,
  "ExtendedProfile"
);

export type ExtendedProfile = t.TypeOf;
github Dragory / ZeppelinBot / backend / src / plugins / CompanionChannels.ts View on Github external
import { decorators as d, IPluginOptions, logger } from "knub";
import { trimPluginDescription, ZeppelinPlugin } from "./ZeppelinPlugin";
import { Member, Channel, GuildChannel, PermissionOverwrite, Permission, Message, TextChannel } from "eris";
import * as t from "io-ts";
import { tNullable } from "../utils";

// Permissions using these numbers: https://abal.moe/Eris/docs/reference (add all allowed/denied ones up)
const CompanionChannelOpts = t.type({
  voice_channel_ids: t.array(t.string),
  text_channel_ids: t.array(t.string),
  permissions: t.number,
  enabled: tNullable(t.boolean),
});
type TCompanionChannelOpts = t.TypeOf;

const ConfigSchema = t.type({
  entries: t.record(t.string, CompanionChannelOpts),
});
type TConfigSchema = t.TypeOf;

interface ICompanionChannelMap {
  [channelId: string]: TCompanionChannelOpts;
}

const defaultCompanionChannelOpts: Partial = {
  enabled: true,
};
github gcanti / io-ts-types / test / nonEmptyArray.ts View on Github external
it('name', () => {
    const T = nonEmptyArray(t.number, 'T')
    assert.strictEqual(T.name, 'T')
  })
github gcanti / io-ts-types / test / optionFromJSON.ts View on Github external
it('encode', () => {
    const T1 = optionFromJSON(t.number)
    assert.deepStrictEqual(T1.encode(none), toJSON(none))
    assert.deepStrictEqual(T1.encode(some(1)), toJSON(some(1)))

    const T2 = optionFromJSON(NumberFromString)
    assert.deepStrictEqual(T2.encode(none), toJSON(none))
    assert.deepStrictEqual(T2.encode(some(1)), toJSON(some('1')))

    const T3 = optionFromJSON(optionFromJSON(t.number))
    assert.deepStrictEqual(T3.encode(none), { _tag: 'None' })
    assert.deepStrictEqual(T3.encode(some(some(1))), { _tag: 'Some', value: { _tag: 'Some', value: 1 } })
    assert.deepStrictEqual(T3.encode(some(none)), { _tag: 'Some', value: { _tag: 'None' } })
  })
})
github maasglobal / maas-schemas / maas-schemas-ts / src / core / profile.ts View on Github external
modified?: Units_.Time;
  } & {
    identityId: Defined;
    phone: Defined;
    favoriteLocations: Defined;
    balance: Defined;
    paymentMethod: Defined;
    subscriptionInstance: Defined;
    balances: Defined;
  },
  ProfileBrand
>;
export const Profile = t.brand(
  t.intersection([
    t.partial({
      id: t.number,
      identityId: Units_.IdentityId,
      phone: Common_.Phone,
      email: Common_.Email,
      firstName: Common_.PersonalName,
      lastName: Common_.PersonalName,
      city: Address_.City,
      country: Address_.Country,
      zipCode: Address_.ZipCode,
      regionId: t.string,
      region: Region_.Region,
      profileImageUrl: t.string,
      favoriteLocations: t.array(Place_.Place),
      paymentMethod: t.intersection([
        t.partial({
          type: t.intersection([
            t.string,
github intraxia / wp-gistpen / client / deltas / authorDelta.ts View on Github external
import { CommitsState } from '../reducers';
import { RootAction } from '../RootAction';
import { GlobalsState } from '../globals';
import { foldResponse } from '../api';

type AuthorServices = {
  ajax$: typeof ajax$;
};

type AuthorDeltaState = {
  commits: CommitsState;
  globals: GlobalsState;
};

const apiAuthor = t.type({
  id: t.number,
  name: t.string,
  url: t.string,
  description: t.string,
  link: t.string,
  slug: t.string,
  avatar_urls: t.dictionary(t.string, t.string),
});

export interface ApiAuthor extends t.TypeOf {}

export const authorDelta = ({ ajax$ }: AuthorServices) => (
  actions$: Stream,
  state$: Property,
): Observable =>
  state$
    .sampledBy(actions$.thru(ofType(commitsFetchSucceeded)))
github AugurProject / augur-node / src / server / getters / get-platform-activity-stats.ts View on Github external
amountStaked: BigNumberType;
}

export interface PlatformActivityResult {
  activeUsers: BigNumber;
  numberOfTrades: BigNumber;
  openInterest: BigNumber;
  marketsCreated: BigNumber;
  volume: BigNumber;
  amountStaked: BigNumber;
  disputedMarkets: BigNumber;
}

export const PlatformActivityStatsParams = t.type({
  universe: t.string,
  endTime: t.union([t.number, t.null]),
  startTime: t.union([t.number, t.null]),
});
export type PlatformActivityStatsParamsType = t.TypeOf;

async function getVolume(db: Knex, startBlock: number, endBlock: number, params: PlatformActivityStatsParamsType): Promise {
  return db
    .select("volume")
    .from("markets")
    .where("universe", params.universe)
    .whereBetween("creationBlockNumber", [startBlock, endBlock]);
}

async function getAmountStaked(db: Knex, startBlock: number, endBlock: number, params: PlatformActivityStatsParamsType): Promise {
  return db
    .select(["disputes.amountStaked"])
    .from("disputes")
github AugurProject / augur / packages / augur-sdk / src / state / getter / Liquidity.ts View on Github external
asks: t.array(Order),
});


export const OrderBook = t.dictionary(
    t.string,
    OutcomeOrderBook,
);

export const GetMarketLiquidityRankingParams = t.type({
    orderBook: OrderBook,
    numTicks: t.string,
    marketType: t.number,
    reportingFeeDivisor: t.string,
    feePerCashInAttoCash: t.string,
    numOutcomes: t.number,
    spread: t.number,
});

export interface MarketLiquidityRanking {
    marketRank: number;
    totalMarkets: number;
    hasLiquidity: boolean;
}

export class Liquidity {
  static getMarketLiquidityRankingParams = GetMarketLiquidityRankingParams;

  @Getter('getMarketLiquidityRankingParams')
  static async getMarketLiquidityRanking(augur: Augur, db: DB, params: t.TypeOf): Promise {
    const liquidityScore = await augur.liquidity.getLiquidityForSpread({
        orderBook: params.orderBook,
github maasglobal / maas-schemas / maas-schemas-ts / src / tsp / stations-list / request.ts View on Github external
>;
export const Request = t.brand(
  t.union([
    t.intersection([
      t.partial({
        location: UnitsGeo_.ShortLocationString,
        radius: UnitsGeo_.Distance,
      }),
      t.type({
        location: Defined,
      }),
    ]),
    t.intersection([
      t.partial({
        name: t.string,
        count: t.number,
        type: t.union([
          t.literal('origin'),
          t.literal('destination'),
          t.literal('viaAvoid'),
        ]),
      }),
      t.type({
        name: Defined,
        type: Defined,
      }),
    ]),
  ]),
  (
    x,
  ): x is t.Branded<
    | ({
github elastic / kibana / x-pack / legacy / plugins / infra / common / http_api / log_entries / summary_highlights.ts View on Github external
export const logEntriesSummaryHighlightsBucketRT = rt.intersection([
  logEntriesSummaryBucketRT,
  rt.type({
    representativeKey: logEntriesCursorRT,
  }),
]);

export type LogEntriesSummaryHighlightsBucket = rt.TypeOf<
  typeof logEntriesSummaryHighlightsBucketRT
>;

export const logEntriesSummaryHighlightsResponseRT = rt.type({
  data: rt.array(
    rt.type({
      start: rt.number,
      end: rt.number,
      buckets: rt.array(logEntriesSummaryHighlightsBucketRT),
    })
  ),
});
export type LogEntriesSummaryHighlightsResponse = rt.TypeOf<
  typeof logEntriesSummaryHighlightsResponseRT
>;