Skip to content

analyze()

The semantic core of dumpkit. The analyze() function traverses any value at runtime and builds a rich, format-agnostic analysis tree – not a string, but a data structure that represents the internal shape of the value.

This tree can be used programmatically to understand data structure, detect circular or shared references, and serve as the foundation for different visualizations (flat, tree, table).


Syntax

ts
analyze(value: unknown, options?: AnalyzeOptions): AnalysisNode

Parameters

ParameterTypeDescription
valueunknownThe value to analyze
optionsAnalyzeOptionsConfiguration options (depth, limits, etc.)

Options

OptionTypeDefaultDescription
depthnumber30Maximum analysis depth
maxArrayLengthnumber1000Maximum number of array items analyzed
maxStringLengthnumber5000Maximum string length
maxPropertiesnumber200Maximum number of object properties
showHiddenbooleanfalseInclude non-enumerable properties and symbols

Return value – AnalysisNode

AnalysisNode is a node in a tree that semantically describes the value. Each node has a type property, which can be:

TypeDescription
primitivePrimitive values (string, number, boolean, null, undefined, bigint, symbol)
objectObjects (with className, properties and truncated flag)
arrayArrays (with length, items and truncated)
mapMap (with size, entries and truncated)
setSet (with size, values and truncated)
dateDate (with isValid and ISO value)
errorError (with name and message)
regexpRegExp (with source and flags)
functionFunction (with name)
typedarrayTypedArray (with className, items and truncated)
weakmapWeakMap (type only)
weaksetWeakSet (type only)
promisePromise (type only)
circularCircular reference detected
sharedShared object (referenced multiple times)

Examples

Programmatic analysis

js
import { analyze } from 'dumpkit';

const user = {
  name: 'John',
  age: 30,
  tags: ['admin', 'user']
};

const analysis = analyze(user);
console.log(analysis.type);                // 'object'
console.log(analysis.properties.length);   // 3
console.log(analysis.properties[0].key);   // 'name'

Circular reference detection

js
const circular = {};
circular.self = circular;

const analysis = analyze(circular);
// analysis.properties[0].value.type === 'circular'
// analysis.properties[0].value.refId === 1

Depth limiting

js
const deep = { a: { b: { c: 'value' } } };
const shallow = analyze(deep, { depth: 1 });
// shallow.properties[0].value.type === 'object' (not expanded)

Shared object

js
const shared = { x: 1 };
const data = { a: shared, b: shared };

const analysis = analyze(data);
// analysis.properties[0].value.type === 'object'
// analysis.properties[1].value.type === 'shared'
// analysis.properties[1].value.refId === 1

Why use analyze()?

  • Structural understanding – programmatically obtain the structure of any value
  • Extensibility – build your own visualizers on top of the analysis
  • Performance – analysis decoupled from formatting (can be cached)
  • Advanced detection – identify circular and shared references

See also

  • inspect() – formats values to string using different views
  • dump() – prints values with flat, tree and table support

MIT License