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

sol-type-check

v1.0.3

Published

A lightweight JavaScript library to validate Solidity data types like int, uint, bytes, and Ethereum-specific types such as addresses and transaction hashes.

Downloads

118

Readme

sol-type-check

A lightweight JavaScript library to validate Solidity data types like int, uint, bytes, and Ethereum-specific types such as addresses and transaction hashes.

Features

  • Validate signed and unsigned integers (int, uint) with customizable bit sizes.
  • Validate Solidity bytes types (1, 2, 4, 8, 16, 32).
  • Validate Ethereum addresses and transaction hashes.
  • Provides simple and easy-to-use functions.

Installation

To install the library, run the following command:

npm install sol-type-check

Usage

Importing the Library

You can import the library in your project like this:

const { isInt, isUint, isBytes, isAddress, isHash } = require('sol-type-check');

Example Functions

isInt(bits, value)

Checks if a value is a signed integer within the range for a given bit size.

isInt(32, 123); // true
isInt(8, -130); // false

isUint(bits, value)

Checks if a value is an unsigned integer within the range for a given bit size.

isUint(32, 4294967295); // true
isUint(8, -1); // false

isBytes(bytes, value)

Checks if a value is a valid bytes array of the specified size.

isBytes(4, "0xabcdef"); // true
isBytes(2, "0x12345"); // false

isAddress(value)

Checks if a value is a valid Ethereum address.

isAddress("0x32Be343B94f860124dC4fEe278FDCBD38C102D88"); // true
isAddress("0xInvalidAddress"); // false

isHash(value)

Checks if a value is a valid Ethereum transaction hash.

isHash("0x5c504ed7d413568f857eeb70f9f70e0d8b6b7469c9a7f325d9776de08e850635"); // true
isHash("0xInvalidHash"); // false

API

  • isInt(bits, value)
    Validates a signed integer for the specified bit size.

    • bits: An integer (8, 16, 32, 64, 128, or 256) representing the bit size.
    • value: A number to check if it is within the valid range.
  • isUint(bits, value)
    Validates an unsigned integer for the specified bit size.

    • bits: An integer (8, 16, 32, 64, 128, or 256) representing the bit size.
    • value: A number to check if it is within the valid range.
  • isBytes(bytes, value)
    Validates a bytes array of a specified size.

    • bytes: An integer (1, 2, 4, 8, 16, or 32) representing the expected byte size.
    • value: A string representing the bytes in hexadecimal format (prefixed with 0x).
  • isAddress(value)
    Validates an Ethereum address.

    • value: A string representing the Ethereum address (must start with 0x and be 40 hexadecimal characters).
  • isHash(value)
    Validates an Ethereum transaction hash.

    • value: A string representing the Ethereum transaction hash (must start with 0x and be 64 hexadecimal characters).

Contributing

If you would like to contribute to this project, feel free to fork the repository and create a pull request. We welcome bug reports, suggestions, and improvements.

🛠 Support

If you encounter any issues or have questions, please open an issue in this repository or contact us at [email protected].

License

This project is licensed under the MIT License - see the LICENSE file for details.