{"id":15587674,"url":"https://github.com/icyleaf/popcorn","last_synced_at":"2026-03-10T12:36:30.516Z","repository":{"id":136301405,"uuid":"141698566","full_name":"icyleaf/popcorn","owner":"icyleaf","description":"Easy and Safe popping from one type to another.","archived":false,"fork":false,"pushed_at":"2021-03-25T02:46:05.000Z","size":736,"stargazers_count":26,"open_issues_count":0,"forks_count":1,"subscribers_count":3,"default_branch":"master","last_synced_at":"2025-04-24T04:49:30.431Z","etag":null,"topics":["crystal","type-casting"],"latest_commit_sha":null,"homepage":"http://icyleaf.github.io/popcorn","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/icyleaf.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","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,"zenodo":null}},"created_at":"2018-07-20T10:27:38.000Z","updated_at":"2024-04-01T00:20:26.000Z","dependencies_parsed_at":"2023-07-24T07:16:09.812Z","dependency_job_id":null,"html_url":"https://github.com/icyleaf/popcorn","commit_stats":null,"previous_names":[],"tags_count":6,"template":false,"template_full_name":null,"purl":"pkg:github/icyleaf/popcorn","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fpopcorn","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fpopcorn/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fpopcorn/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fpopcorn/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/icyleaf","download_url":"https://codeload.github.com/icyleaf/popcorn/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/icyleaf%2Fpopcorn/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30333591,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T05:25:20.737Z","status":"ssl_error","status_checked_at":"2026-03-10T05:25:17.430Z","response_time":106,"last_error":"SSL_read: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["crystal","type-casting"],"created_at":"2024-10-02T22:02:50.712Z","updated_at":"2026-03-10T12:36:30.481Z","avatar_url":"https://github.com/icyleaf.png","language":"Crystal","funding_links":[],"categories":[],"sub_categories":[],"readme":"![popcorn-logo](https://github.com/icyleaf/popcorn/raw/master/logo-small.png)\n\n# Popcorn\n\n[![Language](https://img.shields.io/badge/language-crystal-776791.svg)](https://github.com/crystal-lang/crystal)\n[![Tag](https://img.shields.io/github/tag/icyleaf/popcorn.svg)](https://github.com/icyleaf/popcorn/blob/master/CHANGELOG.md)\n[![Build Status](https://img.shields.io/circleci/project/github/icyleaf/popcorn/master.svg?style=flat)](https://circleci.com/gh/icyleaf/popcorn)\n\nEasy and Safe popping from one type to another. Popcorn icon by HLD from the [Noun Project](https://thenounproject.com).\n\nBuild in Crystal version \u003e= `v0.31.0`.\n\n## Installation\n\nAdd this to your application's `shard.yml`:\n\n```yaml\ndependencies:\n  popcorn:\n    github: icyleaf/popcorn\n```\n\n## Usage\n\nPopcorn is easy and safe from one type to another tool.\n\nPopcorn proviedes a handful of `to_xxx`/`to_xxx?` methods and `xxx` is full type name,\nThis is distinguish between built-in methods in Crystal.\n\n- to_int8\n- to_int16\n- to_int (alias to to_int32)\n- to_int64\n- to_uint8\n- to_uint16\n- to_uint (alias to to_uint32)\n- to_uint64\n- to_float32\n- to_float64\n- to_bool\n- to_time(location : Time::Location? = nil, formatters : Array(String)? = nil)\n- to_array(target : T.class = String)\n- to_hash(target : T.class = String)\n- to_string (alias to to_s in Crystal).\n\n```crystal\nrequire \"popcorn\"\n\nPopcorn.to_sting(\"foobar\")                                                    # =\u003e \"foobar\"\nPopcorn.to_string(8.31)                                                       # =\u003e \"8.31\"\nPopcorn.to_int(\"1\")                                                           # =\u003e 1\nPopcorn.to_int(\"123abc\")                                                      # =\u003e 123\nPopcorn.to_bool(\"no\")                                                         # =\u003e false\nPopcorn.to_bool(\"unkown\")                                                     # =\u003e raise a `TypeCastError` exception\nPopcorn.to_bool?(\"unkown\")                                                    # =\u003e nil\nPopcorn.to_time(\"2018-07-23T10:11:22\")                                        # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location::UTC)\nPopcorn.to_time(\"2018-07-23T10:11:22Z\", Time::Location.load(\"Asia/Shanghai\")) # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location.load(\"Asia/Shanghai\"))\nPopcorn.to_time(\"Tue, 20 Jan 2018\", formatter: [\"%a, %d %b %Y\"])              # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location::UTC)\n```\n\nAlso these methods had been inject to Crystal literals, you can call it directly, Monkey Patching list:\n\n- String\n- Int\n- Float\n- Bool\n- Time\n- Symbol\n- NamedTupe\n- Array\n- Hash\n- Nil\n- JSON::Any\n- YAML::Any\n\n```crystal\nrequire \"popcorn\"\nrequire \"popcorn/injection\" # =\u003e make sure require it!\n\n\"foobar\".to_string                                                   # =\u003e \"foobar\"\n8.31.to_string                                                       # =\u003e \"8.31\"\n\"1\".to_int                                                           # =\u003e 1\n\"123abc\".to_int                                                      # =\u003e 123\n\"no\".to_bool                                                         # =\u003e false\n\"unkown\".to_bool                                                     # =\u003e raise a `TypeCastError` exception\n\"unkown\".to_bool?                                                    # =\u003e nil\n\"2018-07-23T10:11:22\".to_time                                        # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location::UTC)\n\"2018-07-23T10:11:22Z\".to_time(Time::Location.load(\"Asia/Shanghai\")) # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location.load(\"Asia/Shanghai\"))\n\"Tue, 20 Jan 2018\".to_time(formatter: [\"%a, %d %b %Y\"])              # =\u003e Time.local(2018, 7, 23, 10, 11, 22, location: Time::Location::UTC)\n```\n\n## Casting unmatch class\n\nBy desgin in Crystal, we can not match type with `T`(no override by alone type) and no time to match each shard type. so you can write your own.\n\nReference at [totem](https://github.com/icyleaf/totem/blob/b8bfca5f7a6ded111fc5074205dad7a205040b1d/src/totem/any.cr#L256).\n\n## Contributing\n\n1. Fork it (\u003chttps://github.com/icyleaf/popcorn/fork\u003e)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [icyleaf](https://github.com/icyleaf) icyleaf - creator, maintainer\n\n## You may also like\n\n- [halite](https://github.com/icyleaf/halite) - Crystal HTTP Requests Client with a chainable REST API, built-in sessions and middlewares.\n- [totem](https://github.com/icyleaf/totem) - Load and parse a configuration file or string in JSON, YAML, dotenv formats.\n- [poncho](https://github.com/icyleaf/poncho) - A .env parser/loader improved for performance.\n- [fast-crystal](https://github.com/icyleaf/fast-crystal) - 💨 Writing Fast Crystal 😍 -- Collect Common Crystal idioms.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyleaf%2Fpopcorn","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ficyleaf%2Fpopcorn","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ficyleaf%2Fpopcorn/lists"}