npm.io
1.0.2 • Published 3 years ago

@retrohack3r/cloze

Licence
MIT
Version
1.0.2
Deps
0
Size
5 kB
Vulns
0
Weekly
0

Usage

Takes a string containing anki style cloze notation and returns an array.

const cloze = require('@retrohack3r/cloze')

/* Returns:
[ { c: 1, answer: 'answer', hint: 'hint' } ]
*/
cloze('{{c1::answer::hint}}')

/* Returns:
[
  'foo ',
  { c: 2, answer: 'bar', hint: undefined },
  ' beep ',
  { c: 1, answer: 'fizz', hint: 'buzz' },
  'boop'
]
*/
cloze('foo {{c2::bar}} beep {{c1::fizz::buzz}}boop')

The returned array contains each "chunk" of the string, where a chunk is either a plaintext string or a cloze. You can reconstruct the original string from reading the array from left to right.

Keywords