Easter eggs as a service
Finally a production ready and framework agnostic library to help bring back the magic of easter eggs into every app and website (built with modern JavaScript).
Installation
npm i @eeaas/core
Once installed you can import the utility and start creating your own easter eggs.
Basic usage
import { initializeEeaas } from '@eeaas/core'
const eeaas = initializeEeaas()
eeaas.register({
name: 'MyEgg',
onStart() {
console.log('Easter egg time...')
},
onStop() {
console.log('So sad...')
},
})
const egg = eeaas.get('MyEgg')
egg.start()
Building your own egg
You can create quite complex easter eggs, the basic structure of an egg is as follows:
const MyEgg = {
name: string
enabled?: boolean
trigger?: Trigger
stopTrigger?: Trigger
resources?: Resource[]
onStart: (loadedResources: LoadedResource[]) => void | Promise<void>
onStop: (loadedResources: LoadedResource[]) => void | Promise<void>
}
The Trigger allows you to run code when a user enters a sequence of characters instead of solely relying on the egg.start()
method.
Here's the list of valid keystrokes.
Example usage:
trigger: {
type: 'keys',
keystrokes: ['n', 'y', 'a', 'n'],
captureOnInputs: false,
}
This will cause the egg to run its logic when the user enters 'nyan' anywhere, except when the user is actively entering data into an input or textarea - this logic can be toggled with the captureOnInputs
flag (default: true).
Eeaas methods
Eeaas comes with 3 built-in methods. These methods are mainly used to add and access eggs.
register(egg: UserEgg) | Used to add an egg |
get(name: string) | Used to retrieve an egg, useful for triggering the egg |
getInstance() | Used to access the eeaas instance anywhere in the app |