MCPcopy Create free account
hub / github.com/Effect-TS/effect / makeCookie

Function makeCookie

packages/platform/src/Cookies.ts:330–363  ·  view source on GitHub ↗
(
  name: string,
  value: string,
  options?: Cookie["options"] | undefined
)

Source from the content-addressed store, hash-verified

328 * @category constructors
329 */
330export function makeCookie(
331 name: string,
332 value: string,
333 options?: Cookie["options"] | undefined
334): Either.Either<Cookie, CookiesError> {
335 if (!cookieNameRegExp.test(name)) {
336 return Either.left(new CookiesError({ reason: "InvalidName" }))
337 }
338 const encodedValue = encodeURIComponent(value)
339 if (encodedValue && !cookieValueRegExp.test(encodedValue)) {
340 return Either.left(new CookiesError({ reason: "InvalidValue" }))
341 }
342
343 if (options !== undefined) {
344 if (options.domain !== undefined && !cookieDomainRegExp.test(options.domain)) {
345 return Either.left(new CookiesError({ reason: "InvalidDomain" }))
346 }
347
348 if (options.path !== undefined && !cookiePathRegExp.test(options.path)) {
349 return Either.left(new CookiesError({ reason: "InvalidPath" }))
350 }
351
352 if (options.maxAge !== undefined && !Duration.isFinite(Duration.decode(options.maxAge))) {
353 return Either.left(new CookiesError({ reason: "InfinityMaxAge" }))
354 }
355 }
356
357 return Either.right(Object.assign(Object.create(CookieProto), {
358 name,
359 value,
360 valueEncoded: encodedValue,
361 options
362 }))
363}
364
365/**
366 * Create a new cookie, throwing an error if invalid

Callers 2

unsafeMakeCookieFunction · 0.85
Cookies.tsFile · 0.85

Calls 2

decodeMethod · 0.80
createMethod · 0.80

Tested by

no test coverage detected