當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。