{"id":15825347,"url":"https://github.com/traffician/objective-enums","last_synced_at":"2026-04-29T17:36:49.361Z","repository":{"id":57312920,"uuid":"134983651","full_name":"Traffician/objective-enums","owner":"Traffician","description":"Objective-like Enumerated Types in JavaScript and Node","archived":false,"fork":false,"pushed_at":"2018-09-05T16:52:18.000Z","size":27,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-10-12T09:37:49.089Z","etag":null,"topics":["ecmascript","enum","enumerated-types","javascript","nodejs","objective-like"],"latest_commit_sha":null,"homepage":"","language":"JavaScript","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/Traffician.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-05-26T17:59:08.000Z","updated_at":"2018-09-05T16:52:19.000Z","dependencies_parsed_at":"2022-09-20T23:10:56.426Z","dependency_job_id":null,"html_url":"https://github.com/Traffician/objective-enums","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/Traffician%2Fobjective-enums","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traffician%2Fobjective-enums/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traffician%2Fobjective-enums/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Traffician%2Fobjective-enums/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Traffician","download_url":"https://codeload.github.com/Traffician/objective-enums/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246620102,"owners_count":20806715,"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":["ecmascript","enum","enumerated-types","javascript","nodejs","objective-like"],"created_at":"2024-10-05T09:08:18.577Z","updated_at":"2026-04-29T17:36:49.328Z","avatar_url":"https://github.com/Traffician.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Objective-like enums\r\n\r\nYet another JavaScript library introducing Enumerated Types 😊\r\n\r\nIt was inspired by C#'s enums and that's why it allows for **comparing types**, **serialization** and **flagging**.\r\n\r\n\r\n## Installation\r\n\r\n`npm install --save objective-enums`\r\n\r\n\r\n## Contributing\r\n**All pull requests are welcome!**\r\n\r\nLibrary is distributed as Babel-compiled code. If you want to contribute, clone GitHub repo, make changes and create pull request. \r\n\r\nYou can build the code by using `npm run dev` or `npm run prod` commands. There is also *file watching* feature - `npm run watch`, so you don't have to rebuild all sources again after modyfing some scripts.\r\n\r\n## Testing\r\n@TODO\r\n\r\n# Examples #\r\n\r\n## Quick start\r\n\r\n```javascript\r\nimport Enum from 'objective-enums';\r\n\r\nconst Colors = new Enum('Red', 'Yellow', 'Green', 'Blue');\r\nconst allowedColors = Colors.Green | Colors.Blue;\r\n\r\n// Get color value and name\r\nconsole.log(Colors.Red + ' - ' + Colors.Red.toString()); // 1 - Red\r\n\r\n// Check if red is an allowed color\r\nconsole.log(Colors.hasFlag(allowedColors, Colors.red)); // false\r\n\r\n// Get names of allowed colors\r\nconsole.log(Colors.match(allowedColors)); // [\"Green\", \"Blue\"]\r\n\r\n// Get common elements' names of allowed and selected colors\r\nconst selectedColors = Colors.Red | Colors.Green | Colors.Yellow;\r\nconsole.log(Colors.intersect(allowedColors, selectedColors)); // [\"Green\"]\r\n```\r\n\r\n## Flagging operations\r\n```javascript\r\nimport Enum from 'objective-enums';\r\n\r\nconst Colors = new Enum('Red', 'Yellow', 'Green', 'Blue');\r\n\r\n// Only green and blue are allowed colors\r\nlet allowed = Colors.Green | Colors.Blue;\r\n\r\n// Get names of allowed colors\r\nconsole.log(Colors.match(allowed)); // [\"Green\", \"Blue\"]\r\n\r\n// Add yellow to allowed colors\r\nallowed |= Colors.Yellow;\r\nconsole.log(Colors.match(allowed)); // [\"Green\", \"Blue\", \"Yellow\"]\r\n\r\n// Remove blue from allowed colors\r\nallowed \u0026= ~Colors.Blue;\r\nconsole.log(Colors.match(allowed)); // [\"Green\", \"Yellow\"]\r\n```\r\n\r\n## Custom values\r\n```javascript\r\nimport Enum from 'objective-enums';\r\n\r\nconst Colors = new Enum({\r\n    Red: '#FF0000',\r\n    Yellow: {r: 255, g: 255, b: 0},\r\n    Green: 0x008000,\r\n    Blue: true\r\n});\r\n\r\nconsole.log(Colors.Yellow.value); // {r: 255, g: 255, b: 0}\r\n```\r\n\r\n## Custom typing and comparing\r\n```javascript\r\nimport Enum from 'objective-enums';\r\n\r\nconst JewelleryEnum = class Jewellery extends Enum {};\r\nconst Jewellery = new JewelleryEnum('Amethysts', 'Diamonds', 'Emeralds', 'Gems');\r\n\r\nconst Cards = new (class Cards extends Enum {})([\r\n    'Clubs', 'Diamonds', 'Spades', 'Hearts'\r\n]);\r\n\r\nconsole.log(Jewellery instanceof Enum); // true\r\n\r\nconsole.log(Cards.constructor.name); // Cards\r\n\r\nconsole.log(Jewellery.Amethysts.constructor.name); // JewelleryElement\r\n\r\nconsole.log(Cards.Spades.constructor.name); // CardsElement\r\n\r\nconsole.log(Jewellery.Diamonds === Cards.Diamonds); // false\r\n\r\nconst someStones = Jewellery.Diamonds | Jewellery.Gems;\r\nconsole.log(Jewellery.hasFlag(someStones, 'Spades'));\r\n// NotAnElementOf: Spades is not an element of Jewellery\r\n\r\n```","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraffician%2Fobjective-enums","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftraffician%2Fobjective-enums","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftraffician%2Fobjective-enums/lists"}