{"id":24316254,"url":"https://github.com/banlife/class-enum","last_synced_at":"2025-12-30T01:14:51.443Z","repository":{"id":45284969,"uuid":"491910438","full_name":"banlife/class-enum","owner":"banlife","description":"Extendable class-enum on typescript","archived":false,"fork":false,"pushed_at":"2024-01-05T04:19:14.000Z","size":486,"stargazers_count":57,"open_issues_count":0,"forks_count":4,"subscribers_count":1,"default_branch":"develop","last_synced_at":"2024-08-11T10:52:47.352Z","etag":null,"topics":["enum","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/banlife.png","metadata":{"files":{"readme":"README-KR.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}},"created_at":"2022-05-13T13:35:00.000Z","updated_at":"2024-06-01T04:05:53.000Z","dependencies_parsed_at":"2024-01-05T05:27:40.740Z","dependency_job_id":"5c9ae1d4-dde0-4d31-9773-d61836cd0ce8","html_url":"https://github.com/banlife/class-enum","commit_stats":{"total_commits":28,"total_committers":1,"mean_commits":28.0,"dds":0.0,"last_synced_commit":"eec57cc4feeb84ad7a8ed5adfd146260bd26b262"},"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banlife%2Fclass-enum","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banlife%2Fclass-enum/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banlife%2Fclass-enum/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/banlife%2Fclass-enum/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/banlife","download_url":"https://codeload.github.com/banlife/class-enum/tar.gz/refs/heads/develop","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":234360836,"owners_count":18819962,"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","typescript"],"created_at":"2025-01-17T12:19:57.858Z","updated_at":"2025-09-26T23:31:24.152Z","avatar_url":"https://github.com/banlife.png","language":"TypeScript","readme":"![npm:version](https://flat.badgen.net/npm/v/class-enum)\n\n# class-enum\n\nclass-enum은 typescript enum을 대체하기 위하여 만들어졌습니다.  \ntypescript의 enum은 숫자, 문자열 정도의 형식만 지원하기 때문에 추가적인 기능 확장에 아쉬움이 있습니다. 따라서 생성자 지원이 가능한 자바 형태의 enum을 만들기로 했습니다.\n\n## 설치\n\n### NPM\n\n```bash\n$ npm i class-enum\n```\n\n## 사용방법\n\n### 기본 정의\n\n`ClassEnum`클래스 상속을 통하여 상수를 선언합니다. 첫 번째 인자로 unique value 문자열을 넣습니다.\n\n```typescript\nimport { ClassEnum, Enum } from 'class-enum'\n\nclass Animal extends ClassEnum\u003cAnimal\u003e {\n    public static readonly DOG = new Animal(\"DOG\")\n    public static readonly CAT = new Animal(\"CAT\")\n    public static readonly MOUSE = \"foo\" // ignored in ClassEnum\n}\n```\n\n### 확장\n\n```typescript\nclass Animal extends ClassEnum\u003cAnimal\u003e {\n    public static readonly DOG = new Animal('DOG', 'My Dog', 3)\n    public static readonly CAT = new Animal('CAT', 'Cute Cat', 6)\n\n    private readonly title!: string\n    private readonly age!: number\n\n    public constructor(value: string, title: string, age: number) {\n        super(value)\n        this.title = title\n        this.age = age\n    }\n\n    public printTitle() {\n        console.log(this.title)\n    }\n\n    public getAge() {\n        return this.age\n    }\n}\n\nAnimal.DOG.printTitle() // My Dog\nconsole.log(`cat age: ${Animal.CAT.getAge()}`) // cat age: 6\n\n```\n\n## 기능\n\n### values()\n\nEnum 값을 모두 가져옵니다.\n\n```typescript\nconsole.log(Animal.values()) // [ Animal { value: 'DOG' }, Animal { value: 'CAT' } ]\n```\n\n```typescript\nAnimal.values().map((animal: Animal) =\u003e {\n    console.log(animal.name())\n})\n\n// DOG -\u003e string\n// CAT -\u003e string\n```\n\n### valueOf(s: string)\n\nvalue 문자열로부터 Enum을 찾아옵니다.\n\n```typescript\nconsole.log(Animal.valueOf('DOG'))\nconsole.log(Animal.valueOf('CAT'))\nconsole.log(Animal.valueOf('PARROT')) // occurs EnumNotFound exception\n```\n\n### valueOf(s: string, defaultEnum: Enum = null)\n\nvalue 문자열로부터 Enum을 찾아옵니다.\n\n```typescript\nconsole.log(Animal.valueOf('DOG'))\nconsole.log(Animal.valueOf('CAT'))\nconsole.log(Animal.valueOf('PARROT')) // occurs EnumNotFound exception\n```\n\n문자열로부터 Enum을 찾을 수 없다면 defaultEnum을 반환합니다.\n\n```typescript\nconsole.log(Animal.valueOf(\"MONKEY\", Animal.ETC))\n```\n\n### name()\n\nvalue 문자열을 가져옵니다.\n\n```typescript\nconsole.log(Animal.DOG.name()) // \"DOG\"\n```\n\n### equals(e: Enum)\n\nvalue값을 기준으로 비교합니다.\n\n```typescript\nconsole.log(Animal.DOG.equals(Animal.DOG)) // true\nconsole.log(Animal.DOG.equals(Animal.CAT)) // false\nconsole.log(Animal.DOG.equals(Other.DOG)) // false\n```\n\n## Vue.js\n\n선택된 동물(Enum)에 따라서 이름, 색상을 다르게 표시하는 예제입니다.\n\n```vue\n\u003ctemplate\u003e\n  \u003cselect v-model=\"selectedAnimal\"\u003e\n    \u003coption v-for=\"animal in Animal.values()\" :key=\"animal.name()\" :value=\"animal\"\u003e{{ animal.title }}\u003c/option\u003e\n  \u003c/select\u003e\n\n  \u003cp :style=\"{color: selectedAnimal.color}\"\u003eselected:{{ selectedAnimal.name() }}\u003c/p\u003e\n\u003c/template\u003e\n\n\u003cscript setup lang=\"ts\"\u003e\nimport { ClassEnum } from \"class-enum\";\nimport { ref } from \"vue\";\n\nclass Animal extends ClassEnum\u003cAnimal\u003e {\n  public static readonly DOG = new Animal(\"DOG\", \"cute dog\", \"red\");\n  public static readonly CAT = new Animal(\"CAT\", \"beautiful cat\", \"green\");\n  public static readonly MONKEY = new Animal(\"MONKEY\", \"big money\", \"blue\");\n\n  public readonly title!: string;\n  public readonly color!: string;\n\n  public constructor(value: string, title: string, color: string) {\n    super(value);\n    this.title = title;\n    this.color = color;\n  }\n}\n\nconst selectedAnimal = ref(Animal.DOG);\n\u003c/script\u003e\n\n```","funding_links":[],"categories":["TypeScript"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanlife%2Fclass-enum","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbanlife%2Fclass-enum","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbanlife%2Fclass-enum/lists"}