From 1dfcf6cf4138372d67cc71d66238159286838a8c Mon Sep 17 00:00:00 2001 From: JDMathew Date: Wed, 28 May 2025 20:08:32 -0700 Subject: [PATCH 1/3] feat allow for partial patten matching with regex support --- .../src/plugins/asyncStorage.ts | 24 ++++++++++++++----- 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/lib/reactotron-react-native/src/plugins/asyncStorage.ts b/lib/reactotron-react-native/src/plugins/asyncStorage.ts index 0a998e205..750351c93 100644 --- a/lib/reactotron-react-native/src/plugins/asyncStorage.ts +++ b/lib/reactotron-react-native/src/plugins/asyncStorage.ts @@ -8,6 +8,18 @@ const PLUGIN_DEFAULTS: AsyncStorageOptions = { ignore: [], } +function shouldIgnore(key, ignore) { + for (const pattern of ignore) { + if (typeof pattern === "string") { + return key.includes(pattern) + } + if (pattern instanceof RegExp) { + return pattern.test(key) + } + } + return false +} + const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronCore) => { // setup configuration const config = Object.assign({}, PLUGIN_DEFAULTS, options || {}) @@ -28,7 +40,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const setItem: AsyncStorageStatic["setItem"] = async (key, value, callback) => { try { - if (ignore.indexOf(key) < 0) { + if (!shouldIgnore(key, ignore)) { sendToReactotron("setItem", { key, value }) } } catch (e) {} @@ -37,7 +49,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const removeItem: AsyncStorageStatic["removeItem"] = async (key, callback) => { try { - if (ignore.indexOf(key) < 0) { + if (!shouldIgnore(key, ignore)) { sendToReactotron("removeItem", { key }) } } catch (e) {} @@ -46,7 +58,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const mergeItem: AsyncStorageStatic["mergeItem"] = async (key, value, callback) => { try { - if (ignore.indexOf(key) < 0) { + if (!shouldIgnore(key, ignore)) { sendToReactotron("mergeItem", { key, value }) } } catch (e) {} @@ -63,7 +75,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const multiSet: AsyncStorageStatic["multiSet"] = async (pairs, callback) => { try { const shippablePairs = (pairs || []).filter( - (pair) => pair && pair[0] && ignore.indexOf(pair[0]) < 0 + (pair) => pair && pair[0] && !shouldIgnore(pair[0], ignore) ) if (shippablePairs.length > 0) { sendToReactotron("multiSet", { pairs: shippablePairs }) @@ -74,7 +86,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const multiRemove: AsyncStorageStatic["multiRemove"] = async (keys, callback) => { try { - const shippableKeys = (keys || []).filter((key) => ignore.indexOf(key) < 0) + const shippableKeys = (keys || []).filter((key) => !shouldIgnore(key, ignore)) if (shippableKeys.length > 0) { sendToReactotron("multiRemove", { keys: shippableKeys }) } @@ -85,7 +97,7 @@ const asyncStorage = (options?: AsyncStorageOptions) => (reactotron: ReactotronC const multiMerge: AsyncStorageStatic["multiMerge"] = async (pairs, callback) => { try { const shippablePairs = (pairs || []).filter( - (pair) => pair && pair[0] && ignore.indexOf(pair[0]) < 0 + (pair) => pair && pair[0] && !shouldIgnore(pair[0], ignore) ) if (shippablePairs.length > 0) { sendToReactotron("multiMerge", { pairs: shippablePairs }) From 49a9bd0cab8f5a88f695ad8b7d2c607d169b6674 Mon Sep 17 00:00:00 2001 From: JDMathew Date: Wed, 28 May 2025 20:42:21 -0700 Subject: [PATCH 2/3] Updated docs --- docs/plugins/async-storage.md | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/docs/plugins/async-storage.md b/docs/plugins/async-storage.md index 43fe304d4..49aac214a 100644 --- a/docs/plugins/async-storage.md +++ b/docs/plugins/async-storage.md @@ -26,10 +26,12 @@ And you're done! Now you can see your AsyncStorage in Reactotron. ## Advanced Usage -`asyncStorage()` also accepts an object with an `ignore` key. The value is an array of strings you would like to prevent sending to Reactotron. +`asyncStorage()` also accepts an object with an `ignore` key to filter against. The value of `ignore` is an array of string or RegExp patterns that match against AsyncStorage keys you want to prevent from being sent to Reactotron. + +> String patterns match any key containing that text, while RegExp patterns use standard regex matching. ```js asyncStorage({ - ignore: ["secret"], + ignore: ["secret", /^debug_/, "temp"], }) ``` From 7cc7fd2608db0d3854bf53dc74ada0f980b09854 Mon Sep 17 00:00:00 2001 From: JDMathew Date: Wed, 28 May 2025 21:01:06 -0700 Subject: [PATCH 3/3] feat(asyncStorage): update ignore option type to support string and regex patterns --- lib/reactotron-react-native/src/plugins/asyncStorage.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/reactotron-react-native/src/plugins/asyncStorage.ts b/lib/reactotron-react-native/src/plugins/asyncStorage.ts index 750351c93..0369dc197 100644 --- a/lib/reactotron-react-native/src/plugins/asyncStorage.ts +++ b/lib/reactotron-react-native/src/plugins/asyncStorage.ts @@ -1,7 +1,7 @@ import type { ReactotronCore, Plugin } from "reactotron-core-client" import type { AsyncStorageStatic } from "@react-native-async-storage/async-storage" export interface AsyncStorageOptions { - ignore?: string[] + ignore?: (string | RegExp)[] } const PLUGIN_DEFAULTS: AsyncStorageOptions = {