diff --git a/index.js b/index.js index 2f6b1e9..c6c97f3 100644 --- a/index.js +++ b/index.js @@ -27,7 +27,14 @@ function noColor(node) { } // Inspects a node. -function inspect(node) { +function inspect(node, options) { + var settings = options || {} + var showPositions = settings.showPositions + + if (showPositions === null || showPositions === undefined) { + showPositions = true + } + return inspectValue(node, '') function inspectValue(node, pad) { @@ -82,7 +89,9 @@ function inspect(node) { function formatNode(node) { var result = [node.type] var position = node.position || {} - var location = stringifyPosition(position.start, position.end) + var location = showPositions + ? stringifyPosition(position.start, position.end) + : '' var attributes = [] var key var value diff --git a/package.json b/package.json index bcac2f0..046189b 100644 --- a/package.json +++ b/package.json @@ -61,8 +61,8 @@ "build": "npm run build-bundle && npm run build-mangle", "test-api": "node test", "test-coverage": "nyc --reporter lcov tape test.js", - "test": "npm run format && npm run build && npm run test-coverage", - "dtslint": "dtslint types" + "test-types": "dtslint types", + "test": "npm run format && npm run build && npm run test-coverage && npm run test-types" }, "prettier": { "tabWidth": 2, diff --git a/readme.md b/readme.md index 97162d9..d276b38 100644 --- a/readme.md +++ b/readme.md @@ -49,25 +49,26 @@ root[2] ## API -### `inspect(node)` +### `inspect(node[, options])` -By default, color support is enabled in Node.js and turned off anywhere else. +Inspect the given [`node`][node]. +By default, colors are added in Node, and not in other places. See below on how to change that. -###### Parameters +###### `options.showPositions` -* `node` ([`Node`][node]). +Whether to include positional information (`boolean`, default: `true`). ###### Returns `string` — String representing `node`. -### `inspect.