{"id":15283826,"url":"https://github.com/ewei068/anki-reader","last_synced_at":"2025-10-19T10:11:34.933Z","repository":{"id":203655145,"uuid":"710113326","full_name":"ewei068/anki-reader","owner":"ewei068","description":"An anki file reader module for Browser and Node","archived":false,"fork":false,"pushed_at":"2023-11-05T21:49:57.000Z","size":592,"stargazers_count":10,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-10-19T05:12:46.030Z","etag":null,"topics":["anki","anki-card","anki-deck","anki-flashcards","apkg","bun","npm-module","typescript"],"latest_commit_sha":null,"homepage":"https://www.npmjs.com/package/anki-reader","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/ewei068.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,"zenodo":null}},"created_at":"2023-10-26T03:36:28.000Z","updated_at":"2025-07-11T00:00:42.000Z","dependencies_parsed_at":null,"dependency_job_id":"4884383c-6f0b-4b36-8a62-b77f8a2f95ff","html_url":"https://github.com/ewei068/anki-reader","commit_stats":null,"previous_names":["ewei068/anki-reader"],"tags_count":8,"template":false,"template_full_name":null,"purl":"pkg:github/ewei068/anki-reader","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewei068%2Fanki-reader","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewei068%2Fanki-reader/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewei068%2Fanki-reader/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewei068%2Fanki-reader/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ewei068","download_url":"https://codeload.github.com/ewei068/anki-reader/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ewei068%2Fanki-reader/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":279778378,"owners_count":26225475,"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","status":"online","status_checked_at":"2025-10-19T02:00:07.647Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["anki","anki-card","anki-deck","anki-flashcards","apkg","bun","npm-module","typescript"],"created_at":"2024-09-30T14:47:50.470Z","updated_at":"2025-10-19T10:11:34.922Z","avatar_url":"https://github.com/ewei068.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# anki-reader\n\n[![npm version](https://img.shields.io/npm/v/anki-reader.svg?style=flat-square)](https://www.npmjs.org/package/anki-reader)\n[![npm downloads](https://img.shields.io/npm/dm/anki-reader.svg?style=flat-square)](https://npm-stat.com/charts.html?package=anki-reader)\n\nA `.apkg` and `.anki2` file reader module. Compatable node, bun, and browser runtimes.\n\n## Usage\n\n### Installation\n\nUsing npm:\n```\n$ npm install anki-reader\n```\n\nUsing bun:\n```\n$ bun install anki-reader\n```\n\n### Usage\n\nAfter installation, pass in `.apkg` or `.anki2` files to their reader functions. This returns a collection object, which can be used to retrieve deck and card information. Additionally, if a `.apkg` file is returned, media files are also extracted.\n```js\nimport { readAnkiPackage } from 'anki-reader';\n\nconst ankiFile = ...\nreadAnkiPackage(ankiFile)\n  .then((extractedPackage) =\u003e {\n    const { collection, media } = extractedPackage;\n\n    const decks = collection.getDecks();\n    for (const [deckId, deck] of Object.entries(decks)) {\n      console.log(deckId, deck.getRawDeck());\n      for (const [cardId, card] of Object.entries(deck.getCards())) {\n        console.log(cardId, card.getRawCard());\n      }\n    }\n\n    for (const [name, blob] of Object.entries(media)) {\n      console.log(name, blob);\n    }\n  })\n```\n\nAlternatively, you can read a collection file directly from a URL with `readFromUrl` like so:\n```js\nimport { readFromUrl } from 'anki-reader';\n\nreadFromUrl('http://127.0.0.1:8081/collection.anki2')\n  .then((collection) =\u003e {\n    const decks = collection.getDecks();\n    for (const [deckId, deck] of Object.entries(decks)) {\n      console.log(deckId, deck.getRawDeck());\n      for (const [cardId, card] of Object.entries(deck.getCards())) {\n        console.log(cardId, card.getRawCard());\n      }\n    }\n  })\n```\n\nFor more in-depth examples, see the [story directory](https://github.com/ewei068/anki-reader/tree/main/story).\n\n### Browser\n\nIf you intend to use anki-reader in a browser runtime, you must configure additional settings so `sql.js` can locate the `wasm` file. See the official [sql.js documentation](https://github.com/sql-js/sql.js#examples) and [this React example](https://github.com/sql-js/react-sqljs-demo/tree/master).\n\n**React**\n```js\n// App.js\nimport sqlWasm from \"!!file-loader?name=sql-wasm-[contenthash].wasm!sql.js/dist/sql-wasm.wasm\";\n\nexport default function App() {\n  const ankiFile = ...\n  readAnkiCollection(ankiFile, {\n    sqlConfig: { \n      locateFile: () =\u003e sqlWasm \n    },\n  }\n\n  ...\n\n}\n```\n\n```js\n// webpack.config.js\nmodule.exports = {\n    webpack: {\n        configure: {\n            // See https://github.com/webpack/webpack/issues/6725\n            module:{\n                rules: [{\n                    test: /\\.wasm$/,\n                    type: 'javascript/auto',\n                }]\n                ...\n            }\n        }\n    }\n};\n```\n\n### API\n\nAnki collections are stored as sqlite databases, which is what anki-reader queries. The anki-reader follows similarly to the data structure of the `.anki2` database structure, which can be [referenced here](https://github.com/ankidroid/Anki-Android/wiki/Database-Structure).\n\nThis package also provides methods to get the raw database objects or models. For example, `AnkiCollection.getRawCollection()` may be used to get the raw collection database, and can then use the `sql.js` API to query.\n\n## Development (WIP)\n\nTo install dependencies:\n\n```bash\nbun install\n```\n\nTo run:\n\nRefer to `story/README.md`\n\nTo build typescript:\n\n```bash\nnpm run build\n```\n\nThis project was created using `bun init` in bun v1.0.7. [Bun](https://bun.sh) is a fast all-in-one JavaScript runtime.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fewei068%2Fanki-reader","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fewei068%2Fanki-reader","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fewei068%2Fanki-reader/lists"}