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

dodollar

v1.1.1

Published

Lightweight, methods chaining, extended, well-encapsulated output console.

Downloads

18

Readme

boy

Table of Contents

Docs

Installation

  1. npm
npm i dodollar
  1. yarn
yarn add dodollar
  1. bun
bun add dodollar
// or
bun a dodollar

Basic Usage

Act like console.log.

import $$ from 'dodollar';

$$.log('foo');
//> foo

DoDollar compatible with commonly used several methods:

  1. log
  2. info
  3. debug
  4. warn
  5. error
  6. time
  7. timeLog
  8. timeEnd

Method Chaining

$$.log('foo').warn('baz').error('xyzzy');

Output:

method chaining

Extended Utilities

There are some extended utilities for convenience.

$$.separate().title('Debug point').blankLine().log('foo').separate();

Output: extended utilities

title method

Output a title.

$$.title('Hello DoDollar');

// Output
//> # Hello DoDollar

blankLine method

Output blank lines. accept a number to indicate count of blank line.

start and end methods

Same as console.group() and console.groupEnd() make the multiply output line becomes a group and you can easily collapse it:

$$.start('Start').title('Hello DoDollar').separate().end();

Output:

start and end

fold : integrate start and end

If you just want to print a group output, you need the start(), end(), and middle method log() :

const data = {
  name: 'Jack',
  age: 18,
};

$$.start().log(data).end();

fold 1-1

Equal to $$.start().log(data).end(), fold() help out this weary code then you can quickly create a group output:

$$.fold();

separate

Output one line separator, dash( - ) as separator character and maximum number is 80 by default.

$$.separate().separate('*').separate('_-', 150);

Output:

separate

Lifecycle Hooks

Concept

DoDollar support adding custom lifecycle hooks into one method.

Normal method invoke:

Method invoke with hooks:

You can add three types of hook:

  1. intercept: intercept the method execution and over it if hook function return true.
  2. before: execute hook function before method execution.
  3. after: same as before, execute hook function after method is executed.

before and after didn't effect-side for the method.

Usage

With help of lifecycle hook, you can build custom console output for your page or whole project:

// myDoDollar.ts

import { DoDollar } from 'dodollar';
import dodollar from 'dodollar';

const $$ = new DoDollar({
  beforeLog: () => {
    dodollar.log('before log...');
  },
  afterError: () => {
    dodollar.log('Report error to server...');
  },
  interceptInfo: () => {
    dodollar.log('Intercept execution in production environment.');
    return true;
  },
});

export { $$ };

Don't use $$, the DoDollar instance your just create, in hooks which will cause cyclic invoke.

Deliver custom hooks into DoDollar constructor. Import your custom dodollar:

import { $$ } from './myDodollar';

$$.log('I own beforeLog()')
  .blankLine()
  .error('I own afterError()')
  .blankLine()
  .info("I own interceptInfo() and you can't see me.");

Setting in batch

DoDollar support to setting lifecycle hooks in batch by config batchIntercept, batchBefore, and batchAfter:

Build your custom DoDollar instance:

import { isProduction } from '@/utils.ts';
import { DoDollar } from 'dodollar';
import dodollar from 'dodollar';

const $$ = new DoDollar({
  batchIntercept: {
    batchInterceptHook: () => {
      // Intercept every output when in the production environment.
      if (isProduction() === true) {
        return true;
      }
      return false;
    },
  },
  batchBefore: {
    batchBeforeHook: () => {
      dodollar
        .log('I am monitor every methods before hook execution.')
        .separate();
    },
  },
  batchAfter: {
    batchAfterHook: () => {
      dodollar
        .log('Ok, I finish my monitor after hook execution.')
        .separate('*');
    },
  },
});

export { $$ };

Use it:

const data = {
  name: 'Jack',
  age: 18,
};

$$.fold(data);

fold 1-2

Include and Exclude

By default, batch hook will effect to every methods. With include and exclude, you can specify certain methods:

For example, you can add exclude rule that allow error() methods output when in production environment:

const $$ = new DoDollar({
  batchIntercept: {
    batchInterceptHook: () => {
      if (isProduction() === true) {
        return true;
      }
      return false;
    },
    exclude: ["error"],
  },
});

Road Map

The list below should give some indication of my plans for the next major release, and for the future.

  • [x] Setting hook in batches according to different environment.
  • [x] Add batch hooks user docs.
  • [x] fold : same as $$.start().log().end()
  • [ ] Chinese version docs.
  • [ ] Print complex data structure entirely.

Author

| Pandy | | :-------------------------------------------------------------------------------------------: | | Pandy |

License

MIT © Pandy