unist-util-inspect
Advanced tools
Comparing version 6.0.0 to 6.0.1
158
index.js
@@ -7,6 +7,4 @@ 'use strict' | ||
inspect.color = inspect | ||
noColor.color = inspect | ||
inspect.noColor = noColor | ||
noColor.noColor = noColor | ||
inspect.color = noColor.color = inspect | ||
inspect.noColor = noColor.noColor = noColor | ||
@@ -18,32 +16,19 @@ var bold = ansiColor(1, 22) | ||
// Define ANSII color removal functionality. | ||
// ANSI color regex. | ||
var colorExpression = /(?:(?:\u001B\[)|\u009B)(?:\d{1,3})?(?:(?:;\d{0,3})*)?[A-M|f-m]|\u001B[A-M]/g | ||
// Standard keys defined by unist (<https://github.com/syntax-tree/unist>) that | ||
// we format differently. | ||
// We donβt ignore `data` though. | ||
// Also includes `name` (from xast) and `tagName` (from `hast`). | ||
var ignore = ['type', 'value', 'children', 'position'] | ||
var ignoreString = ['name', 'tagName'] | ||
var dataOnly = ['data', 'attributes', 'properties'] | ||
// Inspects a node, without using color. | ||
function noColor(node) { | ||
return stripColor(inspect(node)) | ||
return inspect(node).replace(colorExpression, '') | ||
} | ||
// Inspects a node. | ||
function inspect(node, options) { | ||
var settings = options || {} | ||
var showPositions = settings.showPositions | ||
function inspect(tree, options) { | ||
var positions = | ||
!options || options.showPositions == null ? true : options.showPositions | ||
if (showPositions === null || showPositions === undefined) { | ||
showPositions = true | ||
} | ||
return inspectValue(tree) | ||
return inspectValue(node) | ||
function inspectValue(node) { | ||
if (node && Boolean(node.length) && typeof node === 'object') { | ||
if (node && typeof node === 'object' && 'length' in node) { | ||
return inspectNodes(node) | ||
@@ -64,19 +49,15 @@ } | ||
function inspectNodes(nodes) { | ||
var length = nodes.length | ||
var result = [] | ||
var index = -1 | ||
var result = [] | ||
var node | ||
var tail | ||
var value | ||
while (++index < length) { | ||
node = nodes[index] | ||
tail = index === length - 1 | ||
value = | ||
dim((tail ? 'β' : 'β') + 'β' + index) + | ||
' ' + | ||
indent(inspectValue(node), (tail ? ' ' : dim('β')) + ' ', true) | ||
result.push(value) | ||
while (++index < nodes.length) { | ||
result.push( | ||
dim((index < nodes.length - 1 ? 'β' : 'β') + 'β' + index) + | ||
' ' + | ||
indent( | ||
inspectValue(nodes[index]), | ||
(index < nodes.length - 1 ? dim('β') : ' ') + ' ', | ||
true | ||
) | ||
) | ||
} | ||
@@ -88,3 +69,2 @@ | ||
function inspectFields(object) { | ||
var nonEmpty = object.children && object.children.length | ||
var result = [] | ||
@@ -100,4 +80,10 @@ var key | ||
value === undefined || | ||
ignore.indexOf(key) !== -1 || | ||
(ignoreString.indexOf(key) !== -1 && typeof value === 'string') | ||
// Standard keys defined by unist that we format differently. | ||
// <https://github.com/syntax-tree/unist> | ||
key === 'type' || | ||
key === 'value' || | ||
key === 'children' || | ||
key === 'position' || | ||
// Ignore `name` (from xast) and `tagName` (from `hast`) when string. | ||
(typeof value === 'string' && (key === 'name' || key === 'tagName')) | ||
) { | ||
@@ -107,14 +93,20 @@ continue | ||
// A single node. | ||
if ( | ||
value && | ||
typeof value === 'object' && | ||
typeof value.type === 'string' && | ||
dataOnly.indexOf(key) === -1 | ||
value.type && | ||
key !== 'data' && | ||
key !== 'attributes' && | ||
key !== 'properties' | ||
) { | ||
formatted = inspectTree(value) | ||
} else if ( | ||
Array.isArray(value) && | ||
} | ||
// A list of nodes. | ||
else if ( | ||
value && | ||
typeof value === 'object' && | ||
'length' in value && | ||
value[0] && | ||
typeof value[0] === 'object' && | ||
typeof value[0].type === 'string' | ||
value[0].type | ||
) { | ||
@@ -131,3 +123,6 @@ formatted = '\n' + inspectNodes(value) | ||
return indent(result.join('\n'), (nonEmpty ? dim('β') : ' ') + ' ') | ||
return indent( | ||
result.join('\n'), | ||
(object.children && object.children.length ? dim('β') : ' ') + ' ' | ||
) | ||
} | ||
@@ -148,6 +143,3 @@ | ||
var kind = node.tagName || node.name | ||
var position = node.position || {} | ||
var location = showPositions | ||
? stringifyPosition(position.start, position.end) | ||
: '' | ||
var position = positions ? stringifyPosition(node.position) : '' | ||
@@ -164,4 +156,4 @@ if (typeof kind === 'string') { | ||
if (location) { | ||
result.push(' ', dim('('), location, dim(')')) | ||
if (position) { | ||
result.push(' ', dim('('), position, dim(')')) | ||
} | ||
@@ -176,7 +168,6 @@ | ||
var index = ignoreFirst ? 0 : -1 | ||
var length = lines.length | ||
if (value === '') return '' | ||
if (!value) return value | ||
while (++index < length) { | ||
while (++index < lines.length) { | ||
lines[index] = indentation + lines[index] | ||
@@ -189,3 +180,4 @@ } | ||
// Compile a position. | ||
function stringifyPosition(start, end) { | ||
function stringifyPosition(value) { | ||
var position = value || {} | ||
var result = [] | ||
@@ -195,24 +187,16 @@ var positions = [] | ||
add(start) | ||
add(end) | ||
point(position.start) | ||
point(position.end) | ||
if (positions.length !== 0) { | ||
result.push(positions.join('-')) | ||
} | ||
if (positions.length) result.push(positions.join('-')) | ||
if (offsets.length) result.push(offsets.join('-')) | ||
if (offsets.length !== 0) { | ||
result.push(offsets.join('-')) | ||
} | ||
return result.join(', ') | ||
// Add a position. | ||
function add(position) { | ||
var tuple = stringifyPoint(position) | ||
function point(value) { | ||
if (value) { | ||
positions.push((value.line || 1) + ':' + (value.column || 1)) | ||
if (tuple) { | ||
positions.push(tuple[0]) | ||
if (tuple[1]) { | ||
offsets.push(tuple[1]) | ||
if ('offset' in value) { | ||
offsets.push(String(value.offset || 0)) | ||
} | ||
@@ -223,24 +207,2 @@ } | ||
// Compile a point. | ||
function stringifyPoint(value) { | ||
var result = [] | ||
if (!value) { | ||
return null | ||
} | ||
result = [[value.line || 1, value.column || 1].join(':')] | ||
if ('offset' in value) { | ||
result.push(String(value.offset || 0)) | ||
} | ||
return result | ||
} | ||
// Remove ANSI color from `value`. | ||
function stripColor(value) { | ||
return value.replace(colorExpression, '') | ||
} | ||
// Factory to wrap values in ANSI colours. | ||
@@ -247,0 +209,0 @@ function ansiColor(open, close) { |
{ | ||
"name": "unist-util-inspect", | ||
"version": "6.0.0", | ||
"version": "6.0.1", | ||
"description": "unist utility to inspect nodes", | ||
@@ -41,22 +41,22 @@ "license": "MIT", | ||
"devDependencies": { | ||
"@types/unist": "^2.0.3", | ||
"browserify": "^16.0.0", | ||
"@types/unist": "^2.0.0", | ||
"browserify": "^17.0.0", | ||
"chalk": "^4.0.0", | ||
"dtslint": "^3.0.0", | ||
"hastscript": "^5.0.0", | ||
"dtslint": "^4.0.0", | ||
"hastscript": "^6.0.0", | ||
"nyc": "^15.0.0", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^8.0.0", | ||
"remark-preset-wooorm": "^7.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"retext": "^7.0.0", | ||
"strip-ansi": "^6.0.0", | ||
"tape": "^5.0.0", | ||
"tinyify": "^2.0.0", | ||
"tinyify": "^3.0.0", | ||
"unist-builder": "^2.0.0", | ||
"xastscript": "^1.0.0", | ||
"xastscript": "^2.0.0", | ||
"xast-util-from-xml": "^1.0.0", | ||
"xo": "^0.29.0" | ||
"xo": "^0.34.0" | ||
}, | ||
"scripts": { | ||
"format": "remark . -qfo && prettier --write \"**/*.{js,ts}\" && xo --fix", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"build-bundle": "browserify . -s unistUtilInspect > unist-util-inspect.js", | ||
@@ -82,6 +82,17 @@ "build-mangle": "browserify . -s unistUtilInspect -p tinyify > unist-util-inspect.min.js", | ||
"rules": { | ||
"complexity": "off", | ||
"eqeqeq": [ | ||
"error", | ||
"always", | ||
{ | ||
"null": "ignore" | ||
} | ||
], | ||
"guard-for-in": "off", | ||
"no-control-regex": "off", | ||
"no-eq-null": "off", | ||
"no-multi-assign": "off", | ||
"unicorn/explicit-length-check": "off", | ||
"unicorn/prefer-number-properties": "off", | ||
"unicorn/prefer-includes": "off", | ||
"guard-for-in": "off", | ||
"no-control-regex": "off" | ||
"unicorn/prefer-includes": "off" | ||
}, | ||
@@ -88,0 +99,0 @@ "ignore": [ |
@@ -113,5 +113,5 @@ # unist-util-inspect | ||
[chat-badge]: https://img.shields.io/badge/chat-spectrum-7b16ff.svg | ||
[chat-badge]: https://img.shields.io/badge/chat-discussions-success.svg | ||
[chat]: https://spectrum.chat/unified/syntax-tree | ||
[chat]: https://github.com/syntax-tree/unist/discussions | ||
@@ -128,6 +128,6 @@ [unist]: https://github.com/syntax-tree/unist | ||
[contributing]: https://github.com/syntax-tree/.github/blob/master/contributing.md | ||
[contributing]: https://github.com/syntax-tree/.github/blob/HEAD/contributing.md | ||
[support]: https://github.com/syntax-tree/.github/blob/master/support.md | ||
[support]: https://github.com/syntax-tree/.github/blob/HEAD/support.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/master/code-of-conduct.md | ||
[coc]: https://github.com/syntax-tree/.github/blob/HEAD/code-of-conduct.md |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
0
12812
205