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

pollito

v1.0.2

Published

A simple logger with colors

Downloads

8

Readme

Pollito

A simple colorized logger

Pollito is a very simple logger with some color customizations.

How to use:

Create a new instance with new:

const pollito = new Pollito();

We can create a new instance of Pollito logger with new. We get an object of type Pollito.

Create a new instance with the creator method:

const pollito = Pollito.createInstance();

We get a new isntance of Pollito logger with this method.

It does not matter the creation method to get a instance. The created instance itself will be added to an internal static object in Pollito, accessible with the name of the intance. If we do not provide a name for the instance, automatically it will be named as pollito(length + 1).

Options for the constructor

We can provide some options at construction time of a new instance of Pollito:

  • options: <Object> Optional argument. It can has the props: Default: {}
    • instanceName: <string> The name for the instance. Default: pollito + Pollito.instances.length + 1
    • stringColor: <string> The color used to print strings. Default: normal yellow
    • numberColor: <string> The color used to print numbers. Default: normal magenta
    • arrayStartColor: <string> The color used for the first level of an array. Default: normal red,
    • watch: <Object> Options to watch and emphasise a string.
      • string: <string> The string to watch
      • watchColor: <string> The color used to emphasise the string
      • watchBackground: <string> The color used as background to emphasise the string

All these arguments are optionals, unless watch.string if watch object is present.

Recover the Pollito logger from instances array

We can keep all our different Pollito instances in our Pollito.instances object. So we can access them whenever we need them.

We can supose we have created an instance named as pollito_red:

Pollito.createInstance({
    instanceName: 'pollito_red',
    stringColor: 'bright red'
});

After we call the Pollito.createInstance or new Pollito, a new instance is returned by the method or constructor. At the same time, the instance is saved to Pollito.instances object.

We can recover the instance created with Pollito.getInsance:

const pollitoRed = Pollito.getInstance('pollito_red');

How to log something

We have 3 different and simple methods to log data:

pollitoInstance.log(...data)

  • ...data ...<string[]> | ...<any[]> | ...<object[]>

Log to the console all the data passed as argument, colon separated. It will be printed separated by a colon and a \n character.

pollito.log('hello', [1, 2, 3, 'something', undefined, null], { 'hello': 'world', or: { some: 'thing' } })

Output:

output

pollitoInstance.dateLog(data[, options])

  • data <string> | <any[]> | <Object>
  • options <Object>
    • dateFormat <string> The format to print the date object. Default: localeString

Log something to the console, with the addition of the printing date-time

pollito.dateLog({hello: 'world'});

Output:

output2

possible values for dateFormat:


| Value | Description | | ------------- | ------------------------------------- | | localeString | Calls the method toLocaleString | | string | Calls the method toString | | miliseconds | Parse the Date object to milliseconds |

pollitoInstance.stringify(value)

  • value <any>

It calls internally to JSON.stringify, printing the result with no formats or colors.

pollito.stringify({ hello: 'world' });

Output:

{"hello":"world"}

Watch a string

We can set a string to watch, so if it beign printed, it will have a background and a text color differente than the other text.

Ejample:

const pollito = new Pollito({
    watch: {
        string: 'he',
        watchBackground: 'bright magenta',
        watchColor: 'bright cyan'
    }
});

pollito.log({ hello: 'world', reheat: 'the chicken', something: '`helse`' });

Output:

output3

The watch options are set at instance creation time. However, we can modify these options with the methods:

pollitoInstance.setWatchString(string)

  • string <string> The new string to watch
pollito.setWatchString('hello');

pollitoInstance.setWatchBg(bg)

  • bg <string> The new background color the watching string will have when printed
pollito.setWatchBg('bright magenta');

pollitoIsntance.setWatchColor(color)

  • color <string> The new text color the watched string is going to use when printed
pollito.setWatchColor('normal red');

Possible colors for text

| Normal colors | Bright colors | | ----------------------- | ----------------------------- | | normal blue | bright blue | | normal red | bright red | | normal green | bright green | | normal magenta | bright magenta | | normal cyan | bright cyan | | normal yellow | bright yellow |

Possible colors for background

| Normal colors | Bright colors | | ----------------------- | ----------------------------- | | normal blue | bright blue | | normal red | bright red | | normal green | bright green | | normal magenta | bright magenta | | normal cyan | bright cyan | | normal yellow | bright yellow | | normal black | bright black | | normal white | bright white |

License

Lisence under MIT.