Skip to content

Commit

Permalink
Create participants.ts
Browse files Browse the repository at this point in the history
  • Loading branch information
akinsola-guardian committed Jan 9, 2025
1 parent 281c7d8 commit 840cb98
Showing 1 changed file with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { isObject } from '../../isObject/isObject';
import { isString } from '../../isString/isString';
import { storage } from '../../storage/storage';

export type Participations = Record<string, { variant: string }>;

const participationsKey = 'gu.ab.participations';
export const getParticipationsFromLocalStorage = (): Participations => {
const participations = storage.local.get(participationsKey);
return isParticipations(participations) ? participations : {};
};

const isParticipations = (
participations: unknown,
): participations is Participations => {
return (
isObject(participations) &&
Object.values(participations).every(
(participation) =>
isObject(participation) && isString(participation.variant),
)
);
};

0 comments on commit 840cb98

Please sign in to comment.