first commit
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
{
|
||||
"name": "@ben-to/privacy",
|
||||
"version": "0.1.0",
|
||||
"type": "module",
|
||||
"exports": {
|
||||
"./cookie-consent": "./src/cookie-consent.ts"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
/** Clé localStorage pour le choix cookies / analytics Matomo. */
|
||||
export const COOKIE_CONSENT_STORAGE_KEY = "ben-to-cookie-consent-v1";
|
||||
|
||||
export type StoredAnalyticsConsent = "analytics-accepted" | "analytics-rejected";
|
||||
|
||||
export type ConsentParseResult = "unknown" | StoredAnalyticsConsent;
|
||||
|
||||
export const normalizeConsentRaw = (raw: string | null | undefined): ConsentParseResult => {
|
||||
if (raw === "analytics-accepted") return "analytics-accepted";
|
||||
if (raw === "analytics-rejected") return "analytics-rejected";
|
||||
return "unknown";
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { normalizeConsentRaw } from "./cookie-consent";
|
||||
|
||||
describe("normalizeConsentRaw", () => {
|
||||
it("reconnaît les valeurs stockées", () => {
|
||||
expect(normalizeConsentRaw("analytics-accepted")).toBe("analytics-accepted");
|
||||
expect(normalizeConsentRaw("analytics-rejected")).toBe("analytics-rejected");
|
||||
});
|
||||
|
||||
it("retourne unknown sinon", () => {
|
||||
expect(normalizeConsentRaw(null)).toBe("unknown");
|
||||
expect(normalizeConsentRaw(undefined)).toBe("unknown");
|
||||
expect(normalizeConsentRaw("")).toBe("unknown");
|
||||
expect(normalizeConsentRaw("yes")).toBe("unknown");
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"extends": "../../../tsconfig.base.json",
|
||||
"compilerOptions": {
|
||||
"composite": true
|
||||
},
|
||||
"include": ["src"]
|
||||
}
|
||||
Reference in New Issue
Block a user