├── .npmignore ├── .gitignore ├── .eslintignore ├── test ├── .eslintrc └── test.js ├── .travis.yml ├── CHANGELOG.md ├── lib ├── inspect.js └── dd.js ├── .eslintrc ├── package.json ├── LICENSE.md └── README.md /.npmignore: -------------------------------------------------------------------------------- 1 | /test 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /node_modules 2 | -------------------------------------------------------------------------------- /.eslintignore: -------------------------------------------------------------------------------- 1 | node_modules/** 2 | -------------------------------------------------------------------------------- /test/.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "env": { 3 | "es6": true, 4 | "mocha": true 5 | } 6 | } 7 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: node_js 2 | node_js: 3 | - '4.2' 4 | sudo: false 5 | 6 | before_script: 7 | - npm install 8 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | All Notable changes to `dump-die` will be documented in this file. 4 | 5 | ## 1.0.0 6 | - Initial release 7 | -------------------------------------------------------------------------------- /lib/inspect.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const util = require('util') 4 | 5 | function inspect(thing) { 6 | return util.inspect(thing, { 7 | showHidden: true, 8 | depth: null, 9 | colors: true 10 | }) 11 | } 12 | 13 | module.exports = inspect 14 | -------------------------------------------------------------------------------- /lib/dd.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const inspect = require('./inspect') 4 | const process = require('process') 5 | 6 | function dd() { 7 | Array.prototype.slice.call(arguments).forEach((thing) => { 8 | console.log(inspect(thing)) 9 | }) 10 | 11 | process.exit(1) 12 | } 13 | 14 | module.exports = dd 15 | -------------------------------------------------------------------------------- /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "rules": { 3 | "indent": [ 4 | 2, 5 | 4 6 | ], 7 | "quotes": [ 8 | 2, 9 | "single" 10 | ], 11 | "linebreak-style": [ 12 | 2, 13 | "unix" 14 | ], 15 | "semi": [ 16 | 2, 17 | "never" 18 | ], 19 | "no-console": 0 20 | }, 21 | "env": { 22 | "es6": true, 23 | "node": true 24 | }, 25 | "extends": "eslint:recommended" 26 | } 27 | -------------------------------------------------------------------------------- /test/test.js: -------------------------------------------------------------------------------- 1 | 'use strict' 2 | 3 | const assert = require('chai').assert 4 | const dd = require('../lib/dd') 5 | const inspect = require('../lib/inspect') 6 | 7 | describe('inspect()', () => { 8 | 9 | it('is a function', () => { 10 | assert.isFunction(inspect) 11 | }) 12 | 13 | it('returns a formatted inspection', () => { 14 | let inspection = inspect({ foo: 'foo' }) 15 | assert.isString(inspection) 16 | assert.include(inspection, 'foo') 17 | }) 18 | }) 19 | 20 | describe('dd()', () => { 21 | it('is a function', () => { 22 | assert.isFunction(dd) 23 | }) 24 | }) 25 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "dump-die", 3 | "version": "1.0.0", 4 | "description": "Dump an object and kill the process in node.js", 5 | "main": "lib/dd.js", 6 | "scripts": { 7 | "test": "eslint . && mocha test" 8 | }, 9 | "engines" : { 10 | "node": ">=4.0.0" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/spatie/dump-die.git" 15 | }, 16 | "keywords": [ 17 | "dump", 18 | "debug", 19 | "console", 20 | "dd", 21 | "laravel" 22 | ], 23 | "author": "Sebastian De Deyne", 24 | "license": "MIT", 25 | "bugs": { 26 | "url": "https://github.com/spatie/dump-die/issues" 27 | }, 28 | "homepage": "https://github.com/spatie/dump-die#readme", 29 | "devDependencies": { 30 | "chai": "^3.3.0", 31 | "eslint": "^7.1.0", 32 | "mocha": "^2.3.3" 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | # The MIT License (MIT) 2 | 3 | Copyright (c) 2015 Sebastian De Deyne 4 | 5 | > Permission is hereby granted, free of charge, to any person obtaining a copy 6 | > of this software and associated documentation files (the "Software"), to deal 7 | > in the Software without restriction, including without limitation the rights 8 | > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | > copies of the Software, and to permit persons to whom the Software is 10 | > furnished to do so, subject to the following conditions: 11 | > 12 | > The above copyright notice and this permission notice shall be included in 13 | > all copies or substantial portions of the Software. 14 | > 15 | > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 21 | > THE SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | 2 | [](https://supportukrainenow.org) 3 | 4 | # dump-die 5 | 6 | [![Latest Version on NPM](https://img.shields.io/npm/v/dump-die.svg?style=flat-square)](https://npmjs.com/package/dump-die) 7 | [![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE.md) 8 | [![Build Status](https://img.shields.io/travis/spatie/dump-die.svg?style=flat-square)](https://travis-ci.org/spatie/dump-die) 9 | 10 | Dump an object and kill the process in node.js for quick debugging. Based on Laravel's [`dd()` function](http://laravel.com/docs/master/helpers#method-dd). 11 | 12 | ## Support us 13 | 14 | [](https://spatie.be/github-ad-click/dump-die) 15 | 16 | We invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us). 17 | 18 | We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards). 19 | 20 | ## Postcardware 21 | 22 | You're free to use this package (it's [MIT-licensed](LICENSE.md)), but if it makes it to your production environment you are required to send us a postcard from your hometown, mentioning which of our package(s) you are using. 23 | 24 | Our address is: Spatie, Kruikstraat 22, 2018 Antwerp, Belgium. 25 | 26 | The best postcards will get published on the open source page on our website. 27 | 28 | ## Installation 29 | 30 | ```bash 31 | npm install dump-die 32 | ``` 33 | 34 | ## Usage 35 | 36 | Calling `dd` will print the object in your terminal and kill the process. 37 | 38 | ```es6 39 | const dd = require('dump-die') 40 | 41 | let myObject = { 42 | foo: 'bar', 43 | baz: function() { 44 | return 'Hi' 45 | } 46 | } 47 | 48 | ``` 49 | 50 | Outputs: 51 | 52 | ``` 53 | { foo: 'bar', 54 | baz: 55 | { [Function] 56 | [length]: 0, 57 | [name]: '', 58 | [prototype]: { [constructor]: [Circular] } } } 59 | ``` 60 | 61 | You can dump any amount of objects. 62 | 63 | ```es6 64 | let foo = 'bar', hodor = { hodor: 'hodor' } 65 | dd(foo, baz, hodor) 66 | ``` 67 | 68 | Outputs: 69 | 70 | ``` 71 | 'bar' 72 | { hodor: 'hodor' } 73 | ``` 74 | 75 | If you don't want to kill the process, you can require the inspect function (which is a simple wrapper around node.js' `util.inspect`) 76 | 77 | ```es6 78 | const inspect = require('dump-die/lib/inspect') 79 | 80 | inspect({ foo: 'bar' }) // => '{ foo: \u001b[32m\'bar\'\u001b[39m }' 81 | ``` 82 | 83 | ## Testing 84 | 85 | You can run the tests (ESLint & Mocha) with: 86 | 87 | ```bash 88 | npm run test 89 | ``` 90 | 91 | ## Contributing 92 | 93 | Please see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details. 94 | 95 | ## Security 96 | 97 | If you discover any security related issues, please email [security@spatie.be](mailto:security@spatie.be) instead of using the issue tracker. 98 | 99 | ## Credits 100 | 101 | - [Sebastian De Deyne](https://github.com/sebastiandedeyne) 102 | - [All Contributors](../../contributors) 103 | 104 | ## About Spatie 105 | 106 | Spatie is a webdesign agency in Antwerp, Belgium. You'll find an overview of all our open source projects [on our website](https://spatie.be/opensource). 107 | 108 | ## License 109 | 110 | The MIT License (MIT). Please see [License File](LICENSE.md) for more information. 111 | --------------------------------------------------------------------------------