Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add META symbol to exports (#84)
Two things to note: - The key is the string `'META'` - The value is `Symbol('proc-log.meta')` So it could be used like the following. All of the following is up to producers/consumers to implement with shared conventions. All `proc-log` is doing to allowing them to share a unique `Symbol`. ```js const { output, META } = require('../') // An example of how consumers would see if a META object // was the last argument from an event const getMeta = (args) => { let meta = {} const last = args.at(-1) if (last && typeof last === 'object' && Object.hasOwn(last, META)) { meta = args.pop() } return [meta, ...args] } process.on('output', (level, ...rawArgs) => { const [{ force = false }, ...args] = getMeta(rawArgs) console.log(level, { force, args }) }) // in this implementation the value does not matter, just the key output.standard('arg1', 'arg2', { [META]: null, force: true }) output.standard('arg1', 'arg2') output.standard('arg1', null) output.standard(null) output.standard() // Will log the following: // standard { force: true, args: [ 'arg1', 'arg2' ] } // standard { force: false, args: [ 'arg1', 'arg2' ] } // standard { force: false, args: [ 'arg1', null ] } // standard { force: false, args: [ null ] } // standard { force: false, args: [] } ``` Closes: #81
- Loading branch information