Giter Site home page Giter Site logo

solidity-utils's Introduction

Solidity Utils

We want to improve solidity basic skill and we also create a basic library for learning and practice. You can see how to use as below:

pragma solidity ^0.4.16;

import "github.com/20Scoops-CNX/solidity-utils/lib/ListInteger.sol";

import "github.com/20Scoops-CNX/solidity-utils/lib/Strings.sol";

import "github.com/20Scoops-CNX/solidity-utils/lib/Integers.sol";

contract ExampleContract {
    using ListInteger for *;
    using Strings for string;
    using Integers for uint;

    uint[] items;
}

ListInteger

add(uint)

Add unsigned integer to array

function example() public view returns (uint[]) {
    items.add(99);
    return items;
}

remove()

Remove item last index like function pop() in array

function example() public view returns (uint[]) {
    items.remove();
    return items;
}

removeByValue(uint)

Remove item by value in array

function example() public view returns (uint[]) {
    items.removeByValue(99);
    return items;
}

removeByIndex(uint)

Remove item by index in array start at 0

function example() public view returns (uint[]) {
    items.removeByIndex(0);
    return items;
}

find(uint) : uint

Find index by value in array

function example() public view returns (uint) {
    uint index = items.find(99);
    return index;
}

sort() : uint[]

Sort ascending unsigned integer in array

function example() public view returns (uint[]) {
    return items.sort();
}

sortDESC() : uint[]

Sort descending unsigned integer in array

function example() public view returns (uint[]) {
    return items.sortDESC();
}

getSize() : uint

Get size array

function example() public view returns (uint) {
    uint size = items.getSize();
    return size;
}

sum() : uint

Sum unsigned integer in array

function example() public view returns (uint) {
    uint result = items.sum();
    return result;
}

Strings

concat(string)

Join two strings

function example() {
    string memory str = "20scoops";
    str = str.concat(" ").concat("CNX");
}

length() : uint

Get the length of a string

function example() returns (uint) {
    string memory str = "20scoops CNX";
    return str.length();
}

replaceAll(bytes1, btyes1) : string

Replace all character in string

function example() public view returns (string) {
    string memory str = "20scoops CNX ";
    return str.replaceAll(" ", "");
}

replace(bytes1, bytes1) : string

Replace character in string

function example() public view returns (string) {
    string memory str = "20scoops CNX ";
    return str.replace(" ", "");
}

compareTo(string) : bool

Compare two string

function example() public view returns (bool) {
    string memory str = "20scoops CNX";
    return str.compareTo("20scoops");
}

Intergers

parseInt(string) : uint

Convert string to unsigned integer

function example() public view returns (uint) {
    return Integers.parseInt("99.00");
}

toString() : uint

Convert unsigned integer to string

function example(uint value) public view returns (string) {
    return value.toString();
}

plus(uint) : uint

Plus unsigned integer

function example() public view returns (uint) {
    uint myInt = 5;
    return myInt.plus(5);
}

minus(uint) : uint

Minus unsigned integer

function example() public view returns (string) {
    uint myInt = 5;
    return myInt.minus(5);
}

divide(uint) : uint

Divide unsigned integer

function example(uint value) public view returns (uint) {
    uint myInt = 5;
    return myInt.divide(5);
}

multiply(uint) : uint

Multiply unsigned integer to string

function example() public view returns (uint) {
    uint myInt = 5;
    return myInt.multiply(5);
}

mod(uint) : uint

Modular unsigned integer

function example() public view returns (string) {
    uint myInt = 500;
    return myInt.mod(6);
}

solidity-utils's People

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

solidity-utils's Issues

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.