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 🙏

© 2024 – Pkg Stats / Ryan Hefner

solidity-validator

v0.5.2

Published

solidity validator

Downloads

11

Readme

solidity-validator.js

Travis codecov npm downloads Dependency Status NPM version

A library of string validators.

Installation and Usage

npm install solidity-validator

Function

| Validator | Description | |---------------------------|---------------------------------------| | isAddress(str) | check if a string is a address. | | isBoolean(str) | check if a string is a boolean. | | isInt8(str) | check if a string is a int8. | | isUint8(str) | check if a string is a uint8. | | isBytesN(str) | check if a string is a BytesN, N:1-32 | | isByte(str) | check if a string is a Bytes1 | | isBytes(str) | check if a string is a Byte1 ~ Byte32 | | isValid(type, str) | check if a string is match the type | | getRange(type) | get type MIN and MAX range | | getMessage(type, str) | get valid message |

Example

var validator = require('solidity-validator');

validator.isAddress('0xa77451687Ee77cB3DFf16A24446C54DB76C80222'); // true
validator.isAddress('0xa77451687Ee77cB3DFf16A24446C54DB76C80223'); // false

validator.isBoolean('true'); // true
validator.isBoolean('false'); // true
validator.isBoolean('1'); // false
validator.isBoolean('0'); // false

validator.isInt8('-128'); // true
validator.isInt8('127'); // true
validator.isInt8('128'); // false

validator.isUint8('0'); // true
validator.isUint8('255'); // true
validator.isUint8('0.1'); // false
validator.isUint8('-1'); // false
validator.isUint8('256'); // false

validator.isBytes1('0x00'); // true
validator.isBytes1('0xff'); // true
validator.isBytes1('0xgg'); // false
validator.isBytes1('0x'); // false
validator.isBytes2('0x0000'); // true
validator.isBytes2('0xffff'); // true
validator.isBytes2('0xgggg'); // false
validator.isBytes2('0xff'); // false

validator.isByte('0x00'); // true
validator.isByte('0xff'); // true
validator.isByte('0xgg'); // false
validator.isByte('0x'); // false

validator.isBytes('0x00'); // true
validator.isBytes('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // true
validator.isBytes('0xgg'); // false
validator.isBytes('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); // false

validator.isValid('uint', "123"); // true
validator.isValid('uint', "280"); // false
validator.isValid('address', "ooooooxxxxx"); // false

validator.getMessage('uint8', '255');
validator.getMessage('address', '0xa77451687Ee77cB3DFf16A24446C54DB76C80222');
validator.getMessage('int8', '129'); // The value is an illegal range.
validator.getMessage('uint8', '256'); // The value is an illegal range.
validator.getMessage('bool', '0'); // The value is not a boolean.

validator.getMessage('byte', '0x01')
validator.getMessage('bytes2', '0x01')
validator.getMessage('bytes2', '0x0101')

validator.getMessage('address', 'oooooxxxx'); // The value is not a valid address.
validator.getMessage('byte', 'oooooxxxx'); // The value is not a valid bytes.
validator.getRange('int8');

/* === output ===
{
  MIN: -128,
  MAX: 127
}
*/

Tests

Tests are using mocha, to run the tests use:

npm test

Maintainers

License

MIT © alincode