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

@vandie/customconsole

v1.1.1

Published

Allows you to create a custom output console log style function

Downloads

4

Readme

CustomConsole

CustomConsole replicates the functionality of console.log's stringification (and then some) for a custom output method. Useful if you're wanting to output the console to a ui element for say, a game engine. It supports both JavaScript and TypeScript.

Installation

From your command line call npm install @vandie/customconsole or yarn install @vandie/customconsole

Usage

For basic usage it's as simple as creating a new logger and using it as you would console.log.

Creating a logger

To create a logger, call the customLog function with your callback function passed.

import { customLog } from 'customconsole';

// Our callback should take a single string value
const someCallback = (text: string) => { /** output string **/ }
const logger = customLog(someCallback);

Using your logger.

Use your logger exactly as you would console.log. It takes an unlimited number of arguments with any types you want. eg.

logger("Pass any data types you want", { vip: true }, 3);

Advanced Usage

customLog does allow a second argument of type LogOptions. LogOptions is entirely optional, and all fields within it are such as well. LogOptions supports the following attributes:

LogOptions

| Attribute | type | Effect | | ---------------- | ----------- |--------| | includeTimestamp | Boolean | Starts each log with a js ms datestamp. eg. "1434319925275: Example Log"| | stringifyObjects | Boolean | If true, objects and arrays will be displayed using JSON.stringify rather than as [object Object] | | separator | String | As with console.log each argument passed to your logger will be split with a new line character (\n). This argument allows you to replace that character with anything you see fit. | | customParsers | A key value store, where the keys are variable types (as returned by typeof) and the values is a parser function that you wish to call for this type | Allows you to define custom parsers for the logger to use | | customTypeChecker | (variable: any) => string | Sets the function to use, to get the string type of a variable eg. "string" or "number". If not set, will internally use typeof. This allows you to add support for custom typescript types. |

console.log replacement

Generally speaking you don't want to replace console.log as modifying prototypes is frowned upon. However, if you are attempting to have console.log calls output to a ui element from code you otherwise cannot modify (eg. a module from a third party), you can call

const inbuiltLogger = console.log;
console.log = customLog(someCallback);