diff --git a/desktop/flipper-plugin/src/__tests__/api.node.tsx b/desktop/flipper-plugin/src/__tests__/api.node.tsx index 2cb6c20fc..f255f4b54 100644 --- a/desktop/flipper-plugin/src/__tests__/api.node.tsx +++ b/desktop/flipper-plugin/src/__tests__/api.node.tsx @@ -59,6 +59,7 @@ test('Correct top level API exposed', () => { "path", "produce", "renderReactRoot", + "safeStringify", "sleep", "styled", "textContent", diff --git a/desktop/flipper-plugin/src/index.ts b/desktop/flipper-plugin/src/index.ts index 406c11842..d30e39886 100644 --- a/desktop/flipper-plugin/src/index.ts +++ b/desktop/flipper-plugin/src/index.ts @@ -134,6 +134,7 @@ export {textContent} from './utils/textContent'; import * as path from './utils/path'; export {path}; export * from './utils/uuid'; +export {safeStringify} from './utils/safeStringify'; // It's not ideal that this exists in flipper-plugin sources directly, // but is the least pain for plugin authors. diff --git a/docs/extending/flipper-plugin.mdx b/docs/extending/flipper-plugin.mdx index bafddb32e..6aef69f8d 100644 --- a/docs/extending/flipper-plugin.mdx +++ b/docs/extending/flipper-plugin.mdx @@ -1166,6 +1166,12 @@ Usage: `uuid()` Returns UUID V4. +### safeStringify + +Usage: `safeStringify(dataStructure)` + +Serialises the given data structure using `JSON.stringify`, but doesn't throw if the processes failed, but rather returns a `` string. + ## TestUtils The object `TestUtils` as exposed from `flipper-plugin` exposes utilities to write unit tests for Sandy plugins.