Gathering detailed insights and metrics for @tinyhttp/cookie
Gathering detailed insights and metrics for @tinyhttp/cookie
Gathering detailed insights and metrics for @tinyhttp/cookie
Gathering detailed insights and metrics for @tinyhttp/cookie
🦄 0-legacy, tiny & fast web framework as a replacement of Express
npm install @tinyhttp/cookie
Typescript
Module System
Min. Node Version
Node Version
NPM Version
@tinyhttp/jsonp@2.1.15
Updated on Feb 22, 2025
@tinyhttp/app@2.5.2
Updated on Feb 22, 2025
@tinyhttp/res@2.2.5
Updated on Feb 21, 2025
@tinyhttp/req@2.2.5
Updated on Feb 21, 2025
@tinyhttp/rate-limit@2.1.5
Updated on Feb 21, 2025
@tinyhttp/proxy-addr@2.2.1
Updated on Feb 21, 2025
TypeScript (99.9%)
JavaScript (0.1%)
Total Downloads
0
Last Day
0
Last Week
0
Last Month
0
Last Year
0
MIT License
2,849 Stars
1,773 Commits
127 Forks
21 Watchers
2 Branches
59 Contributors
Updated on Jul 15, 2025
Latest Version
2.1.1
Package Id
@tinyhttp/cookie@2.1.1
Unpacked Size
16.59 kB
Size
5.86 kB
File Count
7
NPM Version
10.8.1
Node Version
22.3.0
Published on
Jun 26, 2024
Cumulative downloads
Total Downloads
Last Day
0%
NaN
Compared to previous day
Last Week
0%
NaN
Compared to previous week
Last Month
0%
NaN
Compared to previous month
Last Year
0%
NaN
Compared to previous year
A rewrite of cookie module.
HTTP cookie parser and serializer for Node.js.
1pnpm i @tinyhttp/cookie
1import { parse, serialize } from '@tinyhttp/cookie'
parse(str, options)
Parse an HTTP Cookie
header string and returning an object of all cookie name-value pairs.
The str
argument is the string representing a Cookie
header value and options
is an
optional object containing additional parsing options.
1import { parse } from '@tinyhttp/cookie' 2 3parse('foo=bar; equation=E%3Dmc%5E2') 4// { foo: 'bar', equation: 'E=mc^2' }
parse
accepts these properties in the options object.
decode
Specifies a function that will be used to decode a cookie's value. Since the value of a cookie has a limited character set (and must be a simple string), this function can be used to decode a previously-encoded cookie value into a JavaScript string or other object.
The default function is the global decodeURIComponent
, which will decode any URL-encoded
sequences into their byte representations.
note if an error is thrown from this function, the original, non-decoded cookie value will be returned as the cookie's value.
serialize(name, value, options)
Serialize a cookie name-value pair into a Set-Cookie
header string. The name
argument is the
name for the cookie, the value
argument is the value to set the cookie to, and the options
argument is an optional object containing additional serialization options.
1import { serialize } from '@tinyhttp/cookie' 2 3serialize('foo', 'bar') 4// foo=bar
serialize
accepts these properties in the options object.
domain
Specifies the value for the [Domain
Set-Cookie
attribute][rfc-6265-5.2.3]. By default, no
domain is set, and most clients will consider the cookie to apply to only the current domain.
encode
Specifies a function that will be used to encode a cookie's value. Since value of a cookie has a limited character set (and must be a simple string), this function can be used to encode a value into a string suited for a cookie's value.
The default function is the global encodeURIComponent
, which will encode a JavaScript string
into UTF-8 byte sequences and then URL-encode any that fall outside of the cookie range.
expires
Specifies the Date
object to be the value for the [Expires
Set-Cookie
attribute][rfc-6265-5.2.1].
By default, no expiration is set, and most clients will consider this a "non-persistent cookie" and
will delete it on a condition like exiting a web browser application.
note the [cookie storage model specification][rfc-6265-5.3] states that if both expires
and
maxAge
are set, then maxAge
takes precedence, but it is possible not all clients by obey this,
so if both are set, they should point to the same date and time.
httpOnly
Specifies the boolean
value for the [HttpOnly
Set-Cookie
attribute][rfc-6265-5.2.6]. When truthy,
the HttpOnly
attribute is set, otherwise it is not. By default, the HttpOnly
attribute is not set.
note be careful when setting this to true
, as compliant clients will not allow client-side
JavaScript to see the cookie in document.cookie
.
maxAge
Specifies the number
(in seconds) to be the value for the [Max-Age
Set-Cookie
attribute][rfc-6265-5.2.2].
The given number will be converted to an integer by rounding down. By default, no maximum age is set.
note the [cookie storage model specification][rfc-6265-5.3] states that if both expires
and
maxAge
are set, then maxAge
takes precedence, but it is possible not all clients by obey this,
so if both are set, they should point to the same date and time.
path
Specifies the value for the [Path
Set-Cookie
attribute][rfc-6265-5.2.4]. By default, the path
is considered the ["default path"][rfc-6265-5.1.4].
sameSite
Specifies the boolean
or string
to be the value for the [SameSite
Set-Cookie
attribute][rfc-6265bis-03-4.1.2.7].
true
will set the SameSite
attribute to Strict
for strict same site enforcement.false
will not set the SameSite
attribute.'lax'
will set the SameSite
attribute to Lax
for lax same site enforcement.'none'
will set the SameSite
attribute to None
for an explicit cross-site cookie.'strict'
will set the SameSite
attribute to Strict
for strict same site enforcement.More information about the different enforcement levels can be found in [the specification][rfc-6265bis-03-4.1.2.7].
note This is an attribute that has not yet been fully standardized, and may change in the future. This also means many clients may ignore this attribute until they understand it.
secure
Specifies the boolean
value for the [Secure
Set-Cookie
attribute][rfc-6265-5.2.5]. When truthy,
the Secure
attribute is set, otherwise it is not. By default, the Secure
attribute is not set.
note be careful when setting this to true
, as compliant clients will not send the cookie back to
the server in the future if the browser does not have an HTTPS connection.
1import { App } from '@tinyhttp/app' 2import { parse, serialize } from '@tinyhttp/cookie' 3import { escapeHTML } from 'es-escape-html' 4 5new App() 6 .use((req, res) => { 7 if (req.query?.name) { 8 // Set a new cookie with the name 9 res.set( 10 'Set-Cookie', 11 serialize('name', String(query.name), { 12 httpOnly: true, 13 maxAge: 60 * 60 * 24 * 7 // 1 week 14 }) 15 ) 16 17 // Redirect back after setting cookie 18 res 19 .status(302) 20 .set('Location', req.headers.referer || '/') 21 .end() 22 } 23 24 const cookie = parse(req.headers.cookie || '') 25 26 const { name } = cookie 27 28 res.set('Content-Type', 'text/html; charset=UTF-8') 29 30 res.write(name ? `<p>Welcome back, <strong>${escapeHTML(name)}</strong>!</p>` : '<p>Hello, new visitor!</p>') 31 32 res.write('<form method="GET">') 33 res.write('<input placeholder="enter your name" name="name"><input type="submit" value="Set Name">') 34 res.end('</form>') 35 }) 36 .listen(3000)
No vulnerabilities found.
Reason
no dangerous workflow patterns detected
Reason
no binaries found in the repo
Reason
license file detected
Details
Reason
SAST tool is not run on all commits -- score normalized to 8
Details
Reason
2 existing vulnerabilities detected
Details
Reason
7 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 6
Reason
Found 2/24 approved changesets -- score normalized to 0
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
detected GitHub workflow tokens with excessive permissions
Details
Reason
dependency not pinned by hash detected -- score normalized to 0
Details
Reason
project is not fuzzed
Details
Reason
security policy file not detected
Details
Score
Last Scanned on 2025-07-07
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More