diff options
| author | ST-DDT <[email protected]> | 2024-12-28 04:25:06 +0100 |
|---|---|---|
| committer | GitHub <[email protected]> | 2024-12-28 03:25:06 +0000 |
| commit | e6d27a353ec9c82e60b31c8d833768141beb4dab (patch) | |
| tree | e9b728c03218d458149cb711909034170f61f3fd /docs/.vitepress/components/api-docs/format.ts | |
| parent | 817f8a01d93378e00c03cf73154fcec34fd5feef (diff) | |
| download | faker-e6d27a353ec9c82e60b31c8d833768141beb4dab.tar.xz faker-e6d27a353ec9c82e60b31c8d833768141beb4dab.zip | |
docs(api): add refresh button to examples (#3301)
* docs(api): add refresh button to examples
* chore: improve button behavior slightly
* chore: improve output format
* chore: ignore examples without recordable results
* temp
* chore: use svg button
* chore: use json5 format for test
* chore: simplify result formatting
* test: add formatting tests
* test: add e2e refresh test
* test: use static test values
* chore: fix regex
* chore: simplify refresh placeholder
* Update cypress/e2e/example-refresh.cy.ts
* fix: handle property after function call
* Apply suggestions from code review
Co-authored-by: Shinigami <[email protected]>
* Apply suggestions from code review
Co-authored-by: Shinigami <[email protected]>
* Apply suggestions from code review
Co-authored-by: Shinigami <[email protected]>
* chore: format
* chore: add comment
---------
Co-authored-by: Shinigami <[email protected]>
Diffstat (limited to 'docs/.vitepress/components/api-docs/format.ts')
| -rw-r--r-- | docs/.vitepress/components/api-docs/format.ts | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/docs/.vitepress/components/api-docs/format.ts b/docs/.vitepress/components/api-docs/format.ts new file mode 100644 index 00000000..34de1e0c --- /dev/null +++ b/docs/.vitepress/components/api-docs/format.ts @@ -0,0 +1,14 @@ +export function formatResult(result: unknown): string { + return result === undefined + ? 'undefined' + : typeof result === 'bigint' + ? `${result}n` + : JSON.stringify(result, undefined, 2) + .replaceAll('\\r', '') + .replaceAll('<', '<') + .replaceAll( + /(^ *|: )"([^'\n]*?)"(?=,?$|: )/gm, + (_, p1, p2) => `${p1}'${p2.replace(/\\"/g, '"')}'` + ) + .replaceAll(/\n */g, ' '); +} |
