cookie-prefs 0.2.2 → 0.2.3

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.
package/dist/index.cjs CHANGED
@@ -91,10 +91,14 @@ var bind = (key, def, prefix, options) => {
91
91
  [...enums].map(([raw, v]) => [raw, merge({ [v]: v }, def.m)[v]])
92
92
  ) : def.k;
93
93
  const parse = enums ? (raw) => enums.get(raw) : def.p;
94
- if (typeof process == "object" && process.env.NODE_ENV != "production") {
95
- if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
96
- if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
97
- throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
94
+ try {
95
+ if (process.env.NODE_ENV != "production") {
96
+ if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
97
+ if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
98
+ throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
99
+ }
100
+ } catch (e) {
101
+ if (/^cookie-prefs/.test(e.message)) throw e;
98
102
  }
99
103
  const cache = /* @__PURE__ */ new Map();
100
104
  const listeners = /* @__PURE__ */ new Set();
@@ -120,11 +124,14 @@ var bind = (key, def, prefix, options) => {
120
124
  return read(document.cookie);
121
125
  } catch {
122
126
  }
123
- if (typeof process == "object" && process.env.NODE_ENV != "production" && !warned) {
124
- warned = true;
125
- console.warn(
126
- `cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
127
- );
127
+ try {
128
+ if (process.env.NODE_ENV != "production" && !warned) {
129
+ warned = true;
130
+ console.warn(
131
+ `cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
132
+ );
133
+ }
134
+ } catch {
128
135
  }
129
136
  return fallback;
130
137
  };
@@ -151,7 +158,7 @@ var bind = (key, def, prefix, options) => {
151
158
  try {
152
159
  document.cookie = serialize(attrs, value);
153
160
  post();
154
- if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
161
+ if (process.env.NODE_ENV != "production" && !rejected && value != null) {
155
162
  const text = value.toWellFormed?.() ?? value;
156
163
  if (rawOf(document.cookie, name) !== text) {
157
164
  rejected = true;
@@ -190,11 +197,14 @@ var bind = (key, def, prefix, options) => {
190
197
  },
191
198
  read,
192
199
  toCookie: (value) => {
193
- if (typeof process == "object" && process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
194
- insecure = true;
195
- console.warn(
196
- `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
197
- );
200
+ try {
201
+ if (process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
202
+ insecure = true;
203
+ console.warn(
204
+ `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
205
+ );
206
+ }
207
+ } catch {
198
208
  }
199
209
  return { ...attrs, value: def.s(value) };
200
210
  }
package/dist/index.js CHANGED
@@ -89,10 +89,14 @@ var bind = (key, def, prefix, options) => {
89
89
  [...enums].map(([raw, v]) => [raw, merge({ [v]: v }, def.m)[v]])
90
90
  ) : def.k;
91
91
  const parse = enums ? (raw) => enums.get(raw) : def.p;
92
- if (typeof process == "object" && process.env.NODE_ENV != "production") {
93
- if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
94
- if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
95
- throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
92
+ try {
93
+ if (process.env.NODE_ENV != "production") {
94
+ if (!name) throw TypeError(`cookie-prefs: ${key} needs a non-empty cookie name`);
95
+ if (targets?.includes("class") && Object.values({ ...kind }).some((c) => !/^[^\t\n\f\r ]+$/.test(c)))
96
+ throw TypeError(`cookie-prefs: ${key}.reflect('class') needs non-empty classes without whitespace`);
97
+ }
98
+ } catch (e) {
99
+ if (/^cookie-prefs/.test(e.message)) throw e;
96
100
  }
97
101
  const cache = /* @__PURE__ */ new Map();
98
102
  const listeners = /* @__PURE__ */ new Set();
@@ -118,11 +122,14 @@ var bind = (key, def, prefix, options) => {
118
122
  return read(document.cookie);
119
123
  } catch {
120
124
  }
121
- if (typeof process == "object" && process.env.NODE_ENV != "production" && !warned) {
122
- warned = true;
123
- console.warn(
124
- `cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
125
- );
125
+ try {
126
+ if (process.env.NODE_ENV != "production" && !warned) {
127
+ warned = true;
128
+ console.warn(
129
+ `cookie-prefs: ${key}.get() cannot read document.cookie here and returns the default. On the server use read() or getPrefs().`
130
+ );
131
+ }
132
+ } catch {
126
133
  }
127
134
  return fallback;
128
135
  };
@@ -149,7 +156,7 @@ var bind = (key, def, prefix, options) => {
149
156
  try {
150
157
  document.cookie = serialize(attrs, value);
151
158
  post();
152
- if (typeof process == "object" && process.env.NODE_ENV != "production" && !rejected && value != null) {
159
+ if (process.env.NODE_ENV != "production" && !rejected && value != null) {
153
160
  const text = value.toWellFormed?.() ?? value;
154
161
  if (rawOf(document.cookie, name) !== text) {
155
162
  rejected = true;
@@ -188,11 +195,14 @@ var bind = (key, def, prefix, options) => {
188
195
  },
189
196
  read,
190
197
  toCookie: (value) => {
191
- if (typeof process == "object" && process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
192
- insecure = true;
193
- console.warn(
194
- `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
195
- );
198
+ try {
199
+ if (process.env.NODE_ENV != "production" && typeof document == "undefined" && !insecure && !attrs.secure && (attrs.sameSite == "none" || /^__(Host|Secure)-/i.test(name))) {
200
+ insecure = true;
201
+ console.warn(
202
+ `cookie-prefs: ${key}.toCookie() builds a cookie that browsers drop: SameSite=None and the __Host- and __Secure- name prefixes need Secure. Set secure: true in .options() or definePrefs().`
203
+ );
204
+ }
205
+ } catch {
196
206
  }
197
207
  return { ...attrs, value: def.s(value) };
198
208
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cookie-prefs",
3
- "version": "0.2.2",
3
+ "version": "0.2.3",
4
4
  "description": "Typed cookie-backed user preference state for React and Next.js",
5
5
  "keywords": [
6
6
  "react",