当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript 0x-json-schemas.SchemaValidator类代码示例

本文整理汇总了TypeScript中0x-json-schemas.SchemaValidator的典型用法代码示例。如果您正苦于以下问题:TypeScript SchemaValidator类的具体用法?TypeScript SchemaValidator怎么用?TypeScript SchemaValidator使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了SchemaValidator类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: it

        it('should return the token added to the tokenRegistry during the migration', async () => {
            const aToken = tokens[0];

            const token = await zeroEx.tokenRegistry.getTokenIfExistsAsync(aToken.address);
            const schemaValidator = new SchemaValidator();
            const validationResult = schemaValidator.validate(token, schemas.tokenSchema);
            expect(validationResult.errors).to.have.lengthOf(0);
        });
开发者ID:linki,项目名称:0x.js,代码行数:8,代码来源:token_registry_wrapper_test.ts

示例2: hasAtMostOneUniqueValue

    },
    hasAtMostOneUniqueValue(value: any[], errMsg: string): void {
        this.assert(_.uniq(value).length <= 1, errMsg);
    },
    isNumber(variableName: string, value: number): void {
        this.assert(_.isFinite(value), this.typeAssertionMessage(variableName, 'number', value));
    },
    isBoolean(variableName: string, value: boolean): void {
        this.assert(_.isBoolean(value), this.typeAssertionMessage(variableName, 'boolean', value));
    },
    isWeb3Provider(variableName: string, value: Web3.Provider): void {
        const isWeb3Provider = _.isFunction((value as any).send) || _.isFunction((value as any).sendAsync);
        this.assert(isWeb3Provider, this.typeAssertionMessage(variableName, 'Web3.Provider', value));
    },
    doesConformToSchema(variableName: string, value: any, schema: Schema): void {
        const schemaValidator = new SchemaValidator();
        const validationResult = schemaValidator.validate(value, schema);
        const hasValidationErrors = validationResult.errors.length > 0;
        const msg = `Expected ${variableName} to conform to schema ${schema.id}
Encountered: ${JSON.stringify(value, null, '\t')}
Validation errors: ${validationResult.errors.join(', ')}`;
        this.assert(!hasValidationErrors, msg);
    },
    assert(condition: boolean, message: string): void {
        if (!condition) {
            throw new Error(message);
        }
    },
    typeAssertionMessage(variableName: string, type: string, value: any): string {
        return `Expected ${variableName} to be of type ${type}, encountered: ${value}`;
    },
开发者ID:linki,项目名称:0x.js,代码行数:31,代码来源:assert.ts

示例3: expect

 _.each(tokenAddresses, tokenAddress => {
     const validationResult = schemaValidator.validate(tokenAddress, schemas.addressSchema);
     expect(validationResult.errors).to.have.lengthOf(0);
     expect(tokenAddress).to.not.be.equal(ZeroEx.NULL_ADDRESS);
 });
开发者ID:linki,项目名称:0x.js,代码行数:5,代码来源:token_registry_wrapper_test.ts

示例4: isTxData

 private isTxData(lastArg: any): boolean {
     const isValid = this.validator.isValid(lastArg, schemas.txDataSchema);
     return isValid;
 }
开发者ID:linki,项目名称:0x.js,代码行数:4,代码来源:contract.ts


注:本文中的0x-json-schemas.SchemaValidator类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。