A bare bones Markov calculator that operates on arrays or strings.
Load via HTML script tag:
<!-- Just an IIFE namespaced `markov` -->
<script src="https://thewhodidthis.github.io/markov/markov.js"></script>
Source from an import map:
{
"imports": {
"@thewhodidthis/markov": "https://thewhodidthis.github.io/markov/main.js"
}
}
Download from GitHub directly if using a package manager:
# Add to package.json
npm install thewhodidthis/markov
Be iterating:
const markov = require("@thewhodidthis/markov")
const filter = ((source) => {
const step = markov(source)
const tick = function*() {
while (1) {
yield step()
}
}
return tick()
})("mama mia, mama mia, mama mia".split(" "))
filter.next()
Be async:
import markov from "@thewhodidthis/markov"
const bender = async (data = "") => {
const step = markov(data)
const next = await step()
return next
}
bender("mama mia, mama mia, mama mia".split(" ")).then(console.log)