{"id":26904918,"url":"https://github.com/eshwinrio/genshin-toolkit-parser","last_synced_at":"2025-04-01T10:55:15.779Z","repository":{"id":241127983,"uuid":"803055878","full_name":"eshwinrio/genshin-toolkit-parser","owner":"eshwinrio","description":"A small library to parse and validate Genshin Impact game data.","archived":false,"fork":false,"pushed_at":"2024-05-29T01:04:36.000Z","size":45,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-05-29T13:26:31.707Z","etag":null,"topics":["genshin","genshin-impact","hoyolab","hoyolab-api","http-archive"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","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/eshwinrio.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,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2024-05-20T01:19:10.000Z","updated_at":"2024-06-04T02:57:59.828Z","dependencies_parsed_at":"2024-05-22T15:43:12.381Z","dependency_job_id":"df6e2944-861a-448d-b3b5-b452f8cd38cc","html_url":"https://github.com/eshwinrio/genshin-toolkit-parser","commit_stats":null,"previous_names":["eshwinrio/genshin-toolkit-parser","eshwinrio/genshin-impact-gamedata-schema"],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eshwinrio%2Fgenshin-toolkit-parser","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eshwinrio%2Fgenshin-toolkit-parser/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eshwinrio%2Fgenshin-toolkit-parser/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eshwinrio%2Fgenshin-toolkit-parser/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eshwinrio","download_url":"https://codeload.github.com/eshwinrio/genshin-toolkit-parser/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246628309,"owners_count":20808106,"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":["genshin","genshin-impact","hoyolab","hoyolab-api","http-archive"],"created_at":"2025-04-01T10:55:15.396Z","updated_at":"2025-04-01T10:55:15.774Z","avatar_url":"https://github.com/eshwinrio.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Parser module of Genshin Toolkit\n\nThis module serves as a core component of all tools built in the Genshin Toolkit chain. This module depends on `zod` for data validation and parsing.\n\n## Usage\n\nThe current version has support for extracting game data from a HAR file captured from your [Battle Chronicle](https://act.hoyolab.com/app/community-game-records-sea/index.html). _You need to be signed-in to obtain your game data_\n\n\u003e If you aren't sure on how to capture the HAR, follow instructions from this [Guide by Microsoft](https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-troubleshoot-network-trace) for the browser you intend to work on:\n\u003e\n\u003e - [Google Chrome](https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-troubleshoot-network-trace#google-chrome)\n\u003e - [Mozilla Firefox](https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-troubleshoot-network-trace#mozilla-firefox)\n\u003e - [Safari](https://learn.microsoft.com/en-us/azure/azure-web-pubsub/howto-troubleshoot-network-trace#safari)\n\n### Importing modules\n\nUse core imports for node and `web` for web environments\n\n```ts\n// For node environment\nimport { DataProvider } from \"@genshin-toolkit/parser\";\n\n// For web environments\nimport { DataProvider } from \"@genshin-toolkit/parser/web\";\n```\n\n### Create a new `DataProvider` instance.\n\nThere are data provider classes for specific use cases, for *Node* and for *Web*:\n\n#### Cross-environment\n- `BufferDataProvider` If you have the HAR `Buffer` at hand, you can use this `DataProvider` instead.\n- `StringDataProvider` Reads data from raw `String`.\n\n#### Node only\n- `FileDataProvider` This is the provider you'll be using if you want to skip the hassle of reading the file yourself and passing in the buffer to the `DataProvider`.\n\n#### Web only\n- `WebFileDataProvider` Alternate `DataProvider` for `FileDataProvider` to be used in browsers.\n\n  ```ts\n  import {\n    BufferDataProvider,\n    FileDataProvider,\n    loadFromHar,\n  } from \"@genshin-toolkit/parser\";\n\n  const fileDataProvider = new FileDataProvider(\"..path-to.har\");\n  // or\n  const bufferDataProvider = new BufferDataProvider(buffer);\n  // or\n  const stringDataProvider = new StringDataProvider(\"{...string_data...}\");\n  ```\n\n2. Call `loadFromHar` to extract and parse game data from a HAR file.\n\n    ```ts\n    const gameData = await loadFromHar(provider);\n    \n    // Tabular display (example)\n    console.table(gameData.avatars.map(avatar =\u003e ({\n        character: avatar.name,\n        level: avatar.level,\n        weapon: `${avatar.weapon?.type_name}/${avatar.weapon?.name} - lv${avatar.weapon?.level}`,\n        friendship: `lv${avatar.fetter}`\n    })));\n    ```\n\n## Examples\n\nBelow are the examples of loading data from HAR for two different use-cases (Use `async` function wrapper if using `await`):\n\n### Parsing data from a local file\n\n```ts\nimport { FileDataProvider, loadFromHar } from \"@genshin-toolkit/parser\";\n\nconst provider = new FileDataProvider(\"/home/path/to.har\");\nconst gameDataFactory = await loadFromHar(provider);\n```\n\n### Parsing game data from a game data file\n\nIf you want to parse the game data (data parsed from HAR with `loadFromHar` and saved on disk or a `GameData` schema compatible json file)\n\n```ts\nimport { FileDataProvider, loadFromFile } from \"@genshin-toolkit/parser\";\n\nconst provider = new FileDataProvider(\"/home/path/gamedata.json\");\nconst gameDataFactory = await loadFromFile(provider);\n```\n\n### Parsing on the web\n\nUse `WebFileDataProvider` to directly work with the `File` provided by the provided by the browser on picking a file. Or use cross-env `DataProviders` like `BufferDataProvider` if you already have the file `Buffer` in memory.\n\n\u003e If using TypeScript, your module resolution should be the newer `Node16` or `NodeNext` when trying to import `parser/web`.\n\n```ts\nimport { WebFileDataProvider } from '@genshin-toolkit/parser/web';\n\ndocument.getElementById('fileInput').addEventListener('change', async (event) =\u003e {\n    const input = event.target as HTMLInputElement;\n    if (input.files \u0026\u0026 input.files.length \u003e 0) {\n        const file = input.files[0];\n        const provider = new WebFileDataProvider(file);\n\n        try {\n            const data = await provider.load();\n            // Parse with loadFromHar or loadFromFile here.\n            console.log('File data loaded:', data);\n        } catch (error) {\n            console.error('Error loading file:', error);\n        }\n    }\n});\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feshwinrio%2Fgenshin-toolkit-parser","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feshwinrio%2Fgenshin-toolkit-parser","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feshwinrio%2Fgenshin-toolkit-parser/lists"}