npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

tokyo-schema

v1.1.5

Published

Tokyo Project, Validate the user input schema

Downloads

43

Readme

Build Status

Tokyo Schema

Validate input using Joi

Types

Time : Human readable string without time zone considered (UTC). Only support YYYY/MM/DD HH:mm:ss format.

  • eg) 01/21/2018 09:30:00

Account : 20 Bytes Ethereum account starting with "0x"

  • eg) 0x5a0b54d5dc17e0aadc383d2db43b0a0d3e029c4c

Uint : string parsed with bignumber.js for unsigned integer.

  • eg) "400000000000000000000", "1e18"

Schema

{
  project_name: String,

  // token defines which function should be given
  token : {
    token_type : {
      is_minime : Boolean,
    },
    token_option : {
      burnable : Boolean,          // self-burnable
      pausable : Boolean,          // pause token transfer. MiniMe token is pausable as default.
      no_mint_after_sale: Boolean, // no more token generation after sale
    },
    token_name : String,
    token_symbol : String,
    decimals : Number,
    use_custom_token: Boolean         // use customized token. token contract will
                                      // go by "<ProjectName>CustomToken"
  },
  sale : {
    max_cap : Uint, // decimals considered
    min_cap : Uint, // decimals considered
    start_time : Time,
    end_time : Time,

    // base value to calculate ratio.
    // if coeff is 1000, ratio value is 20, which means 20/1000 (2%)
    coeff: Uint,

    rate: {
      is_static: Boolean, // true if no bonus, false if dynamic rate
      base_rate: Uint,    // rate without bonus.
                          // token amount = ether amount * rate

      bonus: { // only required for dynamic rate with bonus
               // token rate = base rate * (time bonus + amount bonus + coeff) / coeff

        use_time_bonus : Boolean,
        use_amount_bonus : Boolean,

        // give additional bonus for time and ether amount.
        // bonus_time_stage should be sorted in ascending.
        // bonus_amount_stage should be sorted in descending.
        time_bonuses : [
          {
            bonus_time_stage: Time, // end time of time bonus
            bonus_time_ratio: Uint, // bonus rate
          }
        ],
        amount_bonuses : [
          {
            bonus_amount_stage: Uint, // start amount of amount bonus
            bonus_amount_ratio: Uint, // bonus rate
          }
        ]
      }
    },

    // after sale is finished, distribute ether and generate more tokens
    // to designated accounts
    distribution: {
      token : [
        {
          // `token_holder` can only 3 type of string as value.
          //  - "crowdsale": ratio of tokens purchaed by crowdsale contract.
          //     this ratio detemines the _final total supply_.
          //  - "locker": ratio of tokens generated to locker.
          //     then locker release tokens based on release info.
          //  - Account: ethereum address to be given without purchasing.
          token_holder: "crowdsale" | "locker" | Account,

          // all token_holder's sum of token_ratio should be equal to `coeff`
          token_ratio : Uint
        }
      ],

      // distribute Ether locked in vault.
      ether : [
        {
          // `ether_holder` can only 2 type of string as value.
          //  - "multisig<N>": N'th multisig wallet.
          //    multi-signature wallet contracts will be deployed according to
          //    "multisig" section. see examples
          //  - Account: ethereum address to receive Ether
          ether_holder: "multisig" | Account,
          ether_ratio : Number
        }
      ]
    },

    // Define sale stages seperated by times.
    // independent cap / kyc / max & min purchase limits could be set.
    stages: [
      {
        start_time: Time, // start time of stage, inclusive
        end_time: Time,   // end time of stage, inclusive
                          // start time of next stage should be later than end time
                          // of previous stage

        cap_ratio: Uint,  // 0 for no seperated cap for the stage.
                          // refund partial amount of ether
                          // if raised weia amount is over cap

        min_purchase_limit: Uint, // 0 for no limit,
                                  // reject token purchase
                                  // over this amount of ether

        max_purchase_limit: Uint, // 0 for no limit,
                                  // limit purchaser from funding too many ether.
                                  // this doesn't reject TX, but reduce msg.value
                                  // to fit this limit and refund not-funded ether.
        kyc: Boolean, // check kyc for this stage
      }
    ],
    valid_purchase: {
      min_purchase_limit : Uint, // 0 for no limit
                                 // reject token purchase
                                 // under this amount of ether

      max_purchase_limit : Uint, // 0 for no limit
                                 // limit purchaser from funding too many ether.
                                 // this doesn't reject TX, but reduce msg.value
                                 // to fit this limit and refund not-funded ether.

      block_interval : Number    // 0 for no limit
                                 // only accept token purchase
                                 // if last token purchase TX's block number
                                 // is less than current block number - interval
    },
    new_token_owner : Account,   // account to hold ownership of token after
                                 // sale is finalized.
    multisig : {
      use_multisig : Boolean,

      // each info is used as parameters for multisig wallet contract's constructor
      // see detail explanation: https://github.com/Onther-Tech/tokyo-reusable-crowdsale/blob/a7342431f8fc635702de033f9d2b6bac67f274d9/contracts/wallet/MultiSigWallet.sol
      infos: [
        {
          num_required: Number,
          owners: [ Account ]  
        }
      ]
    }
  },

  // Lock tokens and release them periodically (or linearly)
  // see more explanation: https://github.com/Onther-Tech/tokyo-reusable-crowdsale/blob/ac9656cca602465d1f2cf14f99e6edf5c0a98cf8/contracts/locker/Locker.sol#L11
  locker : {
    use_locker : Boolean,
    beneficiaries: [{
      address: Account | Multisig,       // token beneficiaries
      ratio: Uint                        // The ratio designated to this beneficiary
      is_straight : Boolean,             // locking type : straight, variable

      // A single release for simple locker (a single release time & 100% of the token)
      release : [ { relase_time: Time, release_ratio: Uint } ]
    }]
  }
}

Example

// ES6
import validate from 'tokyo-schema';

// ES5
const validate = require('tokyo-schema').default;

const inputObj = {...} // Input with the above schema form

const result = validate(inputObj);

if (result.error) {
  console.error(result.error);

  // inputObj is invalid schema
} else {
  const obj = resuilt.value;

  // use `obj`...
}