npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@htmlacademy/in-browser-console.js

v1.1.5

Published

Inbrowser Demo Console

Downloads

3

Readme

console.js Build Status

Chrome-like in-browser console

Available methods:

  • log
  • info — same as log
  • dir
  • error
  • warn — same as error
  • logHTML — same as log, but strings won't be escaped

Usage

Manual setting

Connect script https://htmlacademy.github.io/console.js/latest/js/index.js, style file https://htmlacademy.github.io/console.js/latest/css/style.css on page, create new Console instance by passing output container and optional config

<head>
  <link rel="stylesheet" href="//htmlacademy.github.io/console.js/latest/css/style.css">
</head>
<body>
  <div class="console-container"></div>
  <script src="//htmlacademy.github.io/console.js/latest/js/index.js"></script>

  <script>
    const params = {
      expandDepth: 1,
      common: {
        excludeProperties: [`__proto__`],
        maxFieldsInHead: 5,
        minFieldsToAutoexpand: 5,
        maxFieldsToAutoexpand: 15
      }
    };
    var jsConsole = new Console(document.querySelector('.console-container'), params);

    jsConsole.log("Here is console.log!");

    // console.log = jsConsole.log.bind(jsConsole);
    // console.dir = jsConsole.dir.bind(jsConsole);
    // ...
    // console.log(123);
    // or use Console.prototype.extend()
    // jsConsole.extend(console);
    // console.log(123);
  </script>
</body>

Silent

Connect script https://htmlacademy.github.io/console.js/latest/js/index-silent.js on page

Script will automatically create console container and extend native browser window.console

<script src="//htmlacademy.github.io/console.js/latest/js/index-silent.js"></script>

<script>
 console.log(123);
</script>

Presets

Use predefined configurations by connecting scripts on page

Available presets

You can use both to enable autoexpanding with defined behaviour.

Connecting presets on page

<script src="//htmlacademy.github.io/console.js/latest/js/presets/preset-1.js"></script>
<script src="//htmlacademy.github.io/console.js/latest/js/presets/preset-2.js"></script>
<script src="//htmlacademy.github.io/console.js/latest/js/index-silent.js"></script>

Lower connected preset script has higher priority than others. Will be merged with lodash.mergeWith using concatinating arrays

Console constructor

const jsConsole = new Console(DOMElement, config);

Parameters

DOMElement — container to append console DOM element within.

config — object containing settings

You can specify 3 types of views here: object, function and array. And common, that has lower priority than concrete. Will be merged into concrete one with lodash.mergeWith using concatinating arrays

  • expandDepth — depth on which fields of this root object will be expanded. Default: 0.
  • maxFieldsInHead — max length of properties in preview (head). If has more, ... at the end will be showed. Default: 5.
  • minFieldsToAutoexpand — min length of fields in view type to auto expand. Default: 0.
  • maxFieldsToAutoexpand — max length respectively. Default: Positive infinity.
  • excludeViewTypesFromAutoexpand — array of view types that don't need to be expanded inside that root view type.
  • showGetters — specifies if get and set methods will be showed in expanded object body. Default: true.
  • showMethodBodyOnly — if function is a method of any type of object — shows only body of this function (in opened object).
  • excludePropertiesFromAutoexpand — properties in view type which wouldn't be auto expanded.
  • removeProperties — array of properties to remove from view.

Specific properties for array:

  • countEntriesWithoutKeys — useful only if maxFieldsInHead given. Specifies if indexed properties should be counted in preview (head). Default: false.

Specific properties for function:

  • nowrapOnLog — specifies if functions bodies will be collapsed. Default: false.

Example:

{
  object: {
    expandDepth: 2,
    minFieldsToAutoexpand: 1, // will expand if object has 1 or more enumerable fields
    excludeViewTypesFromAutoexpand: [`function`, `array`] // will not expanded inside object,
    showMethodBodyOnly: true // show method's body only (if object was opened)
  },
  function: {
    expandDepth: 1 // will expand only itself (in dir mode only),
    nowrapOnLog: true // On log will collapse function body
  },
  array: {
    expandDepth: 2, // expand 2 levels
    minFieldsToAutoexpand: 4, // if there is 4 enum fields in array
    excludeViewTypesFromAutoexpand: [`object`] // objects inside array won't be expanded
    countEntriesWithoutKeys: true
  },
  common: {
    expandDepth: 1,
    maxFieldsInHead: 6, // object and array will have up to 6 properties in their previews (headers)
    maxFieldsToAutoexpand: 10 // if there's more than 10 properties in obj of any type, it won't be expanded
  }
}

Config merge example

Common merge

This config:

{
  object: {
    maxFieldsToAutoexpand: 10,
    excludeViewTypesFromAutoexpand: [`object`]
  },
  common: {
    expandDepth: 1
    maxFieldsToAutoexpand: 15,
    excludeViewTypesFromAutoexpand: [`array`]
  }
};

will be transformed into this on application start:

{
  object: {
    maxFieldsToAutoexpand: 10,
    expandDepth: 1,
    excludeViewTypesFromAutoexpand: [`object`, `array`]
  }
}

Presets merge

Using lodash.mergeWith to merge objects and concat arrays inside them

You have 2 preset files:

<script src="//htmlacademy.github.io/console.js/latest/js/presets/preset-1.js"></script>
<script src="//htmlacademy.github.io/console.js/latest/js/presets/preset-2.js"></script>
<script src="//htmlacademy.github.io/console.js/latest/js/index-silent.js"></script>

preset-1.js contains:

{
  object: {
    maxFieldsToAutoexpand: 5,
    excludeViewTypesFromAutoexpand: [`object`]
  },
  common: {
    excludeViewTypesFromAutoexpand: [`function`]
  }
}

preset-2.js contains:

{
  object: {
    maxFieldsToAutoexpand: 10
  },
  common: {
    expandDepth: 1
    excludeViewTypesFromAutoexpand: [`array`]
  }
}

result will be:

{
  object: {
    maxFieldsToAutoexpand: 10,
    excludeViewTypesFromAutoexpand: [`object`]
  },
  common: {
    expandDepth: 1
    excludeViewTypesFromAutoexpand: [`array`, `function`]
  }
}