2.0.5 • Published 2 days ago

web3-validator v2.0.5

Weekly downloads
-
License
LGPL-3.0
Repository
github
Last release
2 days ago

web3-validator

ES Version Node Version NPM Package Dependency Status Dev Dependency Status

This is a sub-package of web3.js.

web3-validator contains functions for validating objects.

Get it from the NPM Registry
yarn add web3-validator

Getting Started

Usage

You can use the the validator by importing as and using to validate;

import { validator } from 'web3-validator';

// To validate and throw
validator.validate(['uint8', 'string'], [val1, val2]);

// To validate and return error
const errors = validator.validate(['uint8', 'string'], [val1, val2], { silent: true });

To see more examples of schema you can use to validate check following file.

Following eth types are supported to validate.

TypeInput AsDescription
uintnumber, string, HexStringUnsigned integer, all ethereum compatible variants are also supported e.g. uint8, uint256. You can also use array specifiers as uint[] or uint[2]
intnumber, string, HexStringSigned integer, all ethereum compatible variants are also supported e.g. int8, int256. You can also use array specifiers as int[] or int[2]
bytesHexString, BufferRaw bytes. You can also use fixed length bytes as bytes[2]

| string | string | String values | | address | string, HexString | Ethereum network compatible address | | bloom | string, HexString | Check if a given string is a Eth bloom | | tuple | array | You can specify any tuple as nested arrays. e.g. ['uint', 'string']. For a custom tuple or array tuple you can use syntax e.g. ['tuple[3]', ['uint', 'string']] |

For the ethereum compatible data values should be passed as arrays e.g. for schema ['uint', 'string'] value should be passed as [2, 'my-string'].

You can also pass full ABI schema for the validation. e.g.

[{ "name": "owner", "type": "address" }]

The implementation of the validator is extension of JSON-Schema-Draft07 with a custom keyword eth. So you can use JSON-Schema compatible schema to validate any object based data as well.

Prerequisites

Package.json Scripts

ScriptDescription
cleanUses rimraf to remove dist/
buildUses tsc to build package and dependent packages
lintUses eslint to lint package
lint:fixUses eslint to check and fix any warnings
formatUses prettier to format the code
testUses jest to run unit tests
test:integrationUses jest to run tests under /test/integration
test:unitUses jest to run tests under /test/unit
2.0.5

1 month ago

2.0.4

4 months ago

2.0.3

7 months ago

1.0.2

10 months ago

1.0.2-dev.d12dc7e.0

10 months ago

1.0.1

10 months ago

1.0.0

11 months ago

1.0.3-dev.ad377d1.0

10 months ago

1.0.3-dev.8958413.0

10 months ago

1.0.1-dev.60b8ba9.0

10 months ago

2.0.2

8 months ago

1.0.3-dev.7d0a91d.0

10 months ago

1.0.2-dev.a26a888.0

10 months ago

2.0.1

9 months ago

2.0.0

9 months ago

1.0.2-dev.602dada.0

10 months ago

1.0.3-dev.ebd0c57.0

10 months ago

1.0.3-dev.933ef51.0

10 months ago

1.0.1-dev.e8d579c.0

10 months ago

1.0.1-dev.51a59f9.0

11 months ago

1.0.1-dev.ab0f4cb.0

11 months ago

1.0.1-dev.023f02d.0

11 months ago

1.0.0-rc.2

11 months ago

1.0.3-dev.e143157.0

10 months ago

2.0.0-rc.0

9 months ago

1.0.3-dev.1361787.0

10 months ago

1.0.3-dev.f5b4d7d.0

10 months ago

1.0.3-dev.51bc03d.0

10 months ago

1.0.1-dev.f8a2533.0

11 months ago

1.0.1-dev.af57eae.0

11 months ago

1.0.1-dev.3f49e18.0

10 months ago

1.0.1-dev.2130d22.0

11 months ago

1.0.1-dev.a2a232f.0

11 months ago

1.0.3-dev.b93934a.0

10 months ago

1.0.0-rc.1

1 year ago

1.0.0-rc.0

1 year ago

0.1.1-alpha.2

1 year ago

0.1.1-alpha.1

1 year ago

0.1.1-alpha.4

1 year ago

0.1.1-alpha.3

1 year ago

0.1.1-alpha.5

1 year ago

0.1.1-alpha.0

2 years ago

0.1.0-alpha.0

2 years ago