Sha256: d170fe84377ceb90c10b90e06aaadc6211f4aef5c5ad250f811ebdfb768e99b9

Contents?: true

Size: 1.63 KB

Versions: 98

Compression:

Stored size: 1.63 KB

Contents

/*global window, global*/
var util = require("util")
var assert = require("assert")
var now = require("date-now")

var slice = Array.prototype.slice
var console
var times = {}

if (typeof global !== "undefined" && global.console) {
    console = global.console
} else if (typeof window !== "undefined" && window.console) {
    console = window.console
} else {
    console = {}
}

var functions = [
    [log, "log"],
    [info, "info"],
    [warn, "warn"],
    [error, "error"],
    [time, "time"],
    [timeEnd, "timeEnd"],
    [trace, "trace"],
    [dir, "dir"],
    [consoleAssert, "assert"]
]

for (var i = 0; i < functions.length; i++) {
    var tuple = functions[i]
    var f = tuple[0]
    var name = tuple[1]

    if (!console[name]) {
        console[name] = f
    }
}

module.exports = console

function log() {}

function info() {
    console.log.apply(console, arguments)
}

function warn() {
    console.log.apply(console, arguments)
}

function error() {
    console.warn.apply(console, arguments)
}

function time(label) {
    times[label] = now()
}

function timeEnd(label) {
    var time = times[label]
    if (!time) {
        throw new Error("No such label: " + label)
    }

    var duration = now() - time
    console.log(label + ": " + duration + "ms")
}

function trace() {
    var err = new Error()
    err.name = "Trace"
    err.message = util.format.apply(null, arguments)
    console.error(err.stack)
}

function dir(object) {
    console.log(util.inspect(object) + "\n")
}

function consoleAssert(expression) {
    if (!expression) {
        var arr = slice.call(arguments, 1)
        assert.ok(false, util.format.apply(null, arr))
    }
}

Version data entries

98 entries across 98 versions & 14 rubygems

Version Path
smock-0.1.242 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.241 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.240 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.239 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.2 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.1 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.238 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.237 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.236 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.235 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.234 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.233 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.232 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.231 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.230 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.229 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.228 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.227 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.226 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js
smock-0.1.225 node_modules/webpack/node_modules/node-libs-browser/node_modules/console-browserify/index.js