@music-lyric-player/utils
v0.10.0
Published
Music Lyric Player - Utils
Downloads
900
Readme
@music-lyric-player/utils
Shared utilities for the
music-lyric-playerfamily.
Internal helpers consumed by @music-lyric-player/base and @music-lyric-player/dom. You usually do not need to install this directly — it is pulled in transitively.
Part of music-lyric-player-web.
Install
npm install @music-lyric-player/utilsWhat's inside
| Export | Purpose |
| ----------------------------------------------- | ------------------------------------------------------------------------------------------------------ |
| ConfigManager | Reactive, deeply-mergeable typed config with an update event that emits the set of changed key paths |
| Event | Typed event emitter with add / remove / emit / clear |
| deepCompare, freezeDeep, hasKeyContaining | Object helpers used by the renderer for change-detection and read-only state |
| random, regex | Small pure helpers |
| DeepPartial, DeepRequired, NestedKeys | Type helpers used by config types |
Example
import { ConfigManager, Event } from '@music-lyric-player/utils'
const config = new ConfigManager({ foo: 1, bar: { baz: 2 } }, {})
config.event.add('update', (changedKeys) => {
// changedKeys is a Set of changed key paths, e.g. Set { 'bar.baz' }
})
config.update({ bar: { baz: 3 } })
const event = new Event()
event.add('hello', (name) => console.log(`hi ${name}`))
event.emit('hello', 'world')