From 1bd270ce996267740d5ca0c97abdd4ff01d6a64b Mon Sep 17 00:00:00 2001 From: Luke Peavey <8286271+lukePeavey@users.noreply.github.com> Date: Sun, 22 Oct 2023 06:35:43 -0400 Subject: [PATCH] add static method to clear all data (#66) --- lib/Data.js | 9 +++++++++ lib/SplitType.js | 7 +++++++ lib/index.d.ts | 10 ++++++++++ 3 files changed, 26 insertions(+) diff --git a/lib/Data.js b/lib/Data.js index 0e58323..eda630e 100644 --- a/lib/Data.js +++ b/lib/Data.js @@ -66,6 +66,15 @@ export function remove(element) { } } +/** + * Clear all cached data + */ +export function clear() { + Object.keys(cache).forEach((key) => { + delete cache[key] + }) +} + /** * Remove all temporary data from the store. */ diff --git a/lib/SplitType.js b/lib/SplitType.js index 8e403cb..e2a9bc7 100644 --- a/lib/SplitType.js +++ b/lib/SplitType.js @@ -18,6 +18,13 @@ export default class SplitType { return data.cache } + /** + * CLears all data + */ + static clearData() { + data.clear() + } + /** * The default settings for all splitType instances * @static diff --git a/lib/index.d.ts b/lib/index.d.ts index 3d68c63..c6a7d8c 100644 --- a/lib/index.d.ts +++ b/lib/index.d.ts @@ -47,6 +47,16 @@ declare module 'split-type' { */ chars: HTMLElement[] | null + /** + * Returns the data store object. This is mainly for debugging purposes. + * + */ + static data: any + + /** + * Removes all data from the cache. + */ + static clearData (): void /** * Get the default settings for all SplitType calls, or set new ones. *