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

stylog

v1.1.0

Published

🎨 Stylish way how to easily format console.log messages

Downloads

4

Readme

Table of Contents

Introduction

codecov

Stylog is a stylish way how to easily format rich console.log messages.

It's overengineered on purpose I just wanted to write it in the "old school" way and avoid RegExps. It has been written with a nostalgic memory to the Dragon Book 🐲

Install

yarn add stylog

The library is targeted for the last two version of Chrome, it's designed to be used mostly in dev mode within latest dev tools.

Usage

API

stylog(
  (recipe: string),
  (stylesDictionary: ?{
    [id: string]: {
      [property: string]: string
    }
  }),
  (mapperDictionary ?{
    [id: string]: (value: string) => string
  })
);

If you are fan of FP you can take full advantage of the data-last curried version!✌️

stylog.fp(mapperDictionary)(stylesDictionary)(recipe);

Recipe

  • text is everything outside (non-escaped) "{"
  • styled text start with "{" followed by id (string) and optionally text (multiline string) then it should be closed with "}"
  • each styled text may have corresponding style in stylesDictionary otherwise it would be rendered as text
  • styled text can be escaped by \ (in template literal you have to use \\ ) then it would be considered as text
This is normal text {styled this is styled text}
This is normal text \{styled this is also normal text}

Styles Dictionary

  • is an nullable-object where key should be string matching id of styled text and value is supposed to be object of CSS properties in camelCase notation.
  • it could be null
{
  styled: {
    fontSize: "20px"; // or "fontSize: 20" :)
  }
}

Mapper Dictionary

  • is an nullable-object where key should be string matching id of styled text and value is supposed to be an function which takes that matched string and returns modified string (optionally could return falsy value which will act as empty string)
{
  // return c👏l👏a👏p👏e👏d string
  clap: s => {
    return [...s]
      .map((a, i) => `${a}${i !== s.length - 1 ? "👏" : ""}`)
      .join("");
  };
}

Example

Check it out the example/index.html for interactive playground! 🙌

stylog(
  `{big Hello, everyone! This is nicely styled text!} 
and non-styled text. Lovely, right? {bold *clap* *clap* *clap*} 

{image [GANDALF]} {red Be aware! Wild Gandalf appears!}

.
.
.

\\{gandalf}

.
.
.

not like this

.
.
.
{gandalf}

{clap Awesome}`,
  {
    bold: {
      fontWeight: "bold"
    },
    big: {
      fontSize: "25px",
      border: "1px solid black",
      padding: "10px"
    },
    image: {
      display: "block !important",
      color: "gray",
      fontSize: "10px",
      background: `url("https://vignette.wikia.nocookie.net/casshan/images/d/dc/Warn.png/revision/latest?cb=20120614181856")`,
      backgroundSize: "15px 15px",
      backgroundRepeat: "no-repeat",
      backgroundPosition: "left",
      paddingLeft: "15px"
    },
    red: {
      color: "red",
      textDecoration: "underline"
    },
    gandalf: {
      display: "block !important",
      color: "gray",
      fontSize: "300px",
      lineHeight: "150px",
      display: "block !important",
      background: `url("https://i.giphy.com/media/FyetIxXamPsfC/giphy.webp")`,
      backgroundSize: "200px",
      backgroundRepeat: "no-repeat",
      backgroundPosition: "left"
    },
    clap: {
      background: "black",
      color: "yellow"
    }
  },
  {
    clap: s => {
      return [...s]
        .map((a, i) => `${a}${i !== s.length - 1 ? "👏" : ""}`)
        .join("");
    }
  }
);

will produce this:

Contributing

Do you miss something? Open an issue, I'd like to hear more about your use case. You can also fork this repository and run yarn && yarn dev, do stuff in the playground (example/index.html), then run yarn test and finally send a PR! ❤️

License

The MIT License (MIT) 2018 - Jakub Beneš