peek42
v5.9.2
Published
Touch based browser console
Downloads
96
Readme
Peek42
Touch based browser console

Demo
Distribution
Unpkg - https://unpkg.com/peek42@latest/dist/
- Node module (CJS) - https://unpkg.com/peek42@latest/dist/peek42.node.js (tiny wrapper over
console.log) - Browser bundle (UMD) - https://unpkg.com/peek42@latest/dist/peek42.browser.js
- Node ES module - https://unpkg.com/peek42@latest/dist/peek42.node.mjs
- Bundlers/browsers ES module - https://unpkg.com/peek42@latest/dist/peek42.browser.mjs
- Monofur font (LICENCE_Monofur) - https://unpkg.com/peek42@latest/dist/monofur.woff
- Main style - https://unpkg.com/peek42@latest/dist/peek42.css
- Dark theme - https://unpkg.com/peek42@latest/dist/peek42-dark.css
- Bookmarklet - https://unpkg.com/peek42@latest/dist/peek42.bookmarklet.unpkg.js
Install
(See ApiVis for installing apivis.js)
Node
(apivis is optional)
npm install apivis
npm install peek42All distribution files are in node_modules/peek42/dist/
Browser
(monofur.woff is expected to be next to peek42.css, peek42-dark.css, apivis.browser.js and source-map.js are optional)
<link rel="stylesheet" href="https://unpkg.com/peek42@latest/dist/peek42.css" />
<link rel="stylesheet" href="https://unpkg.com/peek42@latest/dist/peek42-dark.css" />
<script src="https://unpkg.com/apivis@latest/dist/apivis.browser.js"></script>
<script src="https://unpkg.com/peek42@latest/dist/peek42.browser.js"></script>
<script src="https://unpkg.com/source-map@latest/dist/source-map.js"></script>
<script>sourceMap.SourceMapConsumer.initialize({
'lib/mappings.wasm': 'https://unpkg.com/source-map@latest/lib/mappings.wasm'
});</script>Configuration options can be specified by adding a script before peek42.browser.js (values shown are the defaults):
<script>window.PEEK42_CONFIG = {
interceptConsole: true, // Intercept window.console log, info, warn and error calls
addGlobals: true, // Assign p and pp to window
autoUse: true // Integrate ApiVis automatically (needs to be loaded before Peek42)
};</script>Bookmarklet
Bookmark a webpage (any will do). Then change the title to your liking and the url to the contents of peek42.bookmarklet.unpkg.js
Use
Node
const apivis = require('apivis');
const peek42 = require('peek42').use(apivis);
const {p, pp} = peek42;
p.api(process);Browser
document.addEventListener('DOMContentLoaded', () => {
p.api(document);
});ES module
// Node
import apivis from 'apivis';
import peek42, {p, pp} from 'peek42/dist/peek42.node';
peek42.use(apivis);
// Bundlers
import apivis from 'apivis';
import peek42, {p, pp} from 'peek42';
peek42.use(apivis);
// Use the importsAPI
The following properties/functions are available through the peek42 namespace object returned from require('peek42') on node or available as window.peek42 in the browser (the ES module has the namespace object as default export and p, pp and pretty as named exports):
version- library versionp(val[, comment[, opts]])- printvalue with optionalcomment(undefinedand''cause default comment to be generated,nullmeans no comment),optscan be used to specify the log level -{level: 'info'}for example, the default is{level: 'log'}, the other possibilities are'info','warn'and'error'. Setting{collapsed: true}causes the log entry to be initially collapsed (only the comment is visible, tap it to expand/collapse using the UI). If ApiVis is installed andpeek42.use(apivis)executed,pitself gains the following methods (some are built-in):p.type(val[, comment[, opts]])p.desc(val, k[, comment[, opts]])p.member(val, k[, comment[, opts]])p.members(val[, comment[, opts]])p.pretty(val[, comment[, opts]])(peek42built-in)p.inspectStr(val[, comment[, opts]])(betterpp)p.inspectHtml(val[, comment[, opts]])(p.inspectStrfeaturing collapse/expand)p.inspect(val[, comment[, opts]])(usesp.inspectHtmlif available, falls back top.inspectStr)p.chain(val[, comment[, opts]])p.apiStr(val[, comment[, opts]])p.apiHtml(val[, comment[, opts]])(p.apiStrfeaturing collapse/expand)p.api(val[, comment[, opts]])(usesp.apiHtmlif available, falls back top.apiStr)p.domStr(val[, comment[, opts]])(peek42built-in, browser only)p.domHtml(val[, comment[, opts]])(p.domStrfeaturing collapse/expand)p.dom(val[, comment[, opts]])(usesp.domHtmlif available, falls back top.domStr(browser only))p.trace(peek42built-in)
The mandatory parameters mirror those of the corresponding
apivis.xxxStrfunctions.commentandoptsare the same as withp.p.members,p.inspect,p.chainandp.apiaccept{indent: 'string'}as additional option andp.membersaccepts{indentLevel: 'number'}as another aditional optionpp(val[, comment[, opts]])- pretty printvalue - UsesJSON.stringify(handling circular references) (Since v5.8.0ppusesp.inspectif available (falls back top.prettybacked byJSON.stringifyif not))pandppare meant to be the primary library interface (do a suitable assignment or import as per the use examples, by default the browser builds assign them towindow)pretty(val)- prettified value as printed byppas a stringuse(lib)- register peek42 pluginConsole(browser only, advanced usage) - theconsoleclass, use itsinstancestatic getter (returnsPromise) to safely obtain reference to initializedconsoleoutside ofdocumentreadyblocksConsole.instance.then(console => { // Use console }); // or using async/await let console = await Console.instance; // Use consoleconsole(browser only, advanced usage) - theconsoleinstance, use its methods (after making sure it is initialized either viaConsole.instancewait or indocumentreadyblock) to drive it through code (usep.api(peek42.console)to find out the API)cable- TODO: Document server/client websocket init and usagecp(plus apivis extensions viause),cpp- node side of a web app, client print using websocket
peek42 intercepts the native console logging function calls, so console.log calls (for example) will show up
peek42 listens for JavaScript errors (including unhandledrejection of promises) and shows them with the error message as a comment and source snippet and stack trace if possible
UI
If no log function has been called, peek42 is shown minimized. Tap Show to show it. By default, whenever a log function is called, peek42 is shown and the log is scrolled to the top (entries are logged from oldest at the bottom to newest at the top), so that the latest entry is visible. Tap Minimize to minimize it. This can be changed by turning on the Quiet checkbox (visible only when peek42 is minimized). In this mode, peek42 flashes on log write, but stays minimized. Tapping the title alternates the log position between start/end. Use Resize to resize peek42 (peek42 limits its dimensions and the border briefly flashes upon reaching the limits) and Clear to clear the log contents. The buttons on the right can be used to collapse/expand all entries and to filter them by log level (info, log, warn, error). They work like a set of checkboxes (each controls the visibility of the particular level) and show the number of corresponding entries. If peek42 is in quiet mode, log write with filtered out level doesn't show it (the entry is written and peek flashes)
Use the text box JS to evaluate to eval JavaScript code (write in the box and simply hit enter). Print functions can be specified by prefixing the expression with one of v(alue) (the default), p(retty), t(ype), d(esc) (requires two arguments separated by a comma), m(embers), c(hain), a(pi). Only v(alue) and p(retty) are supported out of the box, the others require ApiVis
See the example folder for node and browser examples respectively
