{"id":21148784,"url":"https://github.com/2ue/enums-pandas","last_synced_at":"2025-09-17T19:10:54.651Z","repository":{"id":230166006,"uuid":"778645368","full_name":"2ue/enums-pandas","owner":"2ue","description":null,"archived":false,"fork":false,"pushed_at":"2024-03-28T07:21:55.000Z","size":25,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-01-21T07:43:49.342Z","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":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/2ue.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":"2024-03-28T05:42:50.000Z","updated_at":"2024-03-28T05:50:12.000Z","dependencies_parsed_at":null,"dependency_job_id":"5ec60177-7cca-42a5-8147-08be1a7f8541","html_url":"https://github.com/2ue/enums-pandas","commit_stats":null,"previous_names":["2ue/enums-pandas"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fenums-pandas","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fenums-pandas/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fenums-pandas/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/2ue%2Fenums-pandas/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/2ue","download_url":"https://codeload.github.com/2ue/enums-pandas/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243589333,"owners_count":20315471,"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-20T09:28:59.133Z","updated_at":"2025-09-17T19:10:49.599Z","avatar_url":"https://github.com/2ue.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# EnumsPandas\n\n\u003e 通过使用 EnumsPandas，可以方便地处理枚举数据，并进行各种操作，如获取、筛选、重建等。\n\n## 安装\n\n```bash\nnpm install enums-pandas\n```\n\n## 使用\n\n```js\nimport { EnumsPandas as EP } from 'enums-pandas';\n\nconst fruit = [\n  { key: 'apple', value: 'red', label: '苹果' },\n  { key: 'banana', value: 'yellow', label: '香蕉' },\n];\nconst fruitEp = new EP(fruit);\n```\n\n另外还可以传入参数，指定对应的key和value键值，示例：\n\n```js\n\nconst lingshi = [\n  { key: 'peanut', no: 100, label: '花生' },\n  { key: 'melonSeeds', no: 101, label: '瓜子' },\n];\nconst lingshiEp = new EP(fruit, {\n  keys: {\n    // key: 'key', 默认为key可以不传\n    value: 'no',\n  }\n});\n```\n\n## API\n\n### source\n\n\u003e 获取源数据。\n```js\nconsole.log(fruitEp.source);\n// 输出:\n// [\n//   { key: 'apple', value: 'red', label: '苹果' },\n//   { key: 'banana', value: 'yellow', label: '香蕉' }\n// ]\n```\n\n### size\n\n\u003e 获取枚举项数量。\n\n```js\nconsole.log(fruitEp.size);\n// 输出: 2\n```\n\n### bidict\n\n\u003e 获取以{key}和{value}生成的双向映射字典（bidirectional mapping dict）\n\nps: 注意使用此功能，需要保证每一项{key}和{value}的值是唯一的。\n\n\n```js\nconsole.log(fruitEp.bdict);\n// 输出:\n// {\n//   apple: 'red',\n//   red: 'apple',\n//   banana: 'yellow',\n//   yellow: 'banana'\n// }\n```\n\n### rebuild(cb: RebuildCallback, key?: string)\n\n\u003e 根据回调函数重建枚举项数组，并可选择(如果key有值，如果key相同则覆盖上一次的结果)，将重建结果存入重建缓存对象中。\n\n```js\nconst newFruit = fruitEp.rebuild((item) =\u003e {\n  return { ...item, id: item.key };\n}, 'selectOptions');\nconsole.log(newFruit);\n// 输出:\n// [\n//   { id: 'apple', value: 'red', label: '苹果' },\n//   { id: 'banana', value: 'yellow', label: '香蕉' }\n// ]\nconsole.log(fruitEp.rebuildCache.selectOptions);\n// 输出:\n// [\n//   { id: 'apple', value: 'red', label: '苹果' },\n//   { id: 'banana', value: 'yellow', label: '香蕉' }\n// ]\n```\n\n## getRow(columnKey: string, value: number | string)\n\n\u003e 根据指定的列键和值获取对应的行。\n\n```js\nconsole.log(fruitEp.getRow('key', 'apple'));\n// 输出:\n// { key: 'apple', value: 'red', label: '苹果' }\n```\n\n### getRowsBy(columnKey: string, callback: FilterRowCallback)\n\n\u003e 根据指定的列键和回调函数筛选出符合条件的行数组\n\n```js\nconst filteredRows = fruitEp.getRowsBy('value', (value) =\u003e value.includes('red'));\nconsole.log(filteredRows);\n// 输出:\n// [\n//   { key: 'apple', value: 'red', label: '苹果' }\n// ]\n```\n\n### getColumns(columnKey: string)\n\n\u003e获取指定列键的所有值组成的数组。\n\n```js\nconsole.log(fruitEp.getColumns('key'));\n// 输出:\n// ['apple', 'banana']\n```\n\n### getColumnsBy(columnKey: string, callback: FilterRowCallback)\n\n\u003e根据指定的列键和回调函数筛选出符合条件的值组成的数组\n\n```js\nconst filteredColumns = fruitEp.getColumnsBy('value', (value) =\u003e value.includes('red'));\nconsole.log(filteredColumns);\n// 输出:\n// ['red']\n```\n\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fenums-pandas","html_url":"https://awesome.ecosyste.ms/projects/github.com%2F2ue%2Fenums-pandas","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2F2ue%2Fenums-pandas/lists"}