{"id":20780194,"url":"https://github.com/xotic750/enumify-x","last_synced_at":"2026-04-23T06:31:26.525Z","repository":{"id":21955916,"uuid":"94399500","full_name":"Xotic750/enumify-x","owner":"Xotic750","description":"Enumerated type library.","archived":false,"fork":false,"pushed_at":"2022-12-30T01:51:47.000Z","size":4849,"stargazers_count":0,"open_issues_count":20,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-02-19T02:14:57.562Z","etag":null,"topics":["browser","enum","javascript","library","nodejs"],"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/Xotic750.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":"2017-06-15T04:25:01.000Z","updated_at":"2020-01-31T12:07:38.000Z","dependencies_parsed_at":"2023-01-11T21:25:31.529Z","dependency_job_id":null,"html_url":"https://github.com/Xotic750/enumify-x","commit_stats":null,"previous_names":[],"tags_count":25,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotic750%2Fenumify-x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotic750%2Fenumify-x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotic750%2Fenumify-x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Xotic750%2Fenumify-x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Xotic750","download_url":"https://codeload.github.com/Xotic750/enumify-x/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243123580,"owners_count":20240045,"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":["browser","enum","javascript","library","nodejs"],"created_at":"2024-11-17T13:32:47.072Z","updated_at":"2025-12-25T06:12:05.558Z","avatar_url":"https://github.com/Xotic750.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003ca\n  href=\"https://travis-ci.org/Xotic750/enumify-x\"\n  title=\"Travis status\"\u003e\n\u003cimg\n  src=\"https://travis-ci.org/Xotic750/enumify-x.svg?branch=master\"\n  alt=\"Travis status\" height=\"18\"\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://david-dm.org/Xotic750/enumify-x\"\n  title=\"Dependency status\"\u003e\n\u003cimg src=\"https://david-dm.org/Xotic750/enumify-x/status.svg\"\n  alt=\"Dependency status\" height=\"18\"/\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://david-dm.org/Xotic750/enumify-x?type=dev\"\n  title=\"devDependency status\"\u003e\n\u003cimg src=\"https://david-dm.org/Xotic750/enumify-x/dev-status.svg\"\n  alt=\"devDependency status\" height=\"18\"/\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://badge.fury.io/js/enumify-x\"\n  title=\"npm version\"\u003e\n\u003cimg src=\"https://badge.fury.io/js/enumify-x.svg\"\n  alt=\"npm version\" height=\"18\"\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://www.jsdelivr.com/package/npm/enumify-x\"\n  title=\"jsDelivr hits\"\u003e\n\u003cimg src=\"https://data.jsdelivr.com/v1/package/npm/enumify-x/badge?style=rounded\"\n  alt=\"jsDelivr hits\" height=\"18\"\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://bettercodehub.com/results/Xotic750/enumify-x\"\n  title=\"bettercodehub score\"\u003e\n\u003cimg src=\"https://bettercodehub.com/edge/badge/Xotic750/enumify-x?branch=master\"\n  alt=\"bettercodehub score\" height=\"18\"\u003e\n\u003c/a\u003e\n\u003ca\n  href=\"https://coveralls.io/github/Xotic750/enumify-x?branch=master\"\n  title=\"Coverage Status\"\u003e\n\u003cimg src=\"https://coveralls.io/repos/github/Xotic750/enumify-x/badge.svg?branch=master\"\n  alt=\"Coverage Status\" height=\"18\"\u003e\n\u003c/a\u003e\n\n\u003ca name=\"module_enumify-x\"\u003e\u003c/a\u003e\n\n## enumify-x\n\nEnumerated type library.\n\n**Author**: Xotic750 \u003cXotic750@gmail.com\u003e  \n**License**: [MIT](https://opensource.org/licenses/MIT)  \n**Copyright**: Xotic750\n\n- [enumify-x](#module_enumify-x)\n  - [`module.exports`](#exp_module_enumify-x--module.exports) ⇒ \u003ccode\u003eObject\u003c/code\u003e ⏏\n    - [`~create`](#module_enumify-x--module.exports..create) ⇒ \u003ccode\u003efunction\u003c/code\u003e\n\n\u003ca name=\"exp_module_enumify-x--module.exports\"\u003e\u003c/a\u003e\n\n### `module.exports` ⇒ \u003ccode\u003eObject\u003c/code\u003e ⏏\n\nAn enumeration is a set of symbolic names (members) bound to unique, constant\nvalues. Within an enumeration, the members can be compared by identity, and\nthe enumeration itself can be iterated over.\nInfluenced by Python's Enum implimentation.\n\nCreate an enum name/value. Not usually called directly.\n\n**Kind**: Exported member  \n**Returns**: \u003ccode\u003eObject\u003c/code\u003e - The enum.  \n**See**: [https://docs.python.org/3/library/enum.html](https://docs.python.org/3/library/enum.html)\n\n| Param | Type                | Description                  |\n| ----- | ------------------- | ---------------------------- |\n| name  | \u003ccode\u003estring\u003c/code\u003e | The name of the enum.        |\n|       | \u003ccode\u003e\\*\u003c/code\u003e     | value The value of the enum. |\n\n\u003ca name=\"module_enumify-x--module.exports..create\"\u003e\u003c/a\u003e\n\n#### `module.exports~create` ⇒ \u003ccode\u003efunction\u003c/code\u003e\n\nCreates an enumeration collection. Primary method.\n\n**Kind**: inner property of [\u003ccode\u003emodule.exports\u003c/code\u003e](#exp_module_enumify-x--module.exports)  \n**Returns**: \u003ccode\u003efunction\u003c/code\u003e - The enumeration collection.\n\n| Param      | Type                | Description                      |\n| ---------- | ------------------- | -------------------------------- |\n| typeName   | \u003ccode\u003estring\u003c/code\u003e | The name of the enum collection. |\n| properties | \u003ccode\u003eArray\u003c/code\u003e  | Initialiser array.               |\n| options    | \u003ccode\u003eObject\u003c/code\u003e | Options to determine behaviour.  |\n\n**Example**\n\n```js\nimport Enum from 'enumify-x';\n\n// Creating an Enum\n// Example allows duplicate values, known as aliases.\n// Member values can be anything: number, string, etc.. If the exact value is\n// unimportant you may use auto instances and an appropriate value will be\n// chosen for you. Care must be taken if you mix auto with other values.\n//\n// The class color is an enumeration (or enum)\n// The attributes color.RED, color.GREEN, etc., are enumeration members\n// (or enum members) and are functionally constants.\n// The enum members have names and values (the name of color.RED is RED,\n// value of color.BLUE is 10, etc.)\nconst color = Enum.create('color', [\n  'RED', // auto assign value, starting 0\n  'YELLOW', // auto assign value, will be 1\n  {name: 'BLUE', value: 10},\n  'PINK', // auto assign value, will be 11\n  {name: 'BLACK', value: 1}, // This is an alias for YELLOW\n]);\n\nconsole.log(color.YELLOW); // { name: 'YELLOW', value: 1 }\nconsole.log(color.BLUE.name); // 'BLUE'\nconsole.log(color.BLUE.value); // 10\nconsole.log(color.BLACK === color.YELLOW); // true\n// Enumeration members have human readable string representations.\ncolor.PINK.toString(); // 'color.PINK'\n// Enums also have a human readable string representations.\ncolor.toString(); // 'color { \"RED\", \"YELLOW\", \"BLUE\", \"PINK\", \"BLACK\" }'\n// The type of an enumeration member is the enumeration it belongs to.\nconsole.log(color.PINK instanceof color); // true\n// You can access by value too.\nconsole.log(color(10)); // color.BLUE\n\n// Enumeration members are hashable, so they can be used as property names.\nconst apples = {};\napples[color.RED] = 'Red Delicious';\napples[color.YELLOW] = 'Golden Delicious';\nconsole.log(apples); // {color.RED: 'Red Delicious', color.YELLOW: 'Golden Delicious'}\n\n// No aliases are allowed in this example.\nconst opts = {\n  unique: true,\n};\n\n// Having two enum members with the same name is invalid\nEnum.create('fail', ['RED', 'RED'], opts);\n\n// However, two enum members are allowed to have the same value. Given two\n// members A and B with the same value (and A defined first), B is an alias\n// to A. By-value lookup of the value of A and B will return A. By-name\n// lookup of B will also return A. as seen in the definition of color.\n\nconst color1 = Enum.create('color1', ['RED', 'YELLOW'], opts);\n\n// Depending on the value types used, enumerations are serialisable.\nJSON.stringify(color1); // '[{\"name\":\"RED\",\"value\":0},{\"name\":\"YELLOW\",\"value\":1}]'\n\n// Enumerations support iteration, in definition order.\n// The forEach() method executes a provided function once per each\n// name/value pair in the Enum object, in insertion order.\n// Iterating over the members of an enum does not provide the aliases.\ncolor1.forEach((enumMember) =\u003e {\n  console.log(enumMember.name, enumMember.value);\n});\n\n// Where supported, for..of can be used.\n// Iterating over the members of an enum does not provide the aliases.\nfor (const {name, value} of color1) {\n  console.log(name, value);\n}\n\n// Otherwise, standard iterator pattern.\n// Iterating over the members of an enum does not provide the aliases.\nconst iter = color1[Symbol.iterator]();\nlet next = iter.next();\nwhile (next.done === false) {\n  const enumMember = next.value;\n  console.log(enumMember.name, enumMember.value);\n  next = iter.next();\n}\n\n// To iterate all items, including aliases.\nconst allenumMembers = color1.toJSON();\nallenumMembers.forEach((enumMember) =\u003e {\n  console.log(enumMember.name, enumMember.value);\n});\n\n// Lookups can be performed on the value and not just the name.\nconsole.log(color1(0) === color1.RED); // true\nconsole.log(color1(1) === color1.YELLOW); // true\n\n// Values can be anything, but names must be a string.\nconst anotherEnum = Enum.create('anotherEnum', [\n  {name: 'OBJECT', value: {}},\n  {name: 'ARRAY', value: []},\n  {\n    name: 'FUNCTION',\n    value() {\n      return undefined;\n    },\n  },\n]);\n\n// Enums can be cloned\nconst cloneEnum = Enum.create('cloneEnum', anotherEnum);\nconsole.log(cloneEnum === anotherEnum); // false\nconsole.log(cloneEnum.OBJECT === anotherEnum.OBJECT); // false\nconsole.log(cloneEnum.OBJECT.name === anotherEnum.OBJECT.name); // true\nconsole.log(cloneEnum.OBJECT.value === anotherEnum.OBJECT.value); // true\n\n// Options\n// unique: {boolean} - whether aliases are allowed.\n// auto: {Function} - if you wish to define your own auto value allocation.\n// classMethods: {Object\u003cFunction\u003e} - to defined methods on the enum.\n// instanceMethods: {Object\u003cFunction\u003e} - to defined methods on the enum members.\n\n// ------------------------------------------------------\n\nconst opts1 = {\n  auto() {\n    return {\n      next(name /* , value */) {\n        return name;\n      },\n    };\n  },\n};\n\nconst subject1 = Enum.create('subject1', ['RED'], opts1);\nconsole.log(subject1.RED); // { name: 'RED', value: 'RED'}\n\n// ------------------------------------------------------\n\nconst opts2 = {\n  classMethods: {\n    favourite() {\n      return this.RED;\n    },\n  },\n};\n\nconst subject2 = Enum.create('subject2', ['RED'], opts2);\nconsole.log(subject2.favourite() === subject2.RED); // true\n\n// ------------------------------------------------------\n\nconst opts3 = {\n  instanceMethods: {\n    description() {\n      return `Description: ${this.toString()}`;\n    },\n  },\n};\n\nconst subject3 = Enum.create('subject3', ['RED'], opts3);\nconsole.log(subject3.RED.description() === 'Description: subject3.RED'); // true\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxotic750%2Fenumify-x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fxotic750%2Fenumify-x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fxotic750%2Fenumify-x/lists"}