{"id":18536073,"url":"https://github.com/khalidsheet/enum-utils","last_synced_at":"2025-05-15T00:34:45.678Z","repository":{"id":186148355,"uuid":"674746146","full_name":"khalidsheet/enum-utils","owner":"khalidsheet","description":"Enum Utils is a utility function that allows you to create enum-like objects with read-only properties in JavaScript.","archived":false,"fork":false,"pushed_at":"2023-08-04T17:23:46.000Z","size":4,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-26T06:33:19.988Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/khalidsheet.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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":"2023-08-04T17:02:59.000Z","updated_at":"2023-08-04T18:36:55.000Z","dependencies_parsed_at":null,"dependency_job_id":"7b25eb85-b2c0-49cb-9465-ce3110fda4f2","html_url":"https://github.com/khalidsheet/enum-utils","commit_stats":null,"previous_names":["khalidsheet/enum-utils"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalidsheet%2Fenum-utils","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalidsheet%2Fenum-utils/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalidsheet%2Fenum-utils/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/khalidsheet%2Fenum-utils/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/khalidsheet","download_url":"https://codeload.github.com/khalidsheet/enum-utils/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":239251067,"owners_count":19607560,"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-06T19:29:49.630Z","updated_at":"2025-02-17T07:28:19.091Z","avatar_url":"https://github.com/khalidsheet.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)\n\n# Enum Utility\n\nEnum Utility is a utility function that allows you to create enum-like objects with read-only properties in JavaScript.\n\n## Installation\n\nYou can install Enum Utility using npm:\n\n```sh\nnpm install enum-utility\n```\n\n## Usage\n```js\n// Import the createEnum function\nimport createEnum from 'enum-utility';\n\n// Create an enum-like object\nconst colors = createEnum({\n  RED: 'red',\n  BLUE: 'blue',\n  GREEN: 'green',\n});\n\nconsole.log(colors.RED); // Output: red\nconsole.log(colors.BLUE); // Output: blue\n```\n\n---\n\n## API\n`createEnum(enumObject)`\nCreate an enum-like object.\n\n- `enumObject` (Object): An object containing the enum values by thier keys.\n\nReturns: A Proxy object that allows accessing the enum values by their keys.\n\nThrows:\n\n- **Error** if enumObject is not an object.\n- **Error** if enumObject is empty.\n- **Error** if values in enumObject are not strings or numbers.\n- **Error** if accessing a key that doesn't exist in the enum.\n- **Error** if attempting to set a value (enum is read-only).\n\n---\n## Examples\n```js\nimport createEnum from 'enum-utility';\n\nconst daysOfWeek = createEnum({\n  SUNDAY: 'sunday',\n  MONDAY: 'monday',\n  TUESDAY: 'tuesday',\n  // ... and so on\n});\n\nconsole.log(daysOfWeek.SUNDAY); // Output: sunday\nconsole.log(daysOfWeek.WEDNESDAY); // Throws an Error: Invalid key, WEDNESDAY does not exist\n```\n\n## License\nMIT License\n\nCopyright (c) 2023 Khalid M. Sheet\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalidsheet%2Fenum-utils","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkhalidsheet%2Fenum-utils","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkhalidsheet%2Fenum-utils/lists"}