{"id":28194328,"url":"https://github.com/humansinput/hasheval","last_synced_at":"2025-05-16T13:12:09.039Z","repository":{"id":128773473,"uuid":"350947215","full_name":"humansinput/hasheval","owner":"humansinput","description":"Convert stringified Ruby/Crystal hashes to native ones (String -\u003e Hash)","archived":false,"fork":false,"pushed_at":"2021-03-24T11:13:15.000Z","size":14,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T09:12:03.101Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Crystal","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/humansinput.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"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,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2021-03-24T04:37:53.000Z","updated_at":"2024-01-02T12:05:31.000Z","dependencies_parsed_at":"2023-04-29T17:31:41.517Z","dependency_job_id":null,"html_url":"https://github.com/humansinput/hasheval","commit_stats":null,"previous_names":["humansinput/hasheval"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fhasheval","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fhasheval/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fhasheval/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/humansinput%2Fhasheval/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/humansinput","download_url":"https://codeload.github.com/humansinput/hasheval/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":254535799,"owners_count":22087400,"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":[],"created_at":"2025-05-16T13:11:53.175Z","updated_at":"2025-05-16T13:12:09.025Z","avatar_url":"https://github.com/humansinput.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"# HashEval\n\nCopyright (C) Tim K 2021 \u003ctimprogrammer@rambler.ru\u003e\n\nLicensed under [MIT License](LICENSE).\n\n## What is this thing all about?\n\n**HashEval** is a Crystal library that converts stringified hashes that utilize only basic built-in types like ``String``,`` Int32``, etc into actual hashes. \n\nHashEval supports three forms of string-converted syntaxes:\n\n- The default Crystal/Ruby one \n\n```crystal\n{:salary =\u003e 12000, :currency =\u003e \"RUB\", :including_taxes =\u003e true}\n```\n\n- the simplified hash syntax supported by Crystal (which was originally introduced in Ruby 1.9)\n\n```crystal\n{salary: 12000, currency: \"RUB\", including_taxes: true}\n```\n\n- Haml's HTML-like attributes hash format\n\n```haml\n(salary=12000 currency=\"RUB\" including_taxes)\n```\n\n## How do you use this?\n\nFirst, include the library in your ``shard.yml`` file (that is, if you use shards):\n\n```yaml\ndependencies:\n   hasheval:\n      github: tenfensw/hasheval\n```\n\nThen just include it from your code and use the sole public method provided by the ``HashEval`` module:\n\n```crystal\nrequire \"hasheval\"\n\nHashEval.eval(\"{\\\"chunky_bacon\\\" =\u003e false}\") # =\u003e {\"chunky_bacon\" =\u003e false} \u003c- Hash(String, Bool)\n```\n\nBy the way, HashEval automatically detects the specified stringified hash format, so there is no need to worry about that as long as it is correctly syntaxed.\n\n```crystal\nHashEval.eval(\"{ruby: false, crystal: true}\") # =\u003e {\"ruby\" =\u003e false, \"crystal\" =\u003e true} \u003c- Hash(String, Bool)\n```\n\nAlso, as you can see, due to Crystal limitations and strict typing system, symbols are always converted to strings when used as keys. There are also some other limitations, like no way to reference global variables or even constants as well as lack of support of arrays inside hashes or any types that are not `String`, `Bool`, `Int32`, `BigFloat` and `Nil`, but this might change in the future.\n\n----\n\nIf HashEval encounters a syntax error, it throws a ``HashEval::ParsingException``:\n\n```crystal\nrequire \"hasheval\"\n\nbegin\n\tHashEval.eval(\"{\\\"referencing_a_var\\\" =\u003e variable1}\") # invalid syntax\nrescue ex : HashEval::ParsingException\n\tputs \"Syntax error - #{ex}\"\nend\n```\n\n---\n\nOh, and HashEval also has a more readable `String` and `Hash` extension syntax:\n\n```crystal\nrequire \"hasheval\"\n\ntesthash = {:name =\u003e \"Tim K\", :os =\u003e \"macOS\"}\ntesthash_string = testhash.to_s\n\ntesthash_string.to_hash # same as HashEval.eval(testhash_string)\n```\n\n## Requirements\n\nBasically, HashEval will run anywhere where at least Crystal 0.34.0 is supported. Older versions might work too, but they are untested.\n\n## Unit tests\n\nIf you have this habit of testing if a library works after compilation before you install it, you can run the unit tests provided in this repo:\n\n```bash\n$ shards --ignore-crystal-version # get minitest\n$ crystal unit/unit.cr\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumansinput%2Fhasheval","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhumansinput%2Fhasheval","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhumansinput%2Fhasheval/lists"}