{"id":18421188,"url":"https://github.com/brybrophy/enumitron","last_synced_at":"2025-04-13T11:59:16.338Z","repository":{"id":49607814,"uuid":"161711123","full_name":"brybrophy/enumitron","owner":"brybrophy","description":"An enumeration class written in TypeScript","archived":false,"fork":false,"pushed_at":"2021-06-12T06:34:11.000Z","size":46,"stargazers_count":1,"open_issues_count":1,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-04-13T11:59:12.783Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","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/brybrophy.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":"2018-12-14T00:33:50.000Z","updated_at":"2022-12-15T23:37:30.000Z","dependencies_parsed_at":"2022-09-15T03:00:23.698Z","dependency_job_id":null,"html_url":"https://github.com/brybrophy/enumitron","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/brybrophy%2Fenumitron","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Fenumitron/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Fenumitron/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/brybrophy%2Fenumitron/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/brybrophy","download_url":"https://codeload.github.com/brybrophy/enumitron/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248710434,"owners_count":21149188,"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":"2024-11-06T04:24:41.233Z","updated_at":"2025-04-13T11:59:16.314Z","avatar_url":"https://github.com/brybrophy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Enumitron\n\n![https://img.shields.io/github/license/brybrophy/enumitron?color=blue](https://img.shields.io/github/license/brybrophy/enumitron?color=blue) ![https://img.shields.io/npm/v/enumitron](https://img.shields.io/npm/v/enumitron) ![https://img.shields.io/bundlephobia/minzip/enumitron](https://img.shields.io/bundlephobia/minzip/enumitron) ![https://img.shields.io/librariesio/release/npm/enumitron](https://img.shields.io/librariesio/release/npm/enumitron)\n\n### Generate enumerations in many different forms.\n\nThis package can be used to create type-safe enumerations, and retrieve them as a dictionary, as an array of id's, as an array of names, or as an array of objects. You can also lookup a name by id.\n\n## Usage\n\n```javascript\nimport Enumitron from \"enumitron\";\n\nconst numbers = [\n  { id: 1, name: \"One\" },\n  { id: 2, name: \"Two\" },\n];\nconst numbersEnum = new Enumitron(numbers);\n```\n\n## Constraints\n\nAll enums are required to have unique names and ids. If there are objects with duplicate names or ids in the array that is passed into the Enumitron constructor, an error will be thrown.\n\nAny additional key/value pairs contained in the objects you pass in will be preserved. The values can be of any type.\n\n## Getters\n\n### asDictionary\n\n```javascript\nnumbersEnum.asDictionary;\n/* returns...\n{\n  One: { id: 1, name: 'One' },\n  Two: { id: 2, name: 'Two' }\n}\n*/\n```\n\n### asIds\n\n```javascript\nnumbersEnum.asIds;\n// returns [1, 2]\n```\n\n### asNames\n\n```javascript\nnumbersEnum.asNames;\n// returns ['One', 'Two'];\n```\n\n### asObjects\n\n```javascript\nnumbersEnum.asObjects;\n// returns [{ id: 1, name: 'One' }, { id: 2, name: 'Two' }];\n```\n\n## Methods\n\n### getNameById\n\n```javascript\nnumbersEnum.getNameById(1);\n// returns 'One';\n```\n\nIf a name is not found at the given id, an error will be thrown.\n\n## Additional Properties\n\nYou can include more than just `id` and `name` into an enumeration object. Whatever properties you include will be preserved and returned when `enum.asObject` or `enum.asDictionary` is called.\n\n```javascript\nimport Enumitron from \"enumitron\";\n\nconst numbers = [\n  { id: 1, name: \"One\", translations: { german: \"Ein\", spanish: \"Uno\" } },\n  { id: 2, name: \"Two\", translations: { german: \"Zwei\", spanish: \"Dos\" } },\n];\nconst numbersEnum = new Enumitron(numbers);\n\nnumbersEnum.asObjects;\n/* \nreturns \n[\n  { id: 1, name: \"One\", translations: { german: \"Ein\", spanish: \"Uno\" } },\n  { id: 2, name: \"Two\", translations: { german: \"Zwei\", spanish: \"Dos\" } },\n]\n*/\n```\n\n## Iteration\n\nTo make retrieval of enumerations more streamlined, the Enumitron class is implemented as a interable class. This allows you to access properties of the class at their indexes, and perform loops on the class.\n\n### For Loop\n\n```javascript\nfor (let i = 0; i \u003c numbersEnum.length; i++) {\n  doThingWithEnum(numbersEnum[i]);\n}\n```\n\n### For Of Loop\n\n```javascript\nfor (let item of numbersEnum) {\n  doThingWithEnum(item);\n}\n```\n\n### Index Access\n\n```javascript\nnumbersEnum[1];\n// returns { id: 2, name: 'Two' }\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrybrophy%2Fenumitron","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbrybrophy%2Fenumitron","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbrybrophy%2Fenumitron/lists"}