npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

anki-apkg-builder

v2.0.0

Published

Anki package file (`.apkg`) generator

Downloads

2

Readme

anki-apkg-builder

Generate Anki package files (.apkg) programmatically using Node.js and import them into Anki.

Usage

Install package:

npm install anki-apkg-builder

Generating Anki apkg file TypeScript example:

import { AnkiApkgBuilderFactory } from 'anki-apkg-builder';

const builderFactory = new AnkiApkgBuilderFactory()
const builder = await builderFactory.create();
const germanVocabularyDeck = await builder.addDeck({
  name: 'German Vocabulary',
});
const englishVocabularyDeck = await builder.addDeck({
  name: 'English Vocabulary',
});
const germanVocabularyNoteType = await builder.addNoteType({
  id: 1719390000001,
  did: germanVocabularyDeck.id,
  name: 'German Vocabulary Note type',
  css: '.front{text-align:center}',
  tmpls: [
    {
      name: 'Forward Card',
      ord: 0,
      qfmt: '<span class="front">{{Front}}</span>',
      afmt: '{{FrontSide}}\n\n<hr id="answer">\n\n{{Back}}',
      bqfmt: '',
      bafmt: '',
      did: null,
    },
    {
      name: 'Reverse Card',
      ord: 1,
      qfmt: '{{Back}}',
      afmt: '{{FrontSide}}\n\n<hr id="answer">\n\n{{Front}}',
      bqfmt: '',
      bafmt: '',
      did: null,
    },
  ],
  flds: [
    {
      name: 'Front',
      media: [],
      sticky: false,
      rtl: false,
      ord: 0,
      font: 'Arial',
      size: 20,
    },
    {
      name: 'Back',
      media: [],
      sticky: false,
      rtl: false,
      ord: 1,
      font: 'Arial',
      size: 20,
    },
  ],
});
const englishVocabularyNoteType = await builder.addNoteType({
  id: 1719390000002,
  did: englishVocabularyDeck.id,
  name: 'English Vocabulary Note type',
  css: '.front{text-align:center}',
  tmpls: [
    {
      name: 'Question Card',
      ord: 0,
      qfmt: '<span class="front">{{Front}}</span></br><span class="transcription">[{{Transcription}}]</span>',
      afmt: '{{FrontSide}}\n\n<hr id="answer">\n\n{{Back}}',
      bqfmt: '',
      bafmt: '',
      did: null,
    },
    {
      name: 'Answer Card',
      ord: 1,
      qfmt: '{{Back}}',
      afmt: '{{FrontSide}}\n\n<hr id="answer">\n\n{{Front}}',
      bqfmt: '',
      bafmt: '',
      did: null,
    },
  ],
  flds: [
    {
      name: 'Front',
      media: [],
      sticky: false,
      rtl: false,
      ord: 0,
      font: 'Arial',
      size: 20,
    },
    {
      name: 'Transcription',
      media: [],
      sticky: false,
      rtl: false,
      ord: 1,
      font: 'Arial',
      size: 20,
    },
    {
      name: 'Back',
      media: [],
      sticky: false,
      rtl: false,
      ord: 2,
      font: 'Arial',
      size: 20,
    },
  ],
});

// Note 1
const noteGermanVocabularyDeck = await builder.addNote({
  noteTypeId: germanVocabularyNoteType.id,
  fields: ['fragen', 'запитувати, дізнаватися'],
});
// Forward Card: "fragen" -> "запитувати, дізнаватися"
await builder.addCard({
  nid: noteGermanVocabularyDeck.id,
  did: germanVocabularyDeck.id,
  ord: 0, // Forward Card template of German Vocabulary
});
// Reverse Card: "запитувати, дізнаватися" -> "fragen"
await builder.addCard({
  nid: noteGermanVocabularyDeck.id,
  did: germanVocabularyDeck.id,
  ord: 1, // Reverse Card template of German Vocabulary
});

// Note 2
const noteEnglishVocabularyDeck = await builder.addNote({
  noteTypeId: englishVocabularyNoteType.id,
  fields: ['read', 'ri:d', 'читати'],
});
await builder.addCard({
  nid: noteEnglishVocabularyDeck.id,
  did: englishVocabularyDeck.id,
  ord: 0,
});

// Note 3
const noteWithImageEnglishVocabularyDeck = await builder.addNote({
  noteTypeId: englishVocabularyNoteType.id,
  fields: ['write<br><img src="write.jpeg" alt="write">', 'rīt', 'писати'],
});
await builder.addCard({
  nid: noteWithImageEnglishVocabularyDeck.id,
  did: englishVocabularyDeck.id,
  ord: 0,
});

// Add media from Note 3
await builder.addMedia({
  fileName: 'write.jpeg', // Should be unique across all decks
  data: readFileSync(path.resolve(__dirname, 'write.jpeg')),
});

await builder.generateApkg(path.resolve(__dirname, 'decks-to-import.apkg'));

To create multiple .apkg files, generate a new builder using AnkiApkgBuilderFactory for each file:

import { AnkiApkgBuilderFactory } from '@mdanki/apkg-builder';

for (const archiveInput of archiveInputs) {
  const builder = new AnkiApkgBuilderFactory().create();
  // ...
}

License

ISC License, Copyright (c) 2024, Oleksandr Shlinchak.