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

js-logs-formatter

v0.8.6

Published

Logger library for readable server logs, useful for tools like React Native, Node.js and Next.js server components. Also useful for SPAs with browser log

Downloads

46

Readme

JS Logs Formatter

JS Logs Formatter is a lightweight logging utility designed to format server logs for better readability in tools like React Native, Node.js and Next.js server components. Also useful for SPAs. It aims to enhance your debugging experience by providing structured and easy-to-read log outputs.

Table of Contents

Installation

You can install JS Logs Formatter via npm or yarn:

yarn add js-logs-formatter

using npm:

npm install js-logs-formatter

Expo (React Native)

npx expo install js-logs-formatter

Usage

To use JS Logs Formatter, import the println function and call it with a helper string, color and the data you want to log.

import { println } from "js-logs-formatter";

// Example data
const user = {
  name: "Jane Doe",
  age: 28,
  active: false,
  email: "[email protected]",
  phone: "+1234567890",
  address: {
    street: "123 Main St",
    city: "Anytown",
    state: "CA",
    zipCode: "12345",
  },
  preferences: {
    newsletter: true,
    notifications: {
      email: true,
      sms: false,
    },
  },
  createdAt: "2022-01-15T14:30:00Z",
  lastLogin: "2023-09-28T10:00:00Z",
  roles: ["user", "admin"],
  points: 1500,
};

// Using println with a helper text and color
println({
  helper: "User Data",
  data: user,
  color: "green", // Optional color for the log
  showFunctionOrigin: true, // Show the calling function and line number (default is true)
});

This will output the following to the console with a green color:

User Data (called from function: yourFunctionName at line yourLineNumber) =>
{
  "name": "Jane Doe",
  "age": 28,
  "active": false,
  "email": "[email protected]",
  "phone": "+1234567890",
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zipCode": "12345"
  },
  "preferences": {
    "newsletter": true,
    "notifications": {
      "email": true,
      "sms": false
    }
  },
  "createdAt": "2022-01-15T14:30:00Z",
  "lastLogin": "2023-09-28T10:00:00Z",
  "roles": [
    "user",
    "admin"
  ],
  "points": 1500
}

Note: Due to differences in how React Native handles stack traces, the accuracy of line numbers and function names can vary. While the println function captures file names and line numbers accurately in Node.js environments, in React Native, the stack trace format may include network-related information or different formatting, making line numbers less predictable. For best results, focus on the file name and function name when using this in a React Native environment.

Minimal usage

// Using println without helper text, function name or color
println({
  data: user,
  showFunctionOrigin: false,
});

This will output the following to the console:

{
  "name": "Jane Doe",
  "age": 28,
  "active": false,
  "email": "[email protected]",
  "phone": "+1234567890",
  "address": {
    "street": "123 Main St",
    "city": "Anytown",
    "state": "CA",
    "zipCode": "12345"
  },
  "preferences": {
    "newsletter": true,
    "notifications": {
      "email": true,
      "sms": false
    }
  },
  "createdAt": "2022-01-15T14:30:00Z",
  "lastLogin": "2023-09-28T10:00:00Z",
  "roles": [
    "user",
    "admin"
  ],
  "points": 1500
}

API

| Prop | Description | Default | | -------------------- | ---------------------------------------------------------------------------------------------------------- | ------------------- | | helper | A string that describes the context of the log message. It helps identify what the logged data represents. | "" (empty string) | | data | The data you want to log, which can be of any type (e.g., object, array, string). | N/A | | color | The color applied to the logged data. Available color options are listed here. | reset | | showFunctionOrigin | Determines whether the logs will show the name of the function and line number where println was called. | true |

Available Colors

The color prop allows you to customize the color of the log output. Here are the available color options:

Foreground Colors:

  • reset
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • black

Bright Foreground Colors:

  • brightRed
  • brightGreen
  • brightYellow
  • brightBlue
  • brightMagenta
  • brightCyan
  • brightWhite

Background Colors:

  • bgRed
  • bgGreen
  • bgYellow
  • bgBlue
  • bgMagenta
  • bgCyan
  • bgWhite
  • bgBlack

Bright Background Colors:

  • bgBrightRed
  • bgBrightGreen
  • bgBrightYellow
  • bgBrightBlue
  • bgBrightMagenta
  • bgBrightCyan
  • bgBrightWhite

You can use any of these options when passing the color prop to the println function.

Contributing

Contributions are welcome! Please feel free to submit a pull request or open an issue to discuss any changes.

License

This project is licensed under the MIT License.