Skip to content

Web5design/console-extras.js

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Console Extras

This package contains chainable enhancements to the JavaScript console object.

Builds: dist/console-extras.js and dist/console-extras.min.js.

Methods

console.times(n)
Limits the next call to n invocations.
e.g.

console.times(5).log("This message will only show up 5 times.")

console.throttle(n)
Throttles the next call to at most once every n milliseconds.
e.g.

console.throttle(1000).log("This message will only show up once per second.")

console.collate(...)
Collects arbitrary data for summarization. Accepts numbers, strings, arrays, objects.

console.summary()
Displays a summary of collated data: Average/stddev for numbers, unique string counts, objects by type, arrays by elements. Must be called in the same chain as .collate().

Examples

Chaining

console.times(5).throttle(1000).log("This message will be printed once per second, up to 5 times.")

Collecting data in a live app e.g.

console
  .collate(1, "foo", { x: 1, y: 2 }, [ 1, 2 ])
  .collate(2, "bar", { x: 2, y: 4 }, [ 5, 4 ])
  .collate(3, "bar", { x: 3, y: 4 }, [ 2, 3 ])
  .throttle(1000)
  .summary()

results in:

0: 2 ± 0.82 (×3)
1: 
  "foo" (×1)
  "bar" (×2)
2: 
  Object (×3)
    x: 2 ± 0.82 (×3)
    y: 3.33 ± 0.94 (×3)
3: 
  Array
    0: 2.67 ± 1.7 (×3)
    1: 3 ± 0.82 (×3)

If you do this in a loop with dynamic data, you will get a summary printed out every second of all collected data. The data is reset every time the summary is output.

About

Enhancements to the JavaScript console object.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published