{"id":13732487,"url":"https://github.com/willitscale/solidity-util","last_synced_at":"2025-03-17T00:32:08.752Z","repository":{"id":41113893,"uuid":"103840596","full_name":"willitscale/solidity-util","owner":"willitscale","description":"Solidity Standard Utilities","archived":false,"fork":false,"pushed_at":"2023-10-01T07:02:52.000Z","size":29,"stargazers_count":133,"open_issues_count":4,"forks_count":34,"subscribers_count":8,"default_branch":"master","last_synced_at":"2024-10-13T13:08:26.433Z","etag":null,"topics":["hacktoberfest"],"latest_commit_sha":null,"homepage":"","language":"Solidity","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/willitscale.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2017-09-17T15:42:18.000Z","updated_at":"2024-08-11T04:25:15.000Z","dependencies_parsed_at":"2024-01-12T18:32:02.305Z","dependency_job_id":"1537a565-e330-486c-8502-d9343df5a969","html_url":"https://github.com/willitscale/solidity-util","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fsolidity-util","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fsolidity-util/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fsolidity-util/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/willitscale%2Fsolidity-util/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/willitscale","download_url":"https://codeload.github.com/willitscale/solidity-util/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":221669317,"owners_count":16860853,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["hacktoberfest"],"created_at":"2024-08-03T02:01:59.039Z","updated_at":"2024-10-27T11:35:16.839Z","avatar_url":"https://github.com/willitscale.png","language":"Solidity","funding_links":[],"categories":["Solidity"],"sub_categories":[],"readme":"# Solidity Standard Utilities\n\nSolidity is still very primitive and doing basic operations can be quite tedious and off-putting to newer developers. I've put together a very basic library of functions to help improve this. \n\nThe easiest way to use this library is to install it with npm as\n```bash\nnpm install willitscale/solidity-util\n```\n\nIn a project based on [Truffle framework](https://truffleframework.com/) you may then import and bind the libraries to the appropriate data types as seen below:\n```javascript\npragma solidity ^0.5.0;\n\nimport \"solidity-util/lib/Strings.sol\";\nimport \"solidity-util/lib/Integers.sol\";\nimport \"solidity-util/lib/Addresses.sol\";\n\ncontract MyContract {\n    using Strings for string;\n    using Integers for uint;\n    using Addresses for address;\n    using Addresses for address payable;\n}\n```\nThis will then allow the use of the functionality listed below.\n\nOther frameworks may require slightly different approaches than the description above.\n\n## Addresses\n\nThe functionality of this library is to extend the existing functionality of an address:\n- [isContract\\(address\\) : bool](#iscontractaddress--bool)\n\n### isContract(address) : bool \n\nCheck to see if the subject address is a contract on the Ethereum network\n\n```javascript\n    function isContract(address _addr) public {\n        if (_addr.isContract()) {\n            // Do contract specific stuff\n        }\n    }\n```\n\n## Integers\n\nThe functionality of this library is based loosely around the Java implementation:\n- [parseInt\\(string\\) : uint](#parseintstring--uint)\n- [toString\\(\\) : uint](#tostring--uint)\n- [toBytes\\(uint\\) : bytes](#tobytesuint--bytes)\n- [toByte\\(uint8\\) : byte](#tobyteuint8--byte)\n\n### parseInt(string) : uint \n\nConvert an ASCII string to its unsigned integer equivalent\n\n```javascript\n    function parseInt() {\n        if (321 == Integers.parseInt(\"321\")) {\n            // Matches the uint value\n        }\n    }\n```\n\n### toString() : uint \n\nConvert an unsigned integer to its ASCII string equivalent\n\n```javascript\n    function toString(uint _value) returns (string) {\n        return _value.toString();\n    }\n```\n\n### toBytes(uint) : bytes \n\nConvert an unsigned integer to a bytes equivalent\n\n```javascript\n    function toString(uint _value) returns (bytes) {\n        return _value.toBytes();\n    }\n```\n\n### toByte(uint8) : byte \n\nConvert an 8-bit unsigned integer to its byte equivalent\n\n```javascript\n    function toByte(uint8 _value) {\n        if (0x1 == Integer.toByte(_value)) {\n            // Matching byte\n        }\n    }\n```\n\n## Strings\n\n**Please be aware that some of these functions can be quite gas heavy so use appropriately!**\n\nThe functionality of this library is based loosely around the Java implementation:\n- [concat\\(string\\) : string](#concatstring--string)\n- [indexOf\\(string\\) : int](#indexofstring--int)\n- [length\\(\\) : uint](#length--uint)\n- [substring\\(uint\\) : string](#substringuint--string)\n- [split\\(string\\) : string\\[\\]](#splitstring--string)\n- [compareTo\\(string\\) : bool](#comparetostring--bool)\n- [compareToIgnoreCase\\(string\\) : bool](#comparetoignorecasestring--bool)\n- [upper\\(string\\) : string](#upperstring--string)\n- [lower\\(string\\) : string](#lowerstring--string)\n\n\n### concat(string) : string \n\nConcatenate two strings together.\n\n```javascript\n    function concat() {\n        string memory myVal = \"firstname\";\n        myVal = myVal.concat(\" \").concat(\"lastname\");\n    }\n```\n\n### indexOf(string) : int\n\nFind the position of a character.\n\n```javascript\n    function indexOf() {\n        string memory myVal = \"haystack\";\n        uint positionOfFirstA = myVal.indexOf(\"a\");\n        uint positionOfSecondA = myVal._indexOf(\"a\", positionOfFirstA+1);\n    }\n```\n\n### length() : uint\n\nGet the length of a string.\n\n```javascript\n    function length() {\n        string memory myVal = \"length\";\n        if (myVal.length() == 6) {\n          // Length is 6!\n        }\n    }\n```\n\n### substring(uint) : string\n\nGet a partial section of the string.\n\n```javascript\n    function substring() {\n        string memory myVal = \"sub string example\";\n        string memory firstWord = myVal.substring(3);\n        string memory secondWord = myVal._substring(6,4);\n    }\n```\n\n### split(string) : string[]\n\nSplits a string into an array of smaller strings based off a delimiter.\n\n```javascript\n    function split() {\n        string memory myVal = \"my example split\";\n        string[] storage split = myVal.split(\" \");\n        if (3 == split.length) {\n          if(split[1].compareTo(\"example\")) {\n            // Valid split length and second word\n          }\n        }\n    }\n```\n\n### compareTo(string) : bool\n\nCompare two strings.\n\n```javascript\n    function compareTo() {\n        string memory myVal = \"my example split\";\n        if(myVal.compareTo(\"my example split\")) {\n          // They match!\n        }\n    }\n```\n\n### compareToIgnoreCase(string) : bool\n\nCompare two strings discarding alphabetic case.\n\n```javascript\n    function compareToIgnoreCase() {\n        string memory myVal = \"my example split\";\n        if(myVal.compareTo(\"mY Example Split\")) {\n          // They match regardless of case!\n        }\n    }\n```\n\n### upper(string) : string\n\nConverts a string to use upper alphabetic case.\n\n```javascript\n    function upper() {\n        string memory myVal = \"lower\";\n        if(myVal.upper().compareTo(\"LOWER\")) {\n          // It's now upper!\n        }\n    }\n```\n\n### lower(string) : string\n\n\nConverts a string to use lower alphabetic case.\n\n```javascript\n    function lower() {\n        string memory myVal = \"UPPER\";\n        if (myVal.lower().compareTo(\"upper\")) {\n          // It's now lower!\n        }\n    }\n```\n\nFeel free to contribute!\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillitscale%2Fsolidity-util","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fwillitscale%2Fsolidity-util","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fwillitscale%2Fsolidity-util/lists"}