cookie-prefs 0.0.0-stage → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,208 @@
1
+ /** Value of the `SameSite` cookie attribute. */
2
+ type CookieSameSite = 'lax' | 'strict' | 'none';
3
+ /**
4
+ * Cookie attributes for pref cookies. Prefs are never `HttpOnly`: the browser must
5
+ * read and write them, so they are visible to any script on the page. Never store
6
+ * secrets or session data in a pref. An option set to `undefined` counts as not set, so
7
+ * the value comes from the level below: an earlier `.options()` call, the `definePrefs()`
8
+ * options, then the default.
9
+ */
10
+ interface CookieOptions {
11
+ /** @default '/' */
12
+ path?: string | undefined;
13
+ /** Omitted by default, which scopes the cookie to the current host. */
14
+ domain?: string | undefined;
15
+ /** Lifetime in seconds. Browsers cap it at 400 days. @default 34560000 (400 days) */
16
+ maxAge?: number | undefined;
17
+ /** @default 'lax' */
18
+ sameSite?: CookieSameSite | undefined;
19
+ /**
20
+ * Send only over HTTPS. When unset, browser writes add `Secure` on `https:` pages
21
+ * and `toCookie()` omits it.
22
+ */
23
+ secure?: boolean | undefined;
24
+ /** CHIPS partitioned cookie. @default false */
25
+ partitioned?: boolean | undefined;
26
+ }
27
+ /** Options for a whole set of prefs, passed to `definePrefs()`. */
28
+ interface PrefsOptions extends CookieOptions {
29
+ /**
30
+ * Prepended to every cookie name. Use it to avoid collisions on a shared domain
31
+ * (`'app.'`) or to opt into a cookie prefix (`'__Host-'`, which also needs
32
+ * `secure: true` and no `domain`).
33
+ * @default ''
34
+ */
35
+ prefix?: string | undefined;
36
+ }
37
+ /** Options for a single pref, passed to `.options()`. They override `PrefsOptions`. */
38
+ interface PrefOptions extends CookieOptions {
39
+ /** Full cookie name for this pref. `prefix` is not applied to it. @default prefix + key */
40
+ name?: string | undefined;
41
+ }
42
+ /**
43
+ * A cookie ready to be set by a server framework. Structurally compatible with
44
+ * Next.js `cookies().set(init)` and `ResponseCookies.set(init)`.
45
+ */
46
+ interface CookieInit {
47
+ /** Cookie name, already URI-encoded (same as `Pref.name`). */
48
+ name: string;
49
+ /**
50
+ * Serialized value, NOT URI-encoded: frameworks encode it on set (Next.js, Express
51
+ * `res.cookie`). When writing a raw `Set-Cookie` header yourself, pass it through
52
+ * `encodeURIComponent`, or cookie-prefs reads it as invalid and falls back to the default.
53
+ */
54
+ value: string;
55
+ path: string;
56
+ maxAge: number;
57
+ sameSite: CookieSameSite;
58
+ domain?: string;
59
+ secure?: boolean;
60
+ partitioned?: boolean;
61
+ }
62
+ /** Anything that can give a cookie value by name. `get` matches Next.js `cookies()` and `request.cookies`. */
63
+ interface CookieGetter {
64
+ get(name: string): {
65
+ readonly value: string;
66
+ } | undefined;
67
+ }
68
+ /**
69
+ * Where to read request cookies from on the server:
70
+ * a `Cookie` header string, a cookie store with `get(name)` (Next.js `cookies()`,
71
+ * `NextRequest.cookies`), or a plain name-to-value map. `null` and `undefined` read
72
+ * as "no cookies", so every pref resolves to its default. A header string is
73
+ * URI-decoded by cookie-prefs; stores and maps must already hold URI-decoded values, as
74
+ * Next.js, Express and `snapshotPrefs()` do. Keys are cookie names (`Pref.name`).
75
+ */
76
+ type CookieSource = string | CookieGetter | Readonly<Record<string, string | undefined>> | null | undefined;
77
+ /**
78
+ * Raw cookie values of a set of prefs, keyed by cookie name (`Pref.name`). Values are
79
+ * URI-decoded, like the values of a cookie store. Serializable, so it can cross the
80
+ * Server Component to Client Component boundary. Holds only the prefs' own cookies,
81
+ * never the rest of the request's cookies.
82
+ */
83
+ type PrefsSnapshot = Readonly<Record<string, string>>;
84
+ /** Where a pref is mirrored on `<html>`: a `data-*` attribute or a CSS custom property. */
85
+ type ReflectTarget = `data-${string}` | `--${string}`;
86
+ /** Phantom type carrier: `T` is what you can write, `V` is what you read back. */
87
+ interface PrefTypes<T, V> {
88
+ readonly value: T;
89
+ readonly output: V;
90
+ }
91
+ /**
92
+ * An unbound pref definition, created by `pref.*`. Builders are immutable: every
93
+ * method returns a new builder. Pass builders to `definePrefs()` to get handles.
94
+ * `T` is the writable type, `V` the read type, `O` the parsed value type that
95
+ * `.default()` takes. `O` differs from `T` only for `pref.json()` with a transforming
96
+ * schema, which is written with the schema's input and read as its output.
97
+ */
98
+ interface PrefBuilder<T, V = T | undefined, O = T> {
99
+ /** Type-only marker for inference. Never set at runtime. */
100
+ readonly '~types'?: PrefTypes<T, V>;
101
+ /** Value used when the cookie is missing or invalid. Removes `undefined` from the read type. */
102
+ default(value: O): PrefBuilder<T, O, O>;
103
+ /** Cookie name and attributes for this pref. */
104
+ options(options: PrefOptions): PrefBuilder<T, V, O>;
105
+ }
106
+ /** Builder for `boolean`, `number` and `string` prefs, which can be mirrored on `<html>`. */
107
+ interface ScalarPrefBuilder<T extends string | number | boolean, V = T | undefined> extends PrefBuilder<T, V> {
108
+ default(value: T): ScalarPrefBuilder<T, T>;
109
+ options(options: PrefOptions): ScalarPrefBuilder<T, V>;
110
+ /**
111
+ * Mirror the value on `<html>` before first paint (inline script) and after every
112
+ * change. A missing cookie with no default removes the attribute. Changes from other
113
+ * tabs show up at once while something in this tab subscribes to the pref
114
+ * (`usePref`), otherwise when the tab becomes visible again (`PrefsProvider`).
115
+ * @example pref.boolean().default(true).reflect('data-sidebar') // <html data-sidebar="true">
116
+ */
117
+ reflect(target: ReflectTarget | readonly ReflectTarget[]): ScalarPrefBuilder<T, V>;
118
+ }
119
+ /** Target accepted by `EnumPrefBuilder.reflect()`. `'class'` swaps one class per value. */
120
+ type EnumReflectTarget = 'class' | ReflectTarget;
121
+ /** Builder for `pref.enum()`. */
122
+ interface EnumPrefBuilder<T extends string, V = T | undefined> extends PrefBuilder<T, V> {
123
+ /** The allowed values, in declaration order. */
124
+ readonly values: readonly T[];
125
+ default(value: T): EnumPrefBuilder<T, T>;
126
+ options(options: PrefOptions): EnumPrefBuilder<T, V>;
127
+ /**
128
+ * Mirror the value on `<html>` before first paint (inline script) and after every
129
+ * change. `'class'` adds the current value as a class and removes the others.
130
+ * `value` maps a pref value to the string written to the DOM. Changes from other
131
+ * tabs show up at once while something in this tab subscribes to the pref
132
+ * (`usePref`), otherwise when the tab becomes visible again (`PrefsProvider`).
133
+ * @example pref.enum(['compact', 'cozy']).default('cozy').reflect('data-density')
134
+ */
135
+ reflect(target: EnumReflectTarget | readonly EnumReflectTarget[], value?: Partial<Record<T, string>>): EnumPrefBuilder<T, V>;
136
+ }
137
+ /** A custom codec for `pref.custom()`. */
138
+ interface PrefCodec<T> {
139
+ /** Raw cookie value (already URI-decoded) to a value. Return `undefined` or throw to fall back to the default. */
140
+ parse(raw: string): T | undefined;
141
+ /** Value to the raw cookie string (URI-encoded by cookie-prefs). */
142
+ serialize(value: T): string;
143
+ }
144
+ /** Writes a pref: a value, or an updater that receives the current value. */
145
+ type PrefSetter<T, V> = (value: T | ((prev: V) => T)) => void;
146
+ /**
147
+ * A bound pref handle, one per key of `definePrefs()`. Usable outside React and
148
+ * passed as-is to `usePref()`. `T` is the writable type, `V` the read type
149
+ * (`T`, or `T | undefined` when there is no default).
150
+ */
151
+ interface Pref<T, V = T> {
152
+ /** Type-only marker for inference. Never set at runtime. */
153
+ readonly '~types'?: PrefTypes<T, V>;
154
+ /** Key in the `definePrefs()` shape. */
155
+ readonly key: string;
156
+ /**
157
+ * Cookie name (prefix + key, or the `name` option), URI-encoded: the exact name in
158
+ * `document.cookie`, the `Cookie` header and `PrefsSnapshot` keys.
159
+ */
160
+ readonly name: string;
161
+ /** Value returned when the cookie is missing or invalid. */
162
+ readonly defaultValue: V;
163
+ /**
164
+ * Current value from `document.cookie`. Returns the default where there is no
165
+ * DOM; on the server use `read()` instead.
166
+ */
167
+ get(): V;
168
+ /** Write the cookie in the browser and notify subscribers in this and other tabs. No-op on the server. */
169
+ set(value: T | ((prev: V) => T)): void;
170
+ /** Delete the cookie, so the value goes back to the default. No-op on the server. */
171
+ reset(): void;
172
+ /** Listen for changes from this tab and other tabs. Returns an unsubscribe function. */
173
+ subscribe(listener: (value: V) => void): () => void;
174
+ /**
175
+ * Read the value from request cookies (stores and maps hold URI-decoded values).
176
+ * Pure; never throws. Cached per raw string, so the same cookie returns the same object.
177
+ */
178
+ read(source: CookieSource): V;
179
+ /**
180
+ * Build the cookie for a server-side write, e.g. `(await cookies()).set(prefs.locale.toCookie('de'))`.
181
+ * `value` is not URI-encoded; frameworks encode it on set, raw `Set-Cookie` writers must.
182
+ */
183
+ toCookie(value: T): CookieInit;
184
+ }
185
+ /** Any bound pref handle. */
186
+ type AnyPref = Pref<unknown, unknown>;
187
+ /** A record of bound handles, as returned by `definePrefs()`. */
188
+ type PrefsRecord = Readonly<Record<string, AnyPref>>;
189
+ /** Any pref builder, as accepted by `definePrefs()`. */
190
+ type AnyPrefBuilder = PrefBuilder<unknown, unknown>;
191
+ /** The shape passed to `definePrefs()`. */
192
+ type PrefShape = Readonly<Record<string, AnyPrefBuilder>>;
193
+ /** Handles produced by `definePrefs()` from a shape. */
194
+ type Prefs<S extends PrefShape> = {
195
+ readonly [K in keyof S]: S[K] extends {
196
+ readonly '~types'?: PrefTypes<infer T, infer V>;
197
+ } ? Pref<T, V> : never;
198
+ };
199
+ /** Read type of a single pref handle or builder. */
200
+ type PrefValue<P extends {
201
+ readonly '~types'?: PrefTypes<unknown, unknown>;
202
+ }> = NonNullable<P['~types']>['output'];
203
+ /** Read types of a record of pref handles: `{ theme: 'light' | 'dark', ... }`. */
204
+ type PrefValues<P extends PrefsRecord> = {
205
+ [K in keyof P]: PrefValue<P[K]>;
206
+ };
207
+
208
+ export type { AnyPref as A, CookieSource as C, EnumPrefBuilder as E, PrefBuilder as P, ReflectTarget as R, ScalarPrefBuilder as S, PrefCodec as a, PrefShape as b, PrefsOptions as c, Prefs as d, PrefsRecord as e, PrefValues as f, PrefsSnapshot as g, AnyPrefBuilder as h, CookieGetter as i, CookieInit as j, CookieOptions as k, CookieSameSite as l, EnumReflectTarget as m, Pref as n, PrefOptions as o, PrefSetter as p, PrefTypes as q, PrefValue as r };
@@ -0,0 +1,208 @@
1
+ /** Value of the `SameSite` cookie attribute. */
2
+ type CookieSameSite = 'lax' | 'strict' | 'none';
3
+ /**
4
+ * Cookie attributes for pref cookies. Prefs are never `HttpOnly`: the browser must
5
+ * read and write them, so they are visible to any script on the page. Never store
6
+ * secrets or session data in a pref. An option set to `undefined` counts as not set, so
7
+ * the value comes from the level below: an earlier `.options()` call, the `definePrefs()`
8
+ * options, then the default.
9
+ */
10
+ interface CookieOptions {
11
+ /** @default '/' */
12
+ path?: string | undefined;
13
+ /** Omitted by default, which scopes the cookie to the current host. */
14
+ domain?: string | undefined;
15
+ /** Lifetime in seconds. Browsers cap it at 400 days. @default 34560000 (400 days) */
16
+ maxAge?: number | undefined;
17
+ /** @default 'lax' */
18
+ sameSite?: CookieSameSite | undefined;
19
+ /**
20
+ * Send only over HTTPS. When unset, browser writes add `Secure` on `https:` pages
21
+ * and `toCookie()` omits it.
22
+ */
23
+ secure?: boolean | undefined;
24
+ /** CHIPS partitioned cookie. @default false */
25
+ partitioned?: boolean | undefined;
26
+ }
27
+ /** Options for a whole set of prefs, passed to `definePrefs()`. */
28
+ interface PrefsOptions extends CookieOptions {
29
+ /**
30
+ * Prepended to every cookie name. Use it to avoid collisions on a shared domain
31
+ * (`'app.'`) or to opt into a cookie prefix (`'__Host-'`, which also needs
32
+ * `secure: true` and no `domain`).
33
+ * @default ''
34
+ */
35
+ prefix?: string | undefined;
36
+ }
37
+ /** Options for a single pref, passed to `.options()`. They override `PrefsOptions`. */
38
+ interface PrefOptions extends CookieOptions {
39
+ /** Full cookie name for this pref. `prefix` is not applied to it. @default prefix + key */
40
+ name?: string | undefined;
41
+ }
42
+ /**
43
+ * A cookie ready to be set by a server framework. Structurally compatible with
44
+ * Next.js `cookies().set(init)` and `ResponseCookies.set(init)`.
45
+ */
46
+ interface CookieInit {
47
+ /** Cookie name, already URI-encoded (same as `Pref.name`). */
48
+ name: string;
49
+ /**
50
+ * Serialized value, NOT URI-encoded: frameworks encode it on set (Next.js, Express
51
+ * `res.cookie`). When writing a raw `Set-Cookie` header yourself, pass it through
52
+ * `encodeURIComponent`, or cookie-prefs reads it as invalid and falls back to the default.
53
+ */
54
+ value: string;
55
+ path: string;
56
+ maxAge: number;
57
+ sameSite: CookieSameSite;
58
+ domain?: string;
59
+ secure?: boolean;
60
+ partitioned?: boolean;
61
+ }
62
+ /** Anything that can give a cookie value by name. `get` matches Next.js `cookies()` and `request.cookies`. */
63
+ interface CookieGetter {
64
+ get(name: string): {
65
+ readonly value: string;
66
+ } | undefined;
67
+ }
68
+ /**
69
+ * Where to read request cookies from on the server:
70
+ * a `Cookie` header string, a cookie store with `get(name)` (Next.js `cookies()`,
71
+ * `NextRequest.cookies`), or a plain name-to-value map. `null` and `undefined` read
72
+ * as "no cookies", so every pref resolves to its default. A header string is
73
+ * URI-decoded by cookie-prefs; stores and maps must already hold URI-decoded values, as
74
+ * Next.js, Express and `snapshotPrefs()` do. Keys are cookie names (`Pref.name`).
75
+ */
76
+ type CookieSource = string | CookieGetter | Readonly<Record<string, string | undefined>> | null | undefined;
77
+ /**
78
+ * Raw cookie values of a set of prefs, keyed by cookie name (`Pref.name`). Values are
79
+ * URI-decoded, like the values of a cookie store. Serializable, so it can cross the
80
+ * Server Component to Client Component boundary. Holds only the prefs' own cookies,
81
+ * never the rest of the request's cookies.
82
+ */
83
+ type PrefsSnapshot = Readonly<Record<string, string>>;
84
+ /** Where a pref is mirrored on `<html>`: a `data-*` attribute or a CSS custom property. */
85
+ type ReflectTarget = `data-${string}` | `--${string}`;
86
+ /** Phantom type carrier: `T` is what you can write, `V` is what you read back. */
87
+ interface PrefTypes<T, V> {
88
+ readonly value: T;
89
+ readonly output: V;
90
+ }
91
+ /**
92
+ * An unbound pref definition, created by `pref.*`. Builders are immutable: every
93
+ * method returns a new builder. Pass builders to `definePrefs()` to get handles.
94
+ * `T` is the writable type, `V` the read type, `O` the parsed value type that
95
+ * `.default()` takes. `O` differs from `T` only for `pref.json()` with a transforming
96
+ * schema, which is written with the schema's input and read as its output.
97
+ */
98
+ interface PrefBuilder<T, V = T | undefined, O = T> {
99
+ /** Type-only marker for inference. Never set at runtime. */
100
+ readonly '~types'?: PrefTypes<T, V>;
101
+ /** Value used when the cookie is missing or invalid. Removes `undefined` from the read type. */
102
+ default(value: O): PrefBuilder<T, O, O>;
103
+ /** Cookie name and attributes for this pref. */
104
+ options(options: PrefOptions): PrefBuilder<T, V, O>;
105
+ }
106
+ /** Builder for `boolean`, `number` and `string` prefs, which can be mirrored on `<html>`. */
107
+ interface ScalarPrefBuilder<T extends string | number | boolean, V = T | undefined> extends PrefBuilder<T, V> {
108
+ default(value: T): ScalarPrefBuilder<T, T>;
109
+ options(options: PrefOptions): ScalarPrefBuilder<T, V>;
110
+ /**
111
+ * Mirror the value on `<html>` before first paint (inline script) and after every
112
+ * change. A missing cookie with no default removes the attribute. Changes from other
113
+ * tabs show up at once while something in this tab subscribes to the pref
114
+ * (`usePref`), otherwise when the tab becomes visible again (`PrefsProvider`).
115
+ * @example pref.boolean().default(true).reflect('data-sidebar') // <html data-sidebar="true">
116
+ */
117
+ reflect(target: ReflectTarget | readonly ReflectTarget[]): ScalarPrefBuilder<T, V>;
118
+ }
119
+ /** Target accepted by `EnumPrefBuilder.reflect()`. `'class'` swaps one class per value. */
120
+ type EnumReflectTarget = 'class' | ReflectTarget;
121
+ /** Builder for `pref.enum()`. */
122
+ interface EnumPrefBuilder<T extends string, V = T | undefined> extends PrefBuilder<T, V> {
123
+ /** The allowed values, in declaration order. */
124
+ readonly values: readonly T[];
125
+ default(value: T): EnumPrefBuilder<T, T>;
126
+ options(options: PrefOptions): EnumPrefBuilder<T, V>;
127
+ /**
128
+ * Mirror the value on `<html>` before first paint (inline script) and after every
129
+ * change. `'class'` adds the current value as a class and removes the others.
130
+ * `value` maps a pref value to the string written to the DOM. Changes from other
131
+ * tabs show up at once while something in this tab subscribes to the pref
132
+ * (`usePref`), otherwise when the tab becomes visible again (`PrefsProvider`).
133
+ * @example pref.enum(['compact', 'cozy']).default('cozy').reflect('data-density')
134
+ */
135
+ reflect(target: EnumReflectTarget | readonly EnumReflectTarget[], value?: Partial<Record<T, string>>): EnumPrefBuilder<T, V>;
136
+ }
137
+ /** A custom codec for `pref.custom()`. */
138
+ interface PrefCodec<T> {
139
+ /** Raw cookie value (already URI-decoded) to a value. Return `undefined` or throw to fall back to the default. */
140
+ parse(raw: string): T | undefined;
141
+ /** Value to the raw cookie string (URI-encoded by cookie-prefs). */
142
+ serialize(value: T): string;
143
+ }
144
+ /** Writes a pref: a value, or an updater that receives the current value. */
145
+ type PrefSetter<T, V> = (value: T | ((prev: V) => T)) => void;
146
+ /**
147
+ * A bound pref handle, one per key of `definePrefs()`. Usable outside React and
148
+ * passed as-is to `usePref()`. `T` is the writable type, `V` the read type
149
+ * (`T`, or `T | undefined` when there is no default).
150
+ */
151
+ interface Pref<T, V = T> {
152
+ /** Type-only marker for inference. Never set at runtime. */
153
+ readonly '~types'?: PrefTypes<T, V>;
154
+ /** Key in the `definePrefs()` shape. */
155
+ readonly key: string;
156
+ /**
157
+ * Cookie name (prefix + key, or the `name` option), URI-encoded: the exact name in
158
+ * `document.cookie`, the `Cookie` header and `PrefsSnapshot` keys.
159
+ */
160
+ readonly name: string;
161
+ /** Value returned when the cookie is missing or invalid. */
162
+ readonly defaultValue: V;
163
+ /**
164
+ * Current value from `document.cookie`. Returns the default where there is no
165
+ * DOM; on the server use `read()` instead.
166
+ */
167
+ get(): V;
168
+ /** Write the cookie in the browser and notify subscribers in this and other tabs. No-op on the server. */
169
+ set(value: T | ((prev: V) => T)): void;
170
+ /** Delete the cookie, so the value goes back to the default. No-op on the server. */
171
+ reset(): void;
172
+ /** Listen for changes from this tab and other tabs. Returns an unsubscribe function. */
173
+ subscribe(listener: (value: V) => void): () => void;
174
+ /**
175
+ * Read the value from request cookies (stores and maps hold URI-decoded values).
176
+ * Pure; never throws. Cached per raw string, so the same cookie returns the same object.
177
+ */
178
+ read(source: CookieSource): V;
179
+ /**
180
+ * Build the cookie for a server-side write, e.g. `(await cookies()).set(prefs.locale.toCookie('de'))`.
181
+ * `value` is not URI-encoded; frameworks encode it on set, raw `Set-Cookie` writers must.
182
+ */
183
+ toCookie(value: T): CookieInit;
184
+ }
185
+ /** Any bound pref handle. */
186
+ type AnyPref = Pref<unknown, unknown>;
187
+ /** A record of bound handles, as returned by `definePrefs()`. */
188
+ type PrefsRecord = Readonly<Record<string, AnyPref>>;
189
+ /** Any pref builder, as accepted by `definePrefs()`. */
190
+ type AnyPrefBuilder = PrefBuilder<unknown, unknown>;
191
+ /** The shape passed to `definePrefs()`. */
192
+ type PrefShape = Readonly<Record<string, AnyPrefBuilder>>;
193
+ /** Handles produced by `definePrefs()` from a shape. */
194
+ type Prefs<S extends PrefShape> = {
195
+ readonly [K in keyof S]: S[K] extends {
196
+ readonly '~types'?: PrefTypes<infer T, infer V>;
197
+ } ? Pref<T, V> : never;
198
+ };
199
+ /** Read type of a single pref handle or builder. */
200
+ type PrefValue<P extends {
201
+ readonly '~types'?: PrefTypes<unknown, unknown>;
202
+ }> = NonNullable<P['~types']>['output'];
203
+ /** Read types of a record of pref handles: `{ theme: 'light' | 'dark', ... }`. */
204
+ type PrefValues<P extends PrefsRecord> = {
205
+ [K in keyof P]: PrefValue<P[K]>;
206
+ };
207
+
208
+ export type { AnyPref as A, CookieSource as C, EnumPrefBuilder as E, PrefBuilder as P, ReflectTarget as R, ScalarPrefBuilder as S, PrefCodec as a, PrefShape as b, PrefsOptions as c, Prefs as d, PrefsRecord as e, PrefValues as f, PrefsSnapshot as g, AnyPrefBuilder as h, CookieGetter as i, CookieInit as j, CookieOptions as k, CookieSameSite as l, EnumReflectTarget as m, Pref as n, PrefOptions as o, PrefSetter as p, PrefTypes as q, PrefValue as r };
package/package.json CHANGED
@@ -1,6 +1,171 @@
1
1
  {
2
2
  "name": "cookie-prefs",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.0",
4
+ "description": "Typed cookie-backed user preference state for React and Next.js",
5
+ "keywords": [
6
+ "react",
7
+ "nextjs",
8
+ "cookies",
9
+ "preferences",
10
+ "theme",
11
+ "next-themes",
12
+ "server-components",
13
+ "typescript"
14
+ ],
15
+ "license": "MIT",
16
+ "author": "Stanislav Kozachenko",
17
+ "homepage": "https://github.com/StanislavKozachenko/cookie-prefs#readme",
18
+ "repository": {
19
+ "type": "git",
20
+ "url": "git+https://github.com/StanislavKozachenko/cookie-prefs.git"
21
+ },
22
+ "bugs": {
23
+ "url": "https://github.com/StanislavKozachenko/cookie-prefs/issues"
24
+ },
25
+ "type": "module",
26
+ "sideEffects": false,
27
+ "main": "./dist/index.cjs",
28
+ "module": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "import": {
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "require": {
37
+ "types": "./dist/index.d.cts",
38
+ "default": "./dist/index.cjs"
39
+ }
40
+ },
41
+ "./react": {
42
+ "import": {
43
+ "types": "./dist/react/index.d.ts",
44
+ "default": "./dist/react/index.js"
45
+ },
46
+ "require": {
47
+ "types": "./dist/react/index.d.cts",
48
+ "default": "./dist/react/index.cjs"
49
+ }
50
+ },
51
+ "./next": {
52
+ "import": {
53
+ "types": "./dist/next/index.d.ts",
54
+ "default": "./dist/next/index.js"
55
+ },
56
+ "require": {
57
+ "types": "./dist/next/index.d.cts",
58
+ "default": "./dist/next/index.cjs"
59
+ }
60
+ },
61
+ "./theme": {
62
+ "import": {
63
+ "types": "./dist/theme/index.d.ts",
64
+ "default": "./dist/theme/index.js"
65
+ },
66
+ "require": {
67
+ "types": "./dist/theme/index.d.cts",
68
+ "default": "./dist/theme/index.cjs"
69
+ }
70
+ },
71
+ "./package.json": "./package.json"
72
+ },
73
+ "typesVersions": {
74
+ "*": {
75
+ "react": [
76
+ "./dist/react/index.d.ts"
77
+ ],
78
+ "next": [
79
+ "./dist/next/index.d.ts"
80
+ ],
81
+ "theme": [
82
+ "./dist/theme/index.d.ts"
83
+ ]
84
+ }
85
+ },
86
+ "files": [
87
+ "dist"
88
+ ],
89
+ "scripts": {
90
+ "build": "tsup",
91
+ "test": "vitest run",
92
+ "typecheck": "tsc --noEmit",
93
+ "lint": "eslint .",
94
+ "size": "size-limit",
95
+ "check:package": "publint && attw --pack .",
96
+ "prepublishOnly": "npm run lint && npm run typecheck && npm run build && npm test && npm run check:package && npm run size"
97
+ },
98
+ "size-limit": [
99
+ {
100
+ "name": "cookie-prefs (core)",
101
+ "path": "dist/index.js",
102
+ "limit": "2 KB",
103
+ "gzip": true
104
+ },
105
+ {
106
+ "name": "cookie-prefs/react",
107
+ "path": "dist/react/index.js",
108
+ "limit": "980 B",
109
+ "gzip": true,
110
+ "ignore": [
111
+ "cookie-prefs"
112
+ ]
113
+ },
114
+ {
115
+ "name": "cookie-prefs/next",
116
+ "path": "dist/next/index.js",
117
+ "limit": "440 B",
118
+ "gzip": true,
119
+ "ignore": [
120
+ "cookie-prefs"
121
+ ]
122
+ },
123
+ {
124
+ "name": "cookie-prefs/theme",
125
+ "path": "dist/theme/index.js",
126
+ "limit": "1910 B",
127
+ "gzip": true,
128
+ "ignore": [
129
+ "cookie-prefs"
130
+ ]
131
+ }
132
+ ],
133
+ "peerDependencies": {
134
+ "next": ">=14",
135
+ "react": ">=18"
136
+ },
137
+ "peerDependenciesMeta": {
138
+ "next": {
139
+ "optional": true
140
+ },
141
+ "react": {
142
+ "optional": true
143
+ }
144
+ },
145
+ "devDependencies": {
146
+ "@arethetypeswrong/cli": "^0.18.5",
147
+ "@eslint/js": "^10.0.1",
148
+ "@size-limit/preset-small-lib": "^14.3.0",
149
+ "@types/node": "^26.6.6",
150
+ "@types/react": "^19.3.0",
151
+ "@types/react-dom": "^19.3.0",
152
+ "acorn": "^8.19.0",
153
+ "eslint": "^10.15.0",
154
+ "jsdom": "^31.0.1",
155
+ "next": "^16.4.6",
156
+ "publint": "^0.3.25",
157
+ "react": "^19.3.1",
158
+ "react-dom": "^19.3.1",
159
+ "size-limit": "^14.3.0",
160
+ "tsup": "^9.0.0",
161
+ "typescript": "^6.0.3",
162
+ "typescript-eslint": "^8.72.2",
163
+ "vitest": "^5.1.0",
164
+ "zod": "^4.6.7"
165
+ },
166
+ "overrides": {
167
+ "@typescript-eslint/typescript-estree": {
168
+ "minimatch": "^11.0.1"
169
+ }
170
+ }
171
+ }