Document authorsNote
This commit is contained in:
parent
b7304aff05
commit
4a4ccdb603
2 changed files with 46 additions and 1 deletions
40
examples/authorsNote.js
Normal file
40
examples/authorsNote.js
Normal file
|
@ -0,0 +1,40 @@
|
|||
const themes = [
|
||||
{
|
||||
text: 'ghost story',
|
||||
matcher: /ghost|halloween|spooky/i,
|
||||
},
|
||||
{
|
||||
text: 'trick-or-treat',
|
||||
matcher: /trick.or.treat|halloween|spooky/i,
|
||||
},
|
||||
{
|
||||
text: 'spooky',
|
||||
matcher: /halloween|spooky/i,
|
||||
},
|
||||
]
|
||||
|
||||
const modifier = (text) => {
|
||||
if (!state.setup) {
|
||||
state.theme = Math.floor(Math.random() * themes.length)
|
||||
state.setup = true
|
||||
state.matched = false
|
||||
}
|
||||
|
||||
const theme = themes[state.theme]
|
||||
|
||||
if (!state.matched && text.match(theme.matcher)) {
|
||||
state.matched = true
|
||||
}
|
||||
|
||||
if (state.matched) {
|
||||
state.memory = {}
|
||||
} else {
|
||||
const halloween = ` It involves Halloween and has a ${theme.text} theme.`
|
||||
state.memory = { authorsNote: `the rest of this story is silly & playful.${halloween}` }
|
||||
}
|
||||
|
||||
return {text}
|
||||
}
|
||||
|
||||
// Don't modify this part
|
||||
modifier(text)
|
Reference in a new issue