Svelte <Inspect {value} />

Usage & Conditional Rendering

Install svelte-inspect-value with your favorite package manager.

A common use case for a component like this is to only render it during development.
If you are using SvelteKit, you can conditionally render Inspect using the dev variable exported from '$app/environment'.
If you are not using SvelteKit or Vite, esm-env is a good alternative for checking conditional environment variables with different bundlers and runtimes.

example
...
Result:

Global Options

svelte-inspect-value exports a utility function to set a "global" config for every instance of the Inspect-component in or under the component where the function is called (it sets context). Alternatively, you can use InspectOptionsProvider.

Passing a reactive object to the function will update the components if any property of the object is changed beceause its reactive (yup!)
You can try this now if you change any options in the configurator at the bottom of your screen! (hover it)

+layout.svelte
...
Result:
str 'no long strings in t…' 44 chars

Options set with props will override any global options

Props

NameDescriptionDefault
valuerequired. value to inspect. can be any javascript valuen/a
namename of outer value. displayed as keyundefined
OptionsThe following props can be set using setGlobalInspectOptions or InspectOptionsProvider
stringCollapseset a max display length for string values. 0 means full string will be displayed0
showLengthdisplay length of arrays or strings and number of nested entries in objects / maps etctrue
showTypesdisplay type labels before values e.g. "string" / "number." Mainly affects basic primitive typestrue
showPreviewdisplay preview of nested values of object, array, map, set etc.true
previewDepthhow deeply nested items should be previewed before simply showing types1
previewEntrieshow many nested items should be previewed3
showToolsdisplay row of utility-"tools" when hovering an entrytrue
noanimatedisable animations / transitionsfalse
embedMediaembed images and audio if a string value is a path or url that ends with an image or audio file extensionfalse
themeset color theme class
available built-in themes: 'inspect','drak','stereo','dark','light','cotton-candy'
'inspect'
expandAllinitially expand all nodes. can be a performance hitch with a lot of entriesfalse
expandLeveldefault level of initially expanded nested nodes1
expandPathsarray of paths (string) to initially expanded nodes[]
borderlessremove background color, border and paddingfalse
quotesquote type for string values. 'single' or 'double''single'
renderIffunction or value. render condition for Inspect. if value or return value of function is truthy, Inspect will render.true
customComponentscustom components for values.
object with type as keyname and tuple of component and optional prop modification function.
extended documentation here
{}
parseJsonif enabled, attempt to parse strings that start with { or [ and display the parsed value if it was valid JSONfalse
global options