{"id":19635435,"url":"https://github.com/neoxelox/enum","last_synced_at":"2025-02-26T21:41:43.455Z","repository":{"id":57571036,"uuid":"347145137","full_name":"neoxelox/enum","owner":"neoxelox","description":"Golang Enumerators","archived":false,"fork":false,"pushed_at":"2021-05-02T00:30:05.000Z","size":18,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-01-09T16:22:30.950Z","etag":null,"topics":["enum","enumerator","enums","go","go-enum","golang","neoxelox","simple","type"],"latest_commit_sha":null,"homepage":"","language":"Go","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/neoxelox.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}},"created_at":"2021-03-12T17:28:48.000Z","updated_at":"2021-05-02T00:30:08.000Z","dependencies_parsed_at":"2022-09-17T15:42:28.233Z","dependency_job_id":null,"html_url":"https://github.com/neoxelox/enum","commit_stats":null,"previous_names":[],"tags_count":9,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxelox%2Fenum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxelox%2Fenum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxelox%2Fenum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/neoxelox%2Fenum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/neoxelox","download_url":"https://codeload.github.com/neoxelox/enum/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240941484,"owners_count":19882062,"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":["enum","enumerator","enums","go","go-enum","golang","neoxelox","simple","type"],"created_at":"2024-11-11T12:25:15.031Z","updated_at":"2025-02-26T21:41:43.438Z","avatar_url":"https://github.com/neoxelox.png","language":"Go","funding_links":[],"categories":[],"sub_categories":[],"readme":"# enum ![Integration](https://github.com/Neoxelox/enum/workflows/Integration/badge.svg)\n\n**📑 `Golang Enumerators` 📑**\n\n## What\n\nEnum is a package that provides simple enumerators for Go, with IDE autocompletion and any type support. It may not be the prettiest syntax, but it's so useful.\n\n## Install\n\n**`go get github.com/neoxelox/enum`**\n\n## Usage\n\n**`Create Enum`**\n\n```go\npackage main\n\nimport (\n\t\"fmt\"\n\n\t\"github.com/neoxelox/enum\"\n)\n\ntype State string\n\ntype enumStates = struct {\n\tCOMMITTED   State  // You can use any type you want, for example an int.\n\tIN_PROGRESS State\n\tDONE        State\n\tenum.Enum\n}\n\nvar States = enum.New(\u0026enumStates{\n\tCOMMITTED:   \"COMMITTED\",\n\tIN_PROGRESS: \"BLOCKED\",\n\tDONE:        \"DONE\",\n}).(*enumStates)\n\nfunc main() {\n\tfmt.Println(States.DONE)\n}\n```\n\nCreating a custom type, from a primitive type, for the enum fields (as in the example above), will provide _lite type assertion_, that is, `States.COMMITTED == \"COMMITTED\"` will evaluate to `true`. If you want full type assertion, you can create `type State struct{ string }`, and use that type as the type for the enum fields `COMMITTED: State{\"COMMITTED\"}`. Now you can't compare `States.COMMITTED == \"COMMITTED\"`. However, you will need to create your own `String`, `Marshalling`, `Text`... methods, to deal with serialization correctly.\n\n**`Check if Alias is in Enum`**\n\n```go\nStates.Is(\"COMMITTED\")  // true\nStates.Is(\"COMPLETED\")  // false\nStates.Is(\"BLOCKED\")  // false\n```\n\n**`Get Enum Aliases`**\n\n```go\nStates.Aliases()  // [COMMITTED IN_PROGRESS DONE]\n```\n\n**`Check if Value is in Enum`**\n\n```go\nStates.In(State(\"COMMITTED\"))  // true\nStates.In(State(\"BLOCKED\"))  // true\nStates.In(State(\"IN_PROGRESS\"))  // false\nStates.In(State(\"COMPLETED\"))  // false\n```\n\n**`Get Enum Values`**\n\n```go\nStates.Values()  // [COMMITTED BLOCKED DONE]\n```\n\nSee [`GoDev`](https://pkg.go.dev/github.com/neoxelox/enum) for further documentation.\n\n## Contribute\n\nFeel free to contribute to this project : ) .\n\n## License\n\nThis project is licensed under the [MIT License](https://opensource.org/licenses/MIT) - read the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoxelox%2Fenum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fneoxelox%2Fenum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fneoxelox%2Fenum/lists"}