Giter Site home page Giter Site logo

protolog's Introduction

Protolog

Protolog as a global .log method to all variables in JavaScript. It basically monkeypatches console.log into the Object prototype. The idea is to add a simple shorcut to logging by making all variables loggable, like this:

'a'.log()

Protolog In the Browser

The .log method returns the object itself. In this way, you can plug .log statements anywhere in your code without it interfering with the flow of your code.

var a = 5;

5 === a.log() // true
a.log() === a // true

Showing equality in the browser

if (a === 5) {
  doSomething();
}

Is the same as:

if (a.log() === 5) {
  doSomething();
}

Alternatively, you can just require the module and use it as a replacement for console.log:

var log = require('protolog/local')();

log('hello');

Install

If in node, use npm:

npm install protolog

If in the browser, use bower or the CDN:

bower install protolog

Options

name type default
name String 'log'

Change the name of the the method to be used for logging. This will be the name of the property to be appended to the Object prototype.

name type default
appendToPrototype Boolean true

Specify wether the .log method will be appended to the Object prototype and hence be available in all variables. If false, you can require this function and then use the library as a normal function. This will be useful once the library has unique methods that enhance logging.

Is This A Terrible Idea?

Perhaps. But, thankfully, you don't have to use it :).

Monkey-patching is definitely questionable, but the behavior provided by this library is both: very useful and universal. The .log method is nothing more than a thin wrapper over console.log. The method also implemented responsibly, taking inspiration with should.js's implementation.

The Future

In the future, this library will include other features for logging in the console/REPL. The two main features included will be transformations: transforming the data you want to log, and display methods: changing the way in which the data is displayed.

protolog's People

Contributors

thejsj avatar loringdodge avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.