-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathexample.ts
45 lines (38 loc) · 1.06 KB
/
example.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import fs from 'fs'
import { Package, Deck, Note, Model, Field, Card } from '../src/index'
async function test () {
const fields = [
{ name: 'Answer' },
{ name: 'Question' },
{ name: 'MyMedia' },
]
const card = new Card()
card.setCss().setTemplates([
{
name: 'Card 1',
qfmt: '{{Question}}<br>{{MyMedia}}',
afmt: '{{FrontSide}}<hr id="answer">{{Answer}}',
},
])
const model = new Model(card)
model
.setName('modelName')
.setSticky(true)
.setFields(fields.map((f, index) => new Field(f.name).setOrd(index)))
const note = new Note(model)
note
.setFieldsValue([
'Capital of Argentina',
'Buenos Aires',
'media',
])
.setTags(['q', 'z'])
const deck = new Deck('deckName')
deck.addNote(note)
const pkg = new Package(deck)
const zip: any = await pkg.writeToFile()
const target = './test.apkg'
fs.writeFileSync(target, zip, 'binary')
console.log('success')
}
test()