|
| 1 | +<template> |
| 2 | + <section id="api"> |
| 3 | + <h2 class="text-2xl font-bold text-white mb-6">API Reference</h2> |
| 4 | + |
| 5 | + <div class="space-y-8"> |
| 6 | + <!-- Constructor --> |
| 7 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 8 | + <h3 class="text-lg font-semibold text-white mb-2 font-mono"> |
| 9 | + new JsonCursorPath(code, options?) |
| 10 | + </h3> |
| 11 | + <p class="text-slate-400 text-sm mb-3"> |
| 12 | + Create a new parser instance for the given JSON text. |
| 13 | + </p> |
| 14 | + <div class="overflow-x-auto"> |
| 15 | + <table class="w-full text-sm text-left"> |
| 16 | + <thead> |
| 17 | + <tr class="border-b border-slate-700 text-slate-400"> |
| 18 | + <th class="py-2 pr-4">Parameter</th> |
| 19 | + <th class="py-2 pr-4">Type</th> |
| 20 | + <th class="py-2">Description</th> |
| 21 | + </tr> |
| 22 | + </thead> |
| 23 | + <tbody class="text-slate-300"> |
| 24 | + <tr class="border-b border-slate-700/50"> |
| 25 | + <td class="py-2 pr-4 font-mono text-teal-400">code</td> |
| 26 | + <td class="py-2 pr-4 font-mono">string</td> |
| 27 | + <td class="py-2">The JSON text to parse</td> |
| 28 | + </tr> |
| 29 | + <tr> |
| 30 | + <td class="py-2 pr-4 font-mono text-teal-400">options?</td> |
| 31 | + <td class="py-2 pr-4 font-mono">JsonCursorPathOptions</td> |
| 32 | + <td class="py-2">Optional configuration</td> |
| 33 | + </tr> |
| 34 | + </tbody> |
| 35 | + </table> |
| 36 | + </div> |
| 37 | + </div> |
| 38 | + |
| 39 | + <!-- get() --> |
| 40 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 41 | + <h3 class="text-lg font-semibold text-white mb-2 font-mono"> |
| 42 | + .get(cursorPosition, returnRawPath?) |
| 43 | + </h3> |
| 44 | + <p class="text-slate-400 text-sm mb-3"> |
| 45 | + Get the JSONPath at the specified cursor position. Returns <code class="text-teal-400">null</code> if the cursor is outside any JSON value. |
| 46 | + </p> |
| 47 | + <highlightjs language="typescript" :code="getOverloads" /> |
| 48 | + <div class="overflow-x-auto mt-3"> |
| 49 | + <table class="w-full text-sm text-left"> |
| 50 | + <thead> |
| 51 | + <tr class="border-b border-slate-700 text-slate-400"> |
| 52 | + <th class="py-2 pr-4">Parameter</th> |
| 53 | + <th class="py-2 pr-4">Type</th> |
| 54 | + <th class="py-2">Description</th> |
| 55 | + </tr> |
| 56 | + </thead> |
| 57 | + <tbody class="text-slate-300"> |
| 58 | + <tr class="border-b border-slate-700/50"> |
| 59 | + <td class="py-2 pr-4 font-mono text-teal-400">cursorPosition</td> |
| 60 | + <td class="py-2 pr-4 font-mono">number</td> |
| 61 | + <td class="py-2">Zero-based character offset in the JSON text</td> |
| 62 | + </tr> |
| 63 | + <tr> |
| 64 | + <td class="py-2 pr-4 font-mono text-teal-400">returnRawPath?</td> |
| 65 | + <td class="py-2 pr-4 font-mono">boolean</td> |
| 66 | + <td class="py-2"> |
| 67 | + If <code class="text-teal-400">true</code>, returns a <code class="font-mono">PathToCursor</code> array. |
| 68 | + Defaults to <code class="text-teal-400">false</code> (returns a JSONPath string). |
| 69 | + </td> |
| 70 | + </tr> |
| 71 | + </tbody> |
| 72 | + </table> |
| 73 | + </div> |
| 74 | + </div> |
| 75 | + |
| 76 | + <!-- rawPathToString() --> |
| 77 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 78 | + <h3 class="text-lg font-semibold text-white mb-2 font-mono"> |
| 79 | + .rawPathToString(path) |
| 80 | + </h3> |
| 81 | + <p class="text-slate-400 text-sm"> |
| 82 | + Converts a <code class="font-mono">PathToCursor</code> array to a JSONPath string. |
| 83 | + </p> |
| 84 | + </div> |
| 85 | + |
| 86 | + <!-- Types --> |
| 87 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 88 | + <h3 class="text-lg font-semibold text-white mb-2">Types</h3> |
| 89 | + <highlightjs language="typescript" :code="typesCode" /> |
| 90 | + </div> |
| 91 | + |
| 92 | + <!-- Options --> |
| 93 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 94 | + <h3 class="text-lg font-semibold text-white mb-2 font-mono"> |
| 95 | + JsonCursorPathOptions |
| 96 | + </h3> |
| 97 | + <div class="overflow-x-auto"> |
| 98 | + <table class="w-full text-sm text-left"> |
| 99 | + <thead> |
| 100 | + <tr class="border-b border-slate-700 text-slate-400"> |
| 101 | + <th class="py-2 pr-4">Option</th> |
| 102 | + <th class="py-2 pr-4">Type</th> |
| 103 | + <th class="py-2 pr-4">Default</th> |
| 104 | + <th class="py-2">Description</th> |
| 105 | + </tr> |
| 106 | + </thead> |
| 107 | + <tbody class="text-slate-300"> |
| 108 | + <tr> |
| 109 | + <td class="py-2 pr-4 font-mono text-teal-400">specifyStringIndex</td> |
| 110 | + <td class="py-2 pr-4 font-mono">boolean</td> |
| 111 | + <td class="py-2 pr-4 font-mono">false</td> |
| 112 | + <td class="py-2"> |
| 113 | + When enabled, if the cursor is inside a string value, a <code class="font-mono">string</code> path entry is appended with the character index within that string. |
| 114 | + </td> |
| 115 | + </tr> |
| 116 | + </tbody> |
| 117 | + </table> |
| 118 | + </div> |
| 119 | + </div> |
| 120 | + |
| 121 | + <!-- When get() returns null --> |
| 122 | + <div class="bg-slate-800 rounded-lg p-5"> |
| 123 | + <h3 class="text-lg font-semibold text-white mb-2"> |
| 124 | + When does <code class="font-mono text-teal-400">.get()</code> return <code class="font-mono text-teal-400">null</code>? |
| 125 | + </h3> |
| 126 | + <ul class="list-disc list-inside text-slate-400 text-sm space-y-1"> |
| 127 | + <li>Cursor is before the root value (e.g., on leading whitespace)</li> |
| 128 | + <li>Cursor is after the root value (e.g., on trailing whitespace)</li> |
| 129 | + <li>Cursor is between values (e.g., on whitespace between object entries)</li> |
| 130 | + <li>The JSON text is empty</li> |
| 131 | + </ul> |
| 132 | + </div> |
| 133 | + </div> |
| 134 | + </section> |
| 135 | +</template> |
| 136 | + |
| 137 | +<script setup lang="ts"> |
| 138 | +const getOverloads = `// Returns a JSONPath string |
| 139 | +.get(cursorPosition: number): string | null |
| 140 | +
|
| 141 | +// Returns a raw path array |
| 142 | +.get(cursorPosition: number, true): PathToCursor | null`; |
| 143 | +
|
| 144 | +const typesCode = `type PathEntry = |
| 145 | + | { type: 'object'; key: string } |
| 146 | + | { type: 'array'; index: number } |
| 147 | + | { type: 'string'; index: number }; |
| 148 | +
|
| 149 | +type PathToCursor = PathEntry[]; |
| 150 | +
|
| 151 | +type JsonCursorPathOptions = { |
| 152 | + specifyStringIndex: boolean; |
| 153 | +};`; |
| 154 | +</script> |
0 commit comments