{"_id":"@2anki/mkanki","name":"@2anki/mkanki","dist-tags":{"latest":"1.1.1"},"versions":{"1.1.1":{"name":"@2anki/mkanki","version":"1.1.1","description":"Generate Anki decks. Supports cloze deletion and media.","main":"index.js","scripts":{},"author":{"name":"Alexander Alemayhu","email":"alexander@alemayhu.com"},"license":"AGPL-3.0-only","license-comment":"I'm happy to grant licenses under other terms on a case-by-case basis, just email me!","repository":{"type":"git","url":"git+https://github.com/nornagon/mkanki.git"},"homepage":"https://github.com/2anki/mkanki","dependencies":{"archiver":"^5.3.1","better-sqlite3":"^8.4.0","tmp":"0.2.1"},"gitHead":"9995232f1fa73face438db2b70ff9f085b583c07","bugs":{"url":"https://github.com/nornagon/mkanki/issues"},"_id":"@2anki/mkanki@1.1.1","_nodeVersion":"18.14.1","_npmVersion":"9.3.1","dist":{"integrity":"sha512-fjPYnfOOj+QtNVUfdzArVlcQZR5ikAP3/ZXBrfbPAhI2+kx2dPtc7DbJ5rYDpkAYHirEtr2getl1M4T4KCDYNw==","shasum":"274b578effb69e5ef85bda48a2231c55c5eaea4b","tarball":"https://registry.npmjs.org/@2anki/mkanki/-/mkanki-1.1.1.tgz","fileCount":6,"unpackedSize":57566,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEUCIQDWCHS1iFXtWc5XwmGTRrtO4adU9VqYXySj8H4mFMZCpQIgLpYm7lgtgfCmQQum35ruHDuCgNQtv3dB4q7JZ/ezJbo="}]},"_npmUser":{"name":"aalemayhu","email":"alexander@alemayhu.com"},"directories":{},"maintainers":[{"name":"aalemayhu","email":"alexander@alemayhu.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages","tmp":"tmp/mkanki_1.1.1_1689345022232_0.8424345631467238"},"_hasShrinkwrap":false}},"time":{"created":"2023-07-14T14:30:22.101Z","1.1.1":"2023-07-14T14:30:22.447Z","modified":"2023-07-14T14:30:22.758Z"},"maintainers":[{"name":"aalemayhu","email":"alexander@alemayhu.com"}],"description":"Generate Anki decks. Supports cloze deletion and media.","homepage":"https://github.com/2anki/mkanki","repository":{"type":"git","url":"git+https://github.com/nornagon/mkanki.git"},"author":{"name":"Alexander Alemayhu","email":"alexander@alemayhu.com"},"bugs":{"url":"https://github.com/nornagon/mkanki/issues"},"license":"AGPL-3.0-only","readme":"# mkanki\n\nAn API for generating [Anki](https://apps.ankiweb.net/) decks.\n\nAnki is a tool for [spaced-repetition study](https://ncase.me/remember/).\n\nNote: This is a fork of [nornagon/mkanki](https://github.com/nornagon/mkanki).\n\nFor examples of how to use this library, see the [examples](./examples) folder.\n\n### Install\n\n```sh\nnpm install --save mkanki\n```\n\n## Documentation\n\nFirst, some information about how Anki works.\n\nIn Anki, things to be remembered are called _notes_. Each note can have several\nfields—most commonly, a \"Front\" and a \"Back\", but the fields can be arbitrary.\nEach note can potentially correspond to many individual _cards_, each of which\nshould help you remember one facet of the note.\n\nThe thing that describes how those fields are turned into flashcards is called\na _model_. Every note is described by exactly one model. The model defines\nwhich fields are allowed, and additionally defines one or more _templates_,\nwhich are written as HTML with [mustache](https://mustache.github.io/)-like\nplaceholders.\n\nFinally, each card belongs to a _deck_. Decks collect cards into logical groups\nthat you might want to study separately from each other.\n\n_Models_, _notes_, _cards_ and _decks_ are the fundamental concepts of Anki. In\nmkanki, cards are implicitly defined by notes and models, and you will only\ndeal with models, notes, and decks.\n\n### `Model`\n\nAnki supports two types of models: _standard_ and _cloze_. Standard models\ngenerate one card per template, while cloze models generate one card per cloze\ndeletion. See the [Anki cloze documentation][anki-cloze-docs] for more on cloze\ndeletion.\n\n#### `new anki.Model(props)`\n\nCreate a new standard model with the given properties. `props` is an object\nwith the following fields.\n\n- `id` string - a stable, unique identifier for this model. Generate this once\n  with `+new Date` and then hard-code it into your code. Keeping this stable\n  means that if the package is updated and re-imported into Anki, the app will\n  be able to tell which cards are new and which cards should be merged into\n  already-existing cards, preserving study history.\n- `name` string - the name of the model. Shows up in the \"Add\" UI in Anki.\n- `flds` Array&lt;{name: string}&gt; - the fields in the model.\n- `tmpls` Array&lt;{name?: string, qfmt: string, afmt: string}&gt; - a list of\n  card templates to be generated from each note. `qfmt` is the HTML template\n  for the question, and `afmt` is the HTML template for the answer. `name` is\n  displayed in the configuration screen in Anki and nowhere else, and will\n  default to \"Card N\". See the [Anki template\n  documentation][anki-template-docs] for more on template formatting.\n- `req` Array&lt;[number, \"all\" | \"any\", Array&lt;number&gt;]&gt; - this\n  describes which fields must be non-empty in order for a card to be generated.\n  Each entry in this list is a tuple of the template index, \"all\" or \"any\", and\n  a list of field indices. In order for a card to be generated for a given note\n  and template, one or all of the fields specified in the field list must be\n  non-empty. If the requirement isn't met for a given (template, note) pair, no\n  card will be generated.\n\n#### `new anki.ClozeModel(props)`\n\nCreate a new cloze model with the given properties. `props` is an object with\nthe following fields.\n\n- `id` string - a stable, unique identifier for this model. Generate this once\n  with `+new Date` and then hard-code it into your code. Keeping this stable\n  means that if the package is updated and re-imported into Anki, the app will\n  be able to tell which cards are new and which cards should be merged into\n  already-existing cards, preserving study history.\n- `name` string - the name of the model. Shows up in the \"Add\" UI in Anki.\n- `flds` Array&lt;{name: string}&gt; - the fields in the model.\n- `tmpl` {name?: string, qfmt: string, afmt: string} - the cloze template to\n  be generated from each note. `qfmt` is the HTML template for the question,\n  and `afmt` is the HTML template for the answer. `name` is displayed in the\n  configuration screen in Anki and nowhere else, and will default to \"Cloze\".\n  See the [Anki template documentation][anki-cloze-template-docs] for more on\n  cloze template formatting. Cloze models can only have one template.\n\n#### `model.note(fieldValues, [guid])`\n\nCreate a note using this model.\n\n- `fieldValues` Array&lt;string&gt; | {[fieldName: string]: string} - If\n  `fieldValues` is an array, the order of fields will be matched with the order\n  of the `flds` in the model. If `fieldValues` is an object, the keys must be\n  the names of fields in the model.\n- `guid` string _(optional)_ - a stable, unique identifier for this note. When\n  re-importing an updated version of this note, Anki will replace notes with\n  matching identifiers. Defaults to a hash of the field values.\n\n### `Deck`\n\nIn mkanki, decks are collections of notes (not cards, as in Anki proper).\n\n#### `new anki.Deck(id, name)`\n\nCreate a new deck.\n\n- `id` string - a stable, unique identifier for this deck. Generate this once\n  with `+new Date` and then hard-code it into your code. Keeping this stable\n  means that if the package is updated and re-imported into Anki, the app will\n  be able to tell which cards are new and which cards should be merged into\n  already-existing cards, preserving study history.\n- `name` string - the name of the deck. When importing, Anki will create new\n  decks with the specified names for each deck in the package.\n\n#### `deck.addNote(note)`\n\nAdd a note to this deck. Technically, it is possible for a single note in Anki\nto generate cards belonging to multiple decks, but mkanki does not support\nthat.\n\n- `note` Note - create notes using [`model.note()`](#modelnotefieldvalues).\n\n### `Package`\n\nA package collects together decks, notes, and any media objects (images, audio,\nvideo, etc.) to be exported into a `.apkg` file.\n\n#### `new anki.Package()`\n\nCreate a new empty package.\n\n#### `package.addDeck(deck)`\n\nAdd a deck to this package.\n\n- `deck` [Deck](#deck) - the deck to add.\n\n#### `package.addMedia(data, name)`\n\nAdd a media file to this package.\n\n- `data` string | Buffer - the contents of the media file.\n- `name` string - the name of the file in the package.\n\n#### `package.addMediaFile(filename, [name])`\n\nAdd a media file from the filesystem to this package.\n\n- `filename` string - path to the file.\n- `name` string _(optional)_ - the name of the file in the package. Defaults to\n  `filename`.\n\n#### `package.writeToFile(filename)`\n\nSerializes the package to a file.\n\n- `filename` string - path to the exported package. Conventionally ends in\n  `\".apkg\"`.\n\n[anki-template-docs]: https://apps.ankiweb.net/docs/manual.html#cards-and-templates\n[anki-cloze-docs]: https://apps.ankiweb.net/docs/manual.html#cloze-deletion\n[anki-cloze-template-docs]: https://apps.ankiweb.net/docs/manual.html#cloze-templates\n\n## License\n\nmkanki is licensed to everyone under the terms of the [GNU Affero General\nPublic License v3](https://opensource.org/licenses/AGPL-3.0). If you'd like to\nuse mkanki under different terms, I'm happy to accommodate you—just [email\nme](mailto:nornagon@nornagon.net)!\n","readmeFilename":"README.md"}