https://github.com/alloc/log-format
Evaluate console.log format specifiers before logging
https://github.com/alloc/log-format
console-log format pretty-format string
Last synced: 11 months ago
JSON representation
Evaluate console.log format specifiers before logging
- Host: GitHub
- URL: https://github.com/alloc/log-format
- Owner: alloc
- Created: 2020-06-26T18:32:02.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-08-03T06:18:23.000Z (over 2 years ago)
- Last Synced: 2025-01-11T21:33:12.152Z (about 1 year ago)
- Topics: console-log, format, pretty-format, string
- Language: JavaScript
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# @alloc/log-format
Evaluate `console.log` format specifiers (eg: `%O`) before logging.
**Format specifiers:**
- `%O` Use [`pretty-format`](https://www.npmjs.com/package/pretty-format) before insertion
- `%s` Use `String(value)` before insertion
- `%f` Use `Number(value)` before insertion
- `%d` Use `Math.floor(value)` before insertion (alias: `%i`)
### Example
```js
import format from '@alloc/log-format'
format('a: %O, b: %O', /.+/, new Date)
// => 'a: /.+/, b: 2020-06-26T18:39:40.258Z'
format({ a: [1, 2], b: new Set([3, 4]) })
// => '{"a": [1, 2], "b": Set {3, 4}}'
```