├── test ├── node │ ├── .gitignore │ ├── esm │ │ ├── package.json │ │ └── index.js │ └── cjs │ │ ├── package.json │ │ └── index.js └── index.test.ts ├── bun.lockb ├── .gitignore ├── .npmignore ├── .eslintrc.js ├── LICENSE ├── package.json ├── CHANGELOG.md ├── example └── index.ts ├── src └── index.ts ├── README.md ├── tsconfig.esm.json ├── tsconfig.cjs.json └── tsconfig.json /test/node/.gitignore: -------------------------------------------------------------------------------- 1 | node_modules/ 2 | package-lock.json -------------------------------------------------------------------------------- /bun.lockb: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/elysiajs/elysia-cookie/HEAD/bun.lockb -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | node_modules 4 | .pnpm-debug.log 5 | dist 6 | 7 | build -------------------------------------------------------------------------------- /test/node/esm/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "module", 3 | "dependencies": { 4 | "@elysiajs/cookie": "../../.." 5 | } 6 | } -------------------------------------------------------------------------------- /test/node/cjs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "type": "commonjs", 3 | "dependencies": { 4 | "@elysiajs/cookie": "../../.." 5 | } 6 | } -------------------------------------------------------------------------------- /.npmignore: -------------------------------------------------------------------------------- 1 | .git 2 | .gitignore 3 | .prettierrc 4 | .cjs.swcrc 5 | .es.swcrc 6 | bun.lockb 7 | 8 | node_modules 9 | tsconfig.json 10 | pnpm-lock.yaml 11 | jest.config.js 12 | nodemon.json 13 | 14 | example 15 | tests 16 | test 17 | CHANGELOG.md 18 | .eslintrc.js 19 | tsconfig.cjs.json 20 | tsconfig.esm.json 21 | -------------------------------------------------------------------------------- /test/node/esm/index.js: -------------------------------------------------------------------------------- 1 | if ('Bun' in globalThis) { 2 | throw new Error('❌ Use Node.js to run this test!'); 3 | } 4 | 5 | import { cookie } from '@elysiajs/cookie'; 6 | 7 | if (typeof cookie !== 'function') { 8 | throw new Error('❌ ESM Node.js failed'); 9 | } 10 | 11 | console.log('✅ ESM Node.js works!'); 12 | -------------------------------------------------------------------------------- /test/node/cjs/index.js: -------------------------------------------------------------------------------- 1 | if ('Bun' in globalThis) { 2 | throw new Error('❌ Use Node.js to run this test!'); 3 | } 4 | 5 | const { cookie } = require('@elysiajs/cookie'); 6 | 7 | if (typeof cookie !== 'function') { 8 | throw new Error('❌ CommonJS Node.js failed'); 9 | } 10 | 11 | console.log('✅ CommonJS Node.js works!'); 12 | -------------------------------------------------------------------------------- /.eslintrc.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | "env": { 3 | "es2021": true, 4 | "node": true 5 | }, 6 | "extends": [ 7 | "eslint:recommended", 8 | "plugin:@typescript-eslint/recommended" 9 | ], 10 | "parser": "@typescript-eslint/parser", 11 | "parserOptions": { 12 | "ecmaVersion": "latest", 13 | "sourceType": "module" 14 | }, 15 | "plugins": [ 16 | "@typescript-eslint" 17 | ], 18 | "rules": { 19 | "@typescript-eslint/ban-types": 'off', 20 | '@typescript-eslint/no-explicit-any': 'off' 21 | }, 22 | "ignorePatterns": ["example/*", "tests/**/*"] 23 | } 24 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright 2022 saltyAom 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 8 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@elysiajs/cookie", 3 | "version": "0.8.0", 4 | "description": "Plugin for Elysia that add supports for get/set cookie", 5 | "author": { 6 | "name": "saltyAom", 7 | "url": "https://github.com/SaltyAom", 8 | "email": "saltyaom@gmail.com" 9 | }, 10 | "main": "./dist/index.js", 11 | "exports": { 12 | "bun": "./dist/index.js", 13 | "node": "./dist/cjs/index.js", 14 | "require": "./dist/cjs/index.js", 15 | "import": "./dist/index.js", 16 | "default": "./dist/index.js" 17 | }, 18 | "types": "./src/index.ts", 19 | "keywords": [ 20 | "elysia", 21 | "cookie" 22 | ], 23 | "homepage": "https://github.com/elysiajs/elysia-cookie", 24 | "repository": { 25 | "type": "git", 26 | "url": "https://github.com/elysiajs/elysia-cookie" 27 | }, 28 | "bugs": "https://github.com/elysiajs/elysia-cookie/issues", 29 | "license": "MIT", 30 | "scripts": { 31 | "dev": "bun run --hot example/index.ts", 32 | "test": "bun test && npm run test:node", 33 | "test:node": "npm install --prefix ./test/node/cjs/ && npm install --prefix ./test/node/esm/ && node ./test/node/cjs/index.js && node ./test/node/esm/index.js", 34 | "build": "rimraf dist && tsc --project tsconfig.esm.json && tsc --project tsconfig.cjs.json", 35 | "release": "npm run build && npm run test && npm publish --access public" 36 | }, 37 | "dependencies": { 38 | "@types/cookie": "^0.5.1", 39 | "@types/cookie-signature": "^1.1.0", 40 | "cookie": "^0.5.0", 41 | "cookie-signature": "^1.2.1" 42 | }, 43 | "peerDependencies": { 44 | "elysia": ">= 0.8.0" 45 | }, 46 | "devDependencies": { 47 | "@types/node": "^20.1.4", 48 | "bun-types": "^0.7.0", 49 | "elysia": "0.8.0", 50 | "eslint": "^8.40.0", 51 | "rimraf": "4.3", 52 | "typescript": "^5.0.4" 53 | } 54 | } -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | 2 | # 0.8.0-rc.0 - 15 Dec 2023 3 | Change: 4 | - Add support for Elysia 0.8 5 | 6 | 7 | # 0.7.0 - 20 Sep 2023 8 | - Add support for Elysia 0.7 9 | 10 | 11 | # 0.7.0-beta.0 - 18 Sep 2023 12 | - Add support for Elysia 0.7 13 | 14 | 15 | # 0.6.0 - 6 Aug 2023 16 | - Add support for Elysia 0.6 17 | 18 | 19 | # 0.6.0-rc.0 - 6 Aug 2023 20 | - Add support for Elysia 0.6 21 | # 0.5.0 - 15 May 2023 22 | - Add support for Elysia 0.5 23 | - Add CommonJS support 24 | 25 | # 0.3.0 - 17 Mar 2023 26 | Improvement: 27 | - Minimum requirement is set to >= 0.3.0 28 | 29 | # 0.3.0-rc.0 - 9 Mar 2023 30 | Improvement: 31 | - Minimum requirement is set to >= 0.3.0-rc.3 32 | 33 | # 0.1.1 - 10 Feb 2023 34 | Improvement: 35 | - Add support for setting multiple cookie 36 | 37 | Change: 38 | - Minimum requirement for Elysia is 0.2.6 39 | 40 | # 0.1.0-rc.8 - 13 Dec 2022 41 | Improvement: 42 | - Use `cookie.unsign` which use `crypto.timingSafeEqual` as Bun 0.4.0 supports 43 | 44 | Change: 45 | - Minimum requirement is Bun 0.4.0 46 | 47 | # 0.1.0-rc.4 - 13 Dec 2022 48 | Improvement: 49 | - Add support for Elysia 0.1.0-rc.5 50 | 51 | 52 | # 0.1.0-rc.3 - 9 Dec 2022 53 | Fix: 54 | - Add main fields Bundlephobia 55 | 56 | # 0.1.0-rc.2 - 7 Dec 2022 57 | Fix: 58 | - Add cookie defination as `dependencies` 59 | 60 | # 0.1.0-rc.1 - 6 Dec 2022 61 | Improvement: 62 | - Support for Elysia 0.1.0-rc.1 onward 63 | 64 | # 0.0.0-experimental.5 - 2 Dec 2022 65 | Improvement: 66 | - set `unsignCookie` to `decorate` instead of `inject` 67 | - Remove redundant import 68 | 69 | # 0.0.0-experimental.4 - 2 Dec 2022 70 | Feature: 71 | - Implemented sign cookie 72 | 73 | Change: 74 | - Support for KingWorld 0.0.0-experimental.55 onward 75 | 76 | # 0.0.0-experimental.3 - 22 Nov 2022 77 | Change: 78 | - Support for KingWorld 0.0.0-experimental.50 onward 79 | 80 | # 0.0.0-experimental.2 - 10 Nov 2022 81 | Change: 82 | - Support for KingWorld 0.0.0-experimental.40 onward 83 | 84 | # 0.0.0-experimental.1 - 30 Oct 2022 85 | Change: 86 | - Support for KingWorld 0.0.0-experimental.28 onward 87 | - chore: update dependencies 88 | -------------------------------------------------------------------------------- /example/index.ts: -------------------------------------------------------------------------------- 1 | import { Elysia } from 'elysia' 2 | import { cookie } from '../src' 3 | 4 | const app = new Elysia() 5 | .use( 6 | cookie({ 7 | secret: 'Fischl von Luftschloss Narfidort' 8 | }) 9 | ) 10 | .get( 11 | '/json', 12 | ({ setCookie, unsignCookie, cookie: { council: councilSigned } }) => { 13 | const council = unsignCookie(councilSigned) 14 | 15 | if (!council.valid) 16 | throw new Error('Fail to decode cookie: council') 17 | 18 | setCookie( 19 | 'council', 20 | JSON.stringify([ 21 | { 22 | name: 'Rin', 23 | affilation: 'Adminstration' 24 | } 25 | ]), 26 | { 27 | signed: true 28 | } 29 | ) 30 | 31 | return JSON.parse(council.value) 32 | } 33 | ) 34 | .get('/', ({ cookie, setCookie }) => { 35 | console.log(cookie) 36 | 37 | setCookie( 38 | 'counter', 39 | cookie.counter ? `${+cookie.counter + 1}`.toString() : `1` 40 | ) 41 | 42 | return cookie.counter 43 | }) 44 | .get('/sign-out', ({ cookie, removeCookie }) => { 45 | removeCookie('name') 46 | 47 | return 'signed out' 48 | }) 49 | .get('/cookie', ({ cookie }) => (cookie.biscuit = 'tea')) 50 | .get('/multi', ({ cookie, setCookie }) => { 51 | setCookie('a', 'b') 52 | setCookie('c', 'd') 53 | 54 | return cookie 55 | }) 56 | .get('/sign/:name', ({ params: { name }, cookie, setCookie }) => { 57 | setCookie('name', name, { 58 | signed: true 59 | }) 60 | 61 | return name 62 | }) 63 | .get('/auth', ({ unsignCookie, cookie: { name }, set }) => { 64 | const { valid, value } = unsignCookie(name) 65 | 66 | if (!valid) { 67 | set.status = 401 68 | return 'Unauthorized' 69 | } 70 | 71 | return value 72 | }) 73 | .listen(8080) 74 | -------------------------------------------------------------------------------- /test/index.test.ts: -------------------------------------------------------------------------------- 1 | import { Elysia } from 'elysia' 2 | import { cookie } from '../src' 3 | 4 | import { describe, expect, it } from 'bun:test' 5 | 6 | const req = (path: string) => new Request(`http://localhost:8080${path}`) 7 | 8 | describe('Cookie', () => { 9 | it('should set cookie', async () => { 10 | const app = new Elysia() 11 | .use(cookie()) 12 | .get('/', ({ cookie: { user }, setCookie }) => { 13 | setCookie('user', 'saltyaom') 14 | 15 | return user 16 | }) 17 | 18 | const res = await app.handle(req('/')) 19 | expect(res.headers.get('set-cookie')).toBe('user=saltyaom; Path=/') 20 | }) 21 | 22 | it('should remove cookie', async () => { 23 | const app = new Elysia().use(cookie()).get('/', ({ removeCookie }) => { 24 | removeCookie('user') 25 | 26 | return 'unset' 27 | }) 28 | 29 | const res = await app.handle( 30 | new Request('http://localhost/', { 31 | headers: { 32 | cookie: 'user=saltyaom' 33 | } 34 | }) 35 | ) 36 | expect(res.headers.get('set-cookie')).toBe( 37 | 'user=; Expires=Thu, 01 Jan 1970 00:00:00 GMT' 38 | ) 39 | }) 40 | 41 | it('skip cookie removal if cookie is absent', async () => { 42 | const app = new Elysia().use(cookie()).get('/', ({ removeCookie }) => { 43 | removeCookie('user') 44 | 45 | return 'unset' 46 | }) 47 | 48 | const res = await app.handle(req('/')) 49 | expect(res.headers.get('set-cookie')).toBe(null) 50 | }) 51 | 52 | it('sign cookie', async () => { 53 | const app = new Elysia() 54 | .use( 55 | cookie({ 56 | secret: 'Takodachi' 57 | }) 58 | ) 59 | .get('/', ({ setCookie }) => { 60 | setCookie('name', 'saltyaom', { 61 | signed: true 62 | }) 63 | 64 | return 'unset' 65 | }) 66 | 67 | const res = await app.handle(req('/')) 68 | expect(res.headers.get('set-cookie')?.includes('.')).toBe(true) 69 | }) 70 | 71 | it('unsign cookie', async () => { 72 | const app = new Elysia() 73 | .use( 74 | cookie({ 75 | secret: 'Takodachi' 76 | }) 77 | ) 78 | .get('/', ({ setCookie }) => { 79 | setCookie('name', 'saltyaom', { 80 | signed: true 81 | }) 82 | 83 | return 'unset' 84 | }) 85 | .get('/unsign', ({ cookie, unsignCookie }) => { 86 | const { valid, value } = unsignCookie(cookie.name) 87 | 88 | return value 89 | }) 90 | 91 | const authen = await app.handle(req('/')) 92 | const res = await app 93 | .handle( 94 | new Request('http://localhost:8080/unsign', { 95 | headers: { 96 | cookie: authen.headers.get('set-cookie') ?? '' 97 | } 98 | }) 99 | ) 100 | .then((r) => r.text()) 101 | 102 | expect(res).toBe('saltyaom') 103 | }) 104 | 105 | it('should set multiple', async () => { 106 | const app = new Elysia() 107 | .use(cookie()) 108 | .get('/', ({ cookie: { user }, setCookie }) => { 109 | setCookie('a', 'b') 110 | setCookie('c', 'd') 111 | 112 | return user 113 | }) 114 | 115 | const res = await app.handle(req('/')) 116 | expect(res.headers.getAll('Set-Cookie')).toEqual(['a=b; Path=/', 'c=d; Path=/']) 117 | }) 118 | }) 119 | -------------------------------------------------------------------------------- /src/index.ts: -------------------------------------------------------------------------------- 1 | import { Elysia, Handler } from 'elysia' 2 | 3 | import { serialize, parse, type CookieSerializeOptions } from 'cookie' 4 | import { sign, unsign } from 'cookie-signature' 5 | 6 | export interface SetCookieOptions extends CookieSerializeOptions { 7 | // Should cookie be signed or not 8 | signed?: boolean 9 | } 10 | 11 | export interface CookieOptions extends SetCookieOptions { 12 | /** 13 | * Secret key for signing cookie 14 | * 15 | * If array is passed, will use Key Rotation. 16 | * 17 | * Key rotation is when an encryption key is retired 18 | * and replaced by generating a new cryptographic key. 19 | */ 20 | secret?: string | string[] 21 | } 22 | 23 | export interface CookieRequest { 24 | cookie: Record 25 | setCookie: (name: string, value: string, options?: SetCookieOptions) => void 26 | removeCookie: (name: string) => void 27 | } 28 | 29 | export const cookie = (options: CookieOptions = {}) => { 30 | const { signed, secret: secretKey, ...defaultOptions } = options 31 | 32 | const secret = !secretKey 33 | ? undefined 34 | : typeof secretKey === 'string' 35 | ? secretKey 36 | : secretKey[0] 37 | 38 | const isStringKey = typeof secret === 'string' 39 | 40 | return new Elysia({ 41 | name: '@elysiajs/cookie', 42 | seed: options 43 | }) 44 | .decorate('unsignCookie', ((value: string) => { 45 | if (!secret) 46 | throw new Error('No secret is provided to cookie plugin') 47 | 48 | let unsigned: false | string = isStringKey 49 | ? unsign(value, secret) 50 | : false 51 | 52 | if (isStringKey === false) 53 | for (let i = 0; i < secret.length; i++) { 54 | const temp = unsign(value, secret[i]) 55 | 56 | if (temp) { 57 | unsigned = temp 58 | break 59 | } 60 | } 61 | 62 | return { 63 | valid: unsigned !== false, 64 | value: unsigned || undefined 65 | } 66 | }) as (value: string) => 67 | | { 68 | valid: true 69 | value: string 70 | } 71 | | { 72 | valid: false 73 | value: undefined 74 | }) 75 | .derive((context) => { 76 | let _cookie: Record 77 | 78 | const getCookie = () => { 79 | if (_cookie) return _cookie 80 | 81 | try { 82 | const headerCookie = context.request.headers.get('cookie') 83 | 84 | _cookie = headerCookie ? parse(headerCookie) : {} 85 | } catch (error) { 86 | _cookie = {} 87 | } 88 | 89 | return _cookie 90 | } 91 | 92 | return { 93 | get cookie() { 94 | return getCookie() 95 | }, 96 | setCookie(name, value, { signed = false, ...options } = {}) { 97 | if (signed) { 98 | if (!secret) 99 | throw new Error( 100 | 'No secret is provided to cookie plugin' 101 | ) 102 | 103 | value = sign(value, secret) 104 | } 105 | 106 | if (!Array.isArray(context.set.headers['Set-Cookie'])) 107 | // @ts-ignore 108 | context.set.headers['Set-Cookie'] = [] 109 | 110 | // @ts-ignore 111 | context.set.headers['Set-Cookie'].push( 112 | serialize(name, value, { 113 | path: '/', 114 | ...defaultOptions, 115 | ...options 116 | }) 117 | ) 118 | 119 | if (!_cookie) getCookie() 120 | _cookie[name] = value 121 | }, 122 | removeCookie(name: string) { 123 | if (!getCookie()[name]) return 124 | 125 | context.set.headers['Set-Cookie'] = serialize(name, '', { 126 | expires: new Date('Thu, Jan 01 1970 00:00:00 UTC') 127 | }) 128 | 129 | delete _cookie[name] 130 | } 131 | } as CookieRequest 132 | }) 133 | } 134 | 135 | export default cookie 136 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | This plugin has been merged into Elysia core and is deprecated, please use [Elysia.cookie](https://elysiajs.com/patterns/cookie.html) instead 2 | 3 | # @elysiajs/cookie 4 | Plugin for [Elysia](https://github.com/elysiajs/elysia) that add support for reading, and setting cookie. 5 | 6 | ## Installation 7 | ```bash 8 | bun add @elysiajs/cookie 9 | ``` 10 | 11 | ## Example 12 | ```typescript 13 | import { Elysia } from 'elysia' 14 | import { cookie } from '@elysiajs/cookie' 15 | 16 | const app = new Elysia() 17 | .use(cookie()) 18 | .get('/', ({ cookie: { user }, setCookie, removeCookie }) => { 19 | if (user === 'admin') unsetCookie('user') 20 | if (!user) 21 | setCookie('user', 'saltyaom', { 22 | httpOnly: true 23 | }) 24 | 25 | return `Hi, ${user}!` 26 | }) 27 | .listen(8080) 28 | ``` 29 | 30 | ## API 31 | ### cookie 32 | Parsed cookie from request in form of `Record` 33 | ```typescript 34 | cookie: Record 35 | ``` 36 | 37 | ### setCookie 38 | Function to set new cookie 39 | ```typescript 40 | setCookie: ( 41 | name: string, 42 | value: string, 43 | options?: CookieSerializeOptions 44 | ) => void 45 | ``` 46 | 47 | ### removeCookie 48 | A function to remove cookie 49 | ```typescript 50 | removeCookie: (name: string) => void 51 | ``` 52 | 53 | ### unsignCookie 54 | Unsign cookie 55 | ```typescript 56 | unsignCookie: (name: string) => void 57 | ``` 58 | 59 | ### Serialize Options 60 | Serialize option is based on [cookie package](https://npmjs.com/package/cookie) 61 | ```typescript 62 | export interface CookieSerializeOptions { 63 | /** 64 | * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.3|Domain Set-Cookie attribute}. By default, no 65 | * domain is set, and most clients will consider the cookie to apply to only 66 | * the current domain. 67 | */ 68 | domain?: string | undefined; 69 | 70 | /** 71 | * Specifies a function that will be used to encode a cookie's value. Since 72 | * value of a cookie has a limited character set (and must be a simple 73 | * string), this function can be used to encode a value into a string suited 74 | * for a cookie's value. 75 | * 76 | * The default function is the global `encodeURIComponent`, which will 77 | * encode a JavaScript string into UTF-8 byte sequences and then URL-encode 78 | * any that fall outside of the cookie range. 79 | */ 80 | encode?(value: string): string; 81 | 82 | /** 83 | * Specifies the `Date` object to be the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.1|`Expires` `Set-Cookie` attribute}. By default, 84 | * no expiration is set, and most clients will consider this a "non-persistent cookie" and will delete 85 | * it on a condition like exiting a web browser application. 86 | * 87 | * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} 88 | * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is 89 | * possible not all clients by obey this, so if both are set, they should 90 | * point to the same date and time. 91 | */ 92 | expires?: Date | undefined; 93 | /** 94 | * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.6|`HttpOnly` `Set-Cookie` attribute}. 95 | * When truthy, the `HttpOnly` attribute is set, otherwise it is not. By 96 | * default, the `HttpOnly` attribute is not set. 97 | * 98 | * *Note* be careful when setting this to true, as compliant clients will 99 | * not allow client-side JavaScript to see the cookie in `document.cookie`. 100 | */ 101 | httpOnly?: boolean | undefined; 102 | /** 103 | * Specifies the number (in seconds) to be the value for the `Max-Age` 104 | * `Set-Cookie` attribute. The given number will be converted to an integer 105 | * by rounding down. By default, no maximum age is set. 106 | * 107 | * *Note* the {@link https://tools.ietf.org/html/rfc6265#section-5.3|cookie storage model specification} 108 | * states that if both `expires` and `maxAge` are set, then `maxAge` takes precedence, but it is 109 | * possible not all clients by obey this, so if both are set, they should 110 | * point to the same date and time. 111 | */ 112 | maxAge?: number | undefined; 113 | /** 114 | * Specifies the value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.4|`Path` `Set-Cookie` attribute}. 115 | * By default, the path is considered the "default path". 116 | */ 117 | path?: string | undefined; 118 | /** 119 | * Specifies the `string` to be the value for the [`Priority` `Set-Cookie` attribute][rfc-west-cookie-priority-00-4.1]. 120 | * 121 | * - `'low'` will set the `Priority` attribute to `Low`. 122 | * - `'medium'` will set the `Priority` attribute to `Medium`, the default priority when not set. 123 | * - `'high'` will set the `Priority` attribute to `High`. 124 | * 125 | * More information about the different priority levels can be found in 126 | * [the specification][rfc-west-cookie-priority-00-4.1]. 127 | * 128 | * **note** This is an attribute that has not yet been fully standardized, and may change in the future. 129 | * This also means many clients may ignore this attribute until they understand it. 130 | */ 131 | priority?: 'low' | 'medium' | 'high' | undefined; 132 | /** 133 | * Specifies the boolean or string to be the value for the {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|`SameSite` `Set-Cookie` attribute}. 134 | * 135 | * - `true` will set the `SameSite` attribute to `Strict` for strict same 136 | * site enforcement. 137 | * - `false` will not set the `SameSite` attribute. 138 | * - `'lax'` will set the `SameSite` attribute to Lax for lax same site 139 | * enforcement. 140 | * - `'strict'` will set the `SameSite` attribute to Strict for strict same 141 | * site enforcement. 142 | * - `'none'` will set the SameSite attribute to None for an explicit 143 | * cross-site cookie. 144 | * 145 | * More information about the different enforcement levels can be found in {@link https://tools.ietf.org/html/draft-ietf-httpbis-rfc6265bis-03#section-4.1.2.7|the specification}. 146 | * 147 | * *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. 148 | */ 149 | sameSite?: true | false | 'lax' | 'strict' | 'none' | undefined; 150 | /** 151 | * Specifies the boolean value for the {@link https://tools.ietf.org/html/rfc6265#section-5.2.5|`Secure` `Set-Cookie` attribute}. When truthy, the 152 | * `Secure` attribute is set, otherwise it is not. By default, the `Secure` attribute is not set. 153 | * 154 | * *Note* be careful when setting this to `true`, as compliant clients will 155 | * not send the cookie back to the server in the future if the browser does 156 | * not have an HTTPS connection. 157 | */ 158 | secure?: boolean | undefined; 159 | } 160 | ``` 161 | 162 | ## Caveat 163 | As the current state of Bun (0.1.4), there's no current way to set multiple cookie at once as Bun doesn't support setting multiple headers with same name which is required for setting multiple cookie in one response. 164 | -------------------------------------------------------------------------------- /tsconfig.esm.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2021", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | "lib": ["ESNext", "DOM", "ScriptHost"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "ES2022", /* Specify what module code is generated. */ 29 | // "rootDir": "./src", /* Specify the root folder within your source files. */ 30 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "resolveJsonModule": true, /* Enable importing .json files. */ 39 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 40 | 41 | /* JavaScript Support */ 42 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 43 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 44 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 45 | 46 | /* Emit */ 47 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 48 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 49 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 50 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 51 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 52 | "outDir": "./dist", /* Specify an output folder for all emitted files. */ 53 | "removeComments": true, /* Disable emitting comments. */ 54 | // "noEmit": true, /* Disable emitting files from a compilation. */ 55 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 56 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 57 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 58 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 61 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 62 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 63 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 64 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 65 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 66 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 67 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 68 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 69 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 70 | 71 | /* Interop Constraints */ 72 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 73 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 74 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 75 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 76 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 77 | 78 | /* Type Checking */ 79 | "strict": true, /* Enable all strict type-checking options. */ 80 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 81 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 82 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 83 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 84 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 85 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 86 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 87 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 88 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 89 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 90 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 91 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 92 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 93 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 94 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 95 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 96 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 97 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 98 | 99 | /* Completeness */ 100 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 101 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 102 | }, 103 | "include": ["src/**/*"] 104 | } 105 | -------------------------------------------------------------------------------- /tsconfig.cjs.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2022", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | "lib": ["ESNext", "DOM", "ScriptHost"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "CommonJS", /* Specify what module code is generated. */ 29 | // "rootDir": "./src", /* Specify the root folder within your source files. */ 30 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "resolveJsonModule": true, /* Enable importing .json files. */ 39 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 40 | 41 | /* JavaScript Support */ 42 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 43 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 44 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 45 | 46 | /* Emit */ 47 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 48 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 49 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 50 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 51 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 52 | "outDir": "./dist/cjs", /* Specify an output folder for all emitted files. */ 53 | "removeComments": true, /* Disable emitting comments. */ 54 | // "noEmit": true, /* Disable emitting files from a compilation. */ 55 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 56 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 57 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 58 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 61 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 62 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 63 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 64 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 65 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 66 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 67 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 68 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 69 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 70 | 71 | /* Interop Constraints */ 72 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 73 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 74 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 75 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 76 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 77 | 78 | /* Type Checking */ 79 | "strict": true, /* Enable all strict type-checking options. */ 80 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 81 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 82 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 83 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 84 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 85 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 86 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 87 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 88 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 89 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 90 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 91 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 92 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 93 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 94 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 95 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 96 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 97 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 98 | 99 | /* Completeness */ 100 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 101 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 102 | }, 103 | "include": ["src/**/*"] 104 | } 105 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Visit https://aka.ms/tsconfig to read more about this file */ 4 | 5 | /* Projects */ 6 | // "incremental": true, /* Save .tsbuildinfo files to allow for incremental compilation of projects. */ 7 | // "composite": true, /* Enable constraints that allow a TypeScript project to be used with project references. */ 8 | // "tsBuildInfoFile": "./.tsbuildinfo", /* Specify the path to .tsbuildinfo incremental compilation file. */ 9 | // "disableSourceOfProjectReferenceRedirect": true, /* Disable preferring source files instead of declaration files when referencing composite projects. */ 10 | // "disableSolutionSearching": true, /* Opt a project out of multi-project reference checking when editing. */ 11 | // "disableReferencedProjectLoad": true, /* Reduce the number of projects loaded automatically by TypeScript. */ 12 | 13 | /* Language and Environment */ 14 | "target": "ES2020", /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */ 15 | "lib": ["ESNext", "DOM", "ScriptHost"], /* Specify a set of bundled library declaration files that describe the target runtime environment. */ 16 | // "jsx": "preserve", /* Specify what JSX code is generated. */ 17 | // "experimentalDecorators": true, /* Enable experimental support for TC39 stage 2 draft decorators. */ 18 | // "emitDecoratorMetadata": true, /* Emit design-type metadata for decorated declarations in source files. */ 19 | // "jsxFactory": "", /* Specify the JSX factory function used when targeting React JSX emit, e.g. 'React.createElement' or 'h'. */ 20 | // "jsxFragmentFactory": "", /* Specify the JSX Fragment reference used for fragments when targeting React JSX emit e.g. 'React.Fragment' or 'Fragment'. */ 21 | // "jsxImportSource": "", /* Specify module specifier used to import the JSX factory functions when using 'jsx: react-jsx*'. */ 22 | // "reactNamespace": "", /* Specify the object invoked for 'createElement'. This only applies when targeting 'react' JSX emit. */ 23 | // "noLib": true, /* Disable including any library files, including the default lib.d.ts. */ 24 | // "useDefineForClassFields": true, /* Emit ECMAScript-standard-compliant class fields. */ 25 | // "moduleDetection": "auto", /* Control what method is used to detect module-format JS files. */ 26 | 27 | /* Modules */ 28 | "module": "ES2022", /* Specify what module code is generated. */ 29 | // "rootDir": "./src", /* Specify the root folder within your source files. */ 30 | "moduleResolution": "node", /* Specify how TypeScript looks up a file from a given module specifier. */ 31 | // "baseUrl": "./src", /* Specify the base directory to resolve non-relative module names. */ 32 | // "paths": {}, /* Specify a set of entries that re-map imports to additional lookup locations. */ 33 | // "rootDirs": [], /* Allow multiple folders to be treated as one when resolving modules. */ 34 | // "typeRoots": [], /* Specify multiple folders that act like './node_modules/@types'. */ 35 | "types": ["bun-types"], /* Specify type package names to be included without being referenced in a source file. */ 36 | // "allowUmdGlobalAccess": true, /* Allow accessing UMD globals from modules. */ 37 | // "moduleSuffixes": [], /* List of file name suffixes to search when resolving a module. */ 38 | // "resolveJsonModule": true, /* Enable importing .json files. */ 39 | // "noResolve": true, /* Disallow 'import's, 'require's or ''s from expanding the number of files TypeScript should add to a project. */ 40 | 41 | /* JavaScript Support */ 42 | // "allowJs": true, /* Allow JavaScript files to be a part of your program. Use the 'checkJS' option to get errors from these files. */ 43 | // "checkJs": true, /* Enable error reporting in type-checked JavaScript files. */ 44 | // "maxNodeModuleJsDepth": 1, /* Specify the maximum folder depth used for checking JavaScript files from 'node_modules'. Only applicable with 'allowJs'. */ 45 | 46 | /* Emit */ 47 | "declaration": true, /* Generate .d.ts files from TypeScript and JavaScript files in your project. */ 48 | // "declarationMap": true, /* Create sourcemaps for d.ts files. */ 49 | // "emitDeclarationOnly": true, /* Only output d.ts files and not JavaScript files. */ 50 | // "sourceMap": true, /* Create source map files for emitted JavaScript files. */ 51 | // "outFile": "./", /* Specify a file that bundles all outputs into one JavaScript file. If 'declaration' is true, also designates a file that bundles all .d.ts output. */ 52 | // "outDir": "./dist", /* Specify an output folder for all emitted files. */ 53 | // "removeComments": true, /* Disable emitting comments. */ 54 | "noEmit": true, /* Disable emitting files from a compilation. */ 55 | // "importHelpers": true, /* Allow importing helper functions from tslib once per project, instead of including them per-file. */ 56 | // "importsNotUsedAsValues": "remove", /* Specify emit/checking behavior for imports that are only used for types. */ 57 | // "downlevelIteration": true, /* Emit more compliant, but verbose and less performant JavaScript for iteration. */ 58 | // "sourceRoot": "", /* Specify the root path for debuggers to find the reference source code. */ 59 | // "mapRoot": "", /* Specify the location where debugger should locate map files instead of generated locations. */ 60 | // "inlineSourceMap": true, /* Include sourcemap files inside the emitted JavaScript. */ 61 | // "inlineSources": true, /* Include source code in the sourcemaps inside the emitted JavaScript. */ 62 | // "emitBOM": true, /* Emit a UTF-8 Byte Order Mark (BOM) in the beginning of output files. */ 63 | // "newLine": "crlf", /* Set the newline character for emitting files. */ 64 | // "stripInternal": true, /* Disable emitting declarations that have '@internal' in their JSDoc comments. */ 65 | // "noEmitHelpers": true, /* Disable generating custom helper functions like '__extends' in compiled output. */ 66 | // "noEmitOnError": true, /* Disable emitting files if any type checking errors are reported. */ 67 | // "preserveConstEnums": true, /* Disable erasing 'const enum' declarations in generated code. */ 68 | // "declarationDir": "./", /* Specify the output directory for generated declaration files. */ 69 | // "preserveValueImports": true, /* Preserve unused imported values in the JavaScript output that would otherwise be removed. */ 70 | 71 | /* Interop Constraints */ 72 | // "isolatedModules": true, /* Ensure that each file can be safely transpiled without relying on other imports. */ 73 | // "allowSyntheticDefaultImports": true, /* Allow 'import x from y' when a module doesn't have a default export. */ 74 | "esModuleInterop": true, /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */ 75 | // "preserveSymlinks": true, /* Disable resolving symlinks to their realpath. This correlates to the same flag in node. */ 76 | "forceConsistentCasingInFileNames": true, /* Ensure that casing is correct in imports. */ 77 | 78 | /* Type Checking */ 79 | "strict": true, /* Enable all strict type-checking options. */ 80 | // "noImplicitAny": true, /* Enable error reporting for expressions and declarations with an implied 'any' type. */ 81 | // "strictNullChecks": true, /* When type checking, take into account 'null' and 'undefined'. */ 82 | // "strictFunctionTypes": true, /* When assigning functions, check to ensure parameters and the return values are subtype-compatible. */ 83 | // "strictBindCallApply": true, /* Check that the arguments for 'bind', 'call', and 'apply' methods match the original function. */ 84 | // "strictPropertyInitialization": true, /* Check for class properties that are declared but not set in the constructor. */ 85 | // "noImplicitThis": true, /* Enable error reporting when 'this' is given the type 'any'. */ 86 | // "useUnknownInCatchVariables": true, /* Default catch clause variables as 'unknown' instead of 'any'. */ 87 | // "alwaysStrict": true, /* Ensure 'use strict' is always emitted. */ 88 | // "noUnusedLocals": true, /* Enable error reporting when local variables aren't read. */ 89 | // "noUnusedParameters": true, /* Raise an error when a function parameter isn't read. */ 90 | // "exactOptionalPropertyTypes": true, /* Interpret optional property types as written, rather than adding 'undefined'. */ 91 | // "noImplicitReturns": true, /* Enable error reporting for codepaths that do not explicitly return in a function. */ 92 | // "noFallthroughCasesInSwitch": true, /* Enable error reporting for fallthrough cases in switch statements. */ 93 | // "noUncheckedIndexedAccess": true, /* Add 'undefined' to a type when accessed using an index. */ 94 | // "noImplicitOverride": true, /* Ensure overriding members in derived classes are marked with an override modifier. */ 95 | // "noPropertyAccessFromIndexSignature": true, /* Enforces using indexed accessors for keys declared using an indexed type. */ 96 | // "allowUnusedLabels": true, /* Disable error reporting for unused labels. */ 97 | // "allowUnreachableCode": true, /* Disable error reporting for unreachable code. */ 98 | 99 | /* Completeness */ 100 | // "skipDefaultLibCheck": true, /* Skip type checking .d.ts files that are included with TypeScript. */ 101 | "skipLibCheck": true, /* Skip type checking all .d.ts files. */ 102 | }, 103 | // "include": ["src/**/*"] 104 | } 105 | --------------------------------------------------------------------------------