Examples
Basics
Section titled “Basics”Inspect works well for basic object and array-values aka “JSON”.
Actual JSON strings can be parsed by setting the parseJson option.
Promises
Section titled “Promises”The state and eventual result of promises are displayed.
<script> import Inspect from 'svelte-inspect-value'
const promises = { neverResolve: new Promise(() => {}), resolveInAFew: new Promise((resolve) => { setTimeout(() => { resolve('yep') }, 2000) }), rejectsInAFew: new Promise((_, reject) => { setTimeout(() => { reject('nope') }, 3500) }), }</script>
<Inspect values={promises} />Stores
Section titled “Stores”Objects with a subscribe function are recognized as stores or rxjs observables. The
stores will be subscribed to and the latest emitted value will be displayed.
If the store does not return a valid unsubscriber or the subscribe-function throws an error the store will be displayed as a regular object using the default object-view.
This can be enabled / disabled with the stores option.
Classes
Section titled “Classes”Display “static” properties of classes.
Functions
Section titled “Functions”Function bodies are highlighted with hljs.
HTML Elements
Section titled “HTML Elements”- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
- 0
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
- 90
- 91
- 92
- 93
- 94
- 95
- 96
- 97
- 98
- 99
Getters and Setters
Section titled “Getters and Setters”Getters and setters render as interactive nodes as to avoid executing potential side effects until they are manually called.
Setters can be called with valid JSON input.
<script lang="ts"> import Inspect from 'svelte-inspect-value'
let value = $state({ value: 10, multiplier: 4.2, get current() { return this.value }, set current(value) { if (typeof value !== 'number') throw 'not a number' this.value = value }, get double() { return this.value * 2 }, set currentMultiplier(value: number) { this.multiplier = value }, get multiplied() { return this.value * this.multiplier }, })</script>
<Inspect {value} name="gettersAndSetters" />Iterators and Generators
Section titled “Iterators and Generators”Iterators have to be iterated manually since doing so directly affects the source iterator.
<script> import Inspect from 'svelte-inspect-value';
function* fibonacci() { let current = 1; let next = 1; while (true) { yield current; [current, next] = [next, current + next]; } }
let iterators = { fibonacci: fibonacci(), array: [1, 2, 3, 4].values(), set: new Set([12, 34, 45]).values(), map: new Map([ [0, 0], [{ id: 123 }, 1], [[1, 2, 3], 2], ]).entries(), stringIterator: 'abdcdefghijklmnopqrstuvwxyz'[Symbol.iterator](), };</script>
<Inspect values={iterators} />Media Embeds and Link Strings
Section titled “Media Embeds and Link Strings”If a string looks like a URL or path, it will result in a clickable link.
If a URL-like string ends with an image or sound extension, Inspect will embed the media in the string node’s expandable view. This is disabled by default. Enable by setting the embedMedia option.
Sprite and audio courtesy of pokeapi.co
Other types with specialized views includes Error, Date, RegExp, Map and Set.
Default behaviour for any value not recognized by the component is to find the constructor name and list any enumerable values.