Skip to content

Commit

Permalink
Initial commit, release 1.0.0.
Browse files Browse the repository at this point in the history
  • Loading branch information
papandreou committed Nov 28, 2014
0 parents commit 6db51e8
Show file tree
Hide file tree
Showing 8 changed files with 321 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
@@ -0,0 +1,2 @@
/node_modules/
/coverage/
2 changes: 2 additions & 0 deletions .jshintignore
@@ -0,0 +1,2 @@
node_modules
coverage
93 changes: 93 additions & 0 deletions .jshintrc
@@ -0,0 +1,93 @@
{
// JSHint Default Configuration File (as on JSHint website)
// See http://jshint.com/docs/ for more details

"maxerr" : 50, // {int} Maximum error before stopping

// Enforcing
"bitwise" : true, // true: Prohibit bitwise operators (&, |, ^, etc.)
"camelcase" : false, // true: Identifiers must be in camelCase
"curly" : true, // true: Require {} for every new block or scope
"eqeqeq" : true, // true: Require triple equals (===) for comparison
"forin" : true, // true: Require filtering for..in loops with obj.hasOwnProperty()
"immed" : true, // true: Require immediate invocations to be wrapped in parens e.g. `(function () { } ());`
"indent" : 4, // {int} Number of spaces to use for indentation
"latedef" : true, // true: Require variables/functions to be defined before being used
"newcap" : true, // true: Require capitalization of all constructor functions e.g. `new F()`
"noarg" : true, // true: Prohibit use of `arguments.caller` and `arguments.callee`
"noempty" : true, // true: Prohibit use of empty blocks
"nonew" : false, // true: Prohibit use of constructors for side-effects (without assignment)
"plusplus" : true, // true: Prohibit use of `++` & `--`
"quotmark" : "single", // Quotation mark consistency:
// false : do nothing (default)
// true : ensure whatever is used is consistent
// "single" : require single quotes
// "double" : require double quotes
"undef" : true, // true: Require all non-global variables to be declared (prevents global leaks)
"unused" : "vars", // true: Require all defined variables be used
"strict" : false, // true: Requires all functions run in ES5 Strict Mode
"trailing" : true, // true: Prohibit trailing whitespaces
"maxparams" : false, // {int} Max number of formal params allowed per function
"maxdepth" : false, // {int} Max depth of nested blocks (within functions)
"maxstatements" : false, // {int} Max number statements per function
"maxcomplexity" : false, // {int} Max cyclomatic complexity per function
"maxlen" : false, // {int} Max number of characters per line

// Relaxing
"asi" : false, // true: Tolerate Automatic Semicolon Insertion (no semicolons)
"boss" : false, // true: Tolerate assignments where comparisons would be expected
"debug" : false, // true: Allow debugger statements e.g. browser breakpoints.
"eqnull" : false, // true: Tolerate use of `== null`
"es5" : false, // true: Allow ES5 syntax (ex: getters and setters)
"esnext" : false, // true: Allow ES.next (ES6) syntax (ex: `const`)
// (ex: `for each`, multiple try/catch, function expression…)
"evil" : false, // true: Tolerate use of `eval` and `new Function()`
"expr" : false, // true: Tolerate `ExpressionStatement` as Programs
"funcscope" : false, // true: Tolerate defining variables inside control statements"
"globalstrict" : false, // true: Allow global "use strict" (also enables 'strict')
"iterator" : false, // true: Tolerate using the `__iterator__` property
"lastsemic" : false, // true: Tolerate omitting a semicolon for the last statement of a 1-line block
"laxbreak" : false, // true: Tolerate possibly unsafe line breakings
"laxcomma" : false, // true: Tolerate comma-first style coding
"loopfunc" : true, // true: Tolerate functions being defined in loops
"multistr" : false, // true: Tolerate multi-line strings
"proto" : false, // true: Tolerate using the `__proto__` property
"scripturl" : false, // true: Tolerate script-targeted URLs
"smarttabs" : false, // true: Tolerate mixed tabs/spaces when used for alignment
"shadow" : false, // true: Allows re-define variables later in code e.g. `var x=1; x=2;`
"sub" : false, // true: Tolerate using `[]` notation when it can still be expressed in dot notation
"supernew" : false, // true: Tolerate `new function () { ... };` and `new Object;`
"validthis" : false, // true: Tolerate using this in a non-constructor function

// Environments
"browser" : false, // Web Browser (window, document, etc)
"couch" : false, // CouchDB
"devel" : true, // Development/debugging (alert, confirm, etc)
"dojo" : false, // Dojo Toolkit
"jquery" : true, // jQuery
"mootools" : false, // MooTools
"node" : true, // Node.js
"nonstandard" : true, // Widely adopted globals (escape, unescape, etc)
"prototypejs" : false, // Prototype and Scriptaculous
"rhino" : false, // Rhino
"worker" : false, // Web Workers
"wsh" : false, // Windows Scripting Host
"yui" : false, // Yahoo User Interface

// Legacy
"nomen" : false, // true: Prohibit dangling `_` in variables
"onevar" : false, // true: Allow only one `var` statement per function
"passfail" : false, // true: Stop on first error
"white" : true, // true: Check against strict whitespace and indentation rules

// Custom Globals
"predef" : [ // additional predefined global variables
"TR",
"TRPAT",
"GETTEXT",
"GETSTATICURL",
"INCLUDE",
"define",
"require"
]
}
5 changes: 5 additions & 0 deletions .travis.yml
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "0.10"
before_install: "npm install -g npm && npm cache clean"
script: "npm run-script travis"
28 changes: 28 additions & 0 deletions README.md
@@ -0,0 +1,28 @@
uninspected
===========

Replacement for util.inspect and the console object.

[![NPM version](https://badge.fury.io/js/messy.png)](http://badge.fury.io/js/uninspected)
[![Build Status](https://travis-ci.org/papandreou/uninspected.png)](https://travis-ci.org/papandreou/uninspected)
[![Coverage Status](https://coveralls.io/repos/papandreou/uninspected/badge.png)](https://coveralls.io/r/papandreou/uninspected)
[![Dependency Status](https://david-dm.org/papandreou/uninspected.png)](https://david-dm.org/papandreou/uninspected)

```javascript
var uninspected = require('uninspected');

var str = uninspected({foo: 'bar'}); // "{ foo: 'bar' }"

uninspected.log('foo', {bar: /hey/});
```

Also includes diffing support:

```javascript
uninspected.diff({foo: 'bar'}, {foo: 'baz'});
{
foo: 'bar' // should be 'baz'
// -bar
// +baz
}
```
71 changes: 71 additions & 0 deletions lib/uninspected.js
@@ -0,0 +1,71 @@
/*global console*/
var unexpected = require('unexpected').clone();

unexpected.output.installPlugin(require('magicpen-prism'));

function uninspected() { // ...
return uninspected.log.apply(uninspected, arguments);
}

uninspected.inspect = function (obj, options) {
if (!options || typeof options !== 'object') {
options = {};
}
var depth = options.depth === null ? Infinity : options.depth || uninspected.defaultDepth;
// We add one because unexpected.inspect includes the first level in the depth, and we want
// to be compatible with require('util').inspect:
return unexpected.inspect(obj, depth + 1).toString(uninspected.outputFormat);
}

uninspected.defaultDepth = 4; // util's default level of 2 is annoyingly low
uninspected.output = unexpected.output;
uninspected.outputFormat = unexpected.outputFormat();

['log', 'info', 'warn', 'error'].forEach(function (methodName) {
uninspected[methodName] = function () { // ...
var output = uninspected.output.clone();
Array.prototype.forEach.call(arguments, function (obj, i) {
if (i > 0) {
output.sp();
}
if (typeof obj === 'string') {
output.text(obj);
} else if (obj && obj.isMagicPen) {
output.append(obj);
} else {
output.append(unexpected.inspect(obj, uninspected.defaultDepth));
}
});
console[methodName](output.toString(uninspected.outputFormat));
};
});

uninspected.dir = uninspected.log;

uninspected.diff = function (a, b) {
var result = unexpected.diff(a, b);
if (result && result.diff) {
uninspected.log(result.diff);
} else {
uninspected.log(a);
}
};

// Support trace, time, timeEnd etc.
Object.keys(console).forEach(function (key) {
if (typeof console[key] === 'function' && !uninspected[key]) {
uninspected[key] = function () { // ...
return console[key].apply(console, arguments);
};
}
});

uninspected.addType = function () { // ...
return unexpected.addType.apply(unexpected, arguments);
};

uninspected.addStyle = function () { // ...
return unexpected.output.addStyle.apply(unexpected.output, arguments);
};

module.exports = uninspected;
44 changes: 44 additions & 0 deletions package.json
@@ -0,0 +1,44 @@
{
"name": "uninspected",
"version": "1.0.0",
"description": "util.inspect replacement based on Unexpected's output and type system",
"main": "index.js",
"dependencies": {
"magicpen-prism": "0.2.0",
"unexpected": "5.0.0-beta22"
},
"devDependencies": {
"coveralls": "2.11.2",
"istanbul": "0.3.2",
"jshint": "2.5.10",
"mocha": "2.0.1",
"sinon": "1.12.1",
"unexpected": "5.0.0-beta22",
"unexpected-sinon": "3.0.2"
},
"scripts": {
"lint": "jshint .",
"test": "mocha && npm run lint",
"travis": "npm test && npm run coverage && <coverage/lcov.info coveralls",
"coverage": "NODE_ENV=development istanbul cover _mocha -- --reporter dot"
},
"repository": {
"type": "git",
"url": "git://github.com/papandreou/uninspected.git"
},
"keywords": [
"util",
"inspect",
"object",
"depth",
"color",
"types"
],
"main": "./lib/uninspected",
"author": "Andreas Lind <andreas@one.com>",
"license": "BSD",
"bugs": {
"url": "https://github.com/papandreou/uninspected/issues"
},
"homepage": "https://github.com/papandreou/uninspected"
}
76 changes: 76 additions & 0 deletions test/uninspected.js
@@ -0,0 +1,76 @@
/*global describe, it, console*/

var uninspected = require('../lib/uninspected'),
unexpected = require('unexpected'),
sinon = require('sinon');

describe('uninspected', function () {
var expect = unexpected.clone().installPlugin(require('unexpected-sinon'));

describe('#inspect', function () {
it('should produce colored output', function () {
expect(uninspected.inspect({foo: 'abc'}), 'to equal', "{ foo: \x1B[36m\x1B[38;5;44m'abc'\x1B[39m }");
});

it('should have a default depth of 4', function () {
expect(uninspected.inspect({foo: {foo: {foo: {foo: {foo: {foo: 123}}}}}}), 'to equal', '{ foo: { foo: { foo: { foo: { foo: ... } } } } }');
});
});

it('should be a shorthand for uninspected.log', function () {
sinon.stub(console, 'log');
uninspected('abc', {foo: true});
expect(console.log, 'was called with', 'abc { foo: true }');
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});

describe('#log', function () {
var originalOutputFormat = uninspected.outputFormat;
beforeEach(function () {
sinon.stub(console, 'log');
});

afterEach(function () {
uninspected.outputFormat = originalOutputFormat;
});

it('should log to the console', function () {
uninspected.log('abc', {foo: true});
expect(console.log, 'was called with', 'abc { foo: true }');
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});

it('should log with colors if told to', function () {
uninspected.outputFormat = 'ansi';
uninspected.log('abc', {foo: 'abc'});
expect(console.log.args[0], 'to equal', ["abc { foo: \x1B[36m\x1B[38;5;44m'abc'\x1B[39m }"]);
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});

it('should log without colors if told to', function () {
uninspected.outputFormat = 'text';
uninspected.log('abc', {foo: 'abc'});
expect(console.log.args[0], 'to equal', ["abc { foo: 'abc' }"]);
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});
});

describe('#diff', function () {
beforeEach(function () {
sinon.stub(console, 'log');
});

it('should log without colors if told to', function () {
uninspected.outputFormat = 'text';
uninspected.diff({foo: 'bar'}, {foo: 'baz'});
expect(console.log, 'was called with',
"{\n" +
" foo: 'bar' // should be 'baz'\n" +
" // -bar\n" +
" // +baz\n" +
"}"
);
console.log.restore(); // Cannot do this in an afterEach as it'll suppress mocha's output
});
});
});

0 comments on commit 6db51e8

Please sign in to comment.