@kavach/cookie 1.0.0-next.28 → 1.0.0-next.31

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/README.md CHANGED
@@ -202,7 +202,7 @@ http.createServer(onRequest).listen(3000)
202
202
  ## Testing
203
203
 
204
204
  ```sh
205
- pnpm test
205
+ bun test
206
206
  ```
207
207
 
208
208
  ## References
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kavach/cookie",
3
- "version": "1.0.0-next.28",
3
+ "version": "1.0.0-next.31",
4
4
  "description": "Cookie serialize/deserialize forked from jshttp/cookie",
5
5
  "author": "Jerry Thomas <me@jerrythomas.name>",
6
6
  "license": "MIT",
@@ -8,7 +8,6 @@
8
8
  "cookie",
9
9
  "cookies"
10
10
  ],
11
- "main": "index.js",
12
11
  "module": "src/index.js",
13
12
  "types": "dist/index.d.ts",
14
13
  "type": "module",
@@ -26,6 +25,12 @@
26
25
  "clean": "rm -rf dist",
27
26
  "build": "bun prepublishOnly"
28
27
  },
28
+ "files": [
29
+ "src/**/*.js",
30
+ "dist/**/*.d.ts",
31
+ "README.md",
32
+ "package.json"
33
+ ],
29
34
  "exports": {
30
35
  "./package.json": "./package.json",
31
36
  ".": {
@@ -1,9 +0,0 @@
1
- import { describe, it, expect } from 'vitest'
2
- // skipcq: JS-C1003 - Importing all components for verification
3
- import * as utilities from '../src'
4
-
5
- describe('utilities', () => {
6
- it('should contain all exported utilities', () => {
7
- expect(Object.keys(utilities)).toEqual(['parse', 'serialize'])
8
- })
9
- })
@@ -1,91 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { parse } from '../src/index.js'
3
-
4
- describe('Cookie Parser', () => {
5
- const identity = (v) => v
6
-
7
- it('argument validation', () => {
8
- expect(parse.bind()).toThrowError(/argument str must be a string/)
9
- expect(parse.bind(null, 42)).toThrowError(/argument str must be a string/)
10
- })
11
-
12
- it('basic', () => {
13
- expect(parse('foo=bar')).toEqual({ foo: 'bar' })
14
- expect(parse('foo=123')).toEqual({ foo: '123' })
15
- })
16
-
17
- it('ignore spaces', () => {
18
- expect(parse('FOO = bar; baz = raz')).toEqual({
19
- FOO: 'bar',
20
- baz: 'raz'
21
- })
22
- })
23
-
24
- it('escaping', () => {
25
- expect(parse('foo="bar=123456789&name=Magic+Mouse"')).toEqual({
26
- foo: 'bar=123456789&name=Magic+Mouse'
27
- })
28
-
29
- expect(parse('email=%20%22%2c%3b%2f')).toEqual({ email: ' ",;/' })
30
- })
31
-
32
- it('ignore escaping error and return original value', () => {
33
- expect(parse('foo=%1;bar=bar')).toEqual({ foo: '%1', bar: 'bar' })
34
- })
35
-
36
- it('ignore non values', () => {
37
- expect(parse('foo=%1;bar=bar;HttpOnly;Secure')).toEqual({
38
- foo: '%1',
39
- bar: 'bar'
40
- })
41
- })
42
-
43
- it('unencoded', () => {
44
- expect(
45
- parse('foo="bar=123456789&name=Magic+Mouse"', {
46
- decode: identity
47
- })
48
- ).toEqual({ foo: 'bar=123456789&name=Magic+Mouse' })
49
-
50
- expect(
51
- parse('email=%20%22%2c%3b%2f', {
52
- decode: identity
53
- })
54
- ).toEqual({ email: '%20%22%2c%3b%2f' })
55
- })
56
-
57
- it('dates', () => {
58
- expect(
59
- parse('priority=true; expires=Wed, 29 Jan 2014 17:43:25 GMT; Path=/', {
60
- decode: identity
61
- })
62
- ).toEqual({
63
- priority: 'true',
64
- Path: '/',
65
- expires: 'Wed, 29 Jan 2014 17:43:25 GMT'
66
- })
67
- })
68
-
69
- it('missing value', () => {
70
- expect(
71
- parse('foo; bar=1; fizz= ; buzz=2', {
72
- decode: identity
73
- })
74
- ).toEqual({ bar: '1', fizz: '', buzz: '2' })
75
- })
76
-
77
- it('assign only once', () => {
78
- expect(parse('foo=%1;bar=bar;foo=boo')).toEqual({
79
- foo: '%1',
80
- bar: 'bar'
81
- })
82
- expect(parse('foo=false;bar=bar;foo=true'), {
83
- foo: 'false',
84
- bar: 'bar'
85
- })
86
- expect(parse('foo=;bar=bar;foo=boo')).toEqual({
87
- foo: '',
88
- bar: 'bar'
89
- })
90
- })
91
- })
@@ -1,158 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { parse, serialize } from '../src/index.js'
3
-
4
- describe('Cookie Serialize', () => {
5
- const identity = (v) => v
6
-
7
- it('basic', () => {
8
- expect(serialize('foo', 'bar')).toEqual('foo=bar')
9
- expect(serialize('foo', 'bar baz')).toEqual('foo=bar%20baz')
10
- expect(serialize('foo', '')).toEqual('foo=')
11
- expect(() => serialize('foo\n', 'bar')).toThrowError(
12
- /argument name is invalid/
13
- )
14
- expect(() => serialize('foo\n', 'bar')).toThrowError(
15
- /argument name is invalid/
16
- )
17
- expect(() => serialize('foo\u280a', 'bar')).toThrowError(
18
- /argument name is invalid/
19
- )
20
- expect(() => serialize('foo', 'bar', { encode: 42 })).toThrowError(
21
- /option encode is invalid/
22
- )
23
- })
24
-
25
- it('path', () => {
26
- expect(serialize('foo', 'bar', { path: '/' })).toEqual('foo=bar; Path=/')
27
- expect(() =>
28
- serialize('foo', 'bar', {
29
- path: '/\n'
30
- })
31
- ).toThrowError(/option path is invalid/)
32
- })
33
-
34
- it('secure', () => {
35
- expect(serialize('foo', 'bar', { secure: true })).toEqual('foo=bar; Secure')
36
- expect(serialize('foo', 'bar', { secure: false })).toEqual('foo=bar')
37
- })
38
-
39
- it('domain', () => {
40
- expect(serialize('foo', 'bar', { domain: 'example.com' })).toEqual(
41
- 'foo=bar; Domain=example.com'
42
- )
43
- expect(() =>
44
- serialize('foo', 'bar', {
45
- domain: 'example.com\n'
46
- })
47
- ).toThrowError(/option domain is invalid/)
48
- })
49
-
50
- it('httpOnly', () => {
51
- expect(serialize('foo', 'bar', { httpOnly: true })).toEqual(
52
- 'foo=bar; HttpOnly'
53
- )
54
- })
55
-
56
- it('maxAge', () => {
57
- expect(() =>
58
- serialize('foo', 'bar', {
59
- maxAge: 'buzz'
60
- })
61
- ).toThrowError(/option maxAge is invalid/)
62
-
63
- expect(() =>
64
- serialize('foo', 'bar', {
65
- maxAge: Infinity
66
- })
67
- ).toThrowError(/option maxAge is invalid/)
68
-
69
- expect(serialize('foo', 'bar', { maxAge: 1000 })).toEqual(
70
- 'foo=bar; Max-Age=1000'
71
- )
72
- expect(serialize('foo', 'bar', { maxAge: '1000' })).toEqual(
73
- 'foo=bar; Max-Age=1000'
74
- )
75
- expect(serialize('foo', 'bar', { maxAge: 0 })).toEqual('foo=bar; Max-Age=0')
76
- expect(serialize('foo', 'bar', { maxAge: '0' })).toEqual(
77
- 'foo=bar; Max-Age=0'
78
- )
79
- expect(serialize('foo', 'bar', { maxAge: null })).toEqual('foo=bar')
80
- expect(serialize('foo', 'bar')).toEqual('foo=bar')
81
- expect(serialize('foo', 'bar', { maxAge: 3.14 })).toEqual(
82
- 'foo=bar; Max-Age=3'
83
- )
84
- })
85
-
86
- it('expires', () => {
87
- expect(
88
- serialize('foo', 'bar', {
89
- expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900))
90
- })
91
- ).toEqual('foo=bar; Expires=Sun, 24 Dec 2000 10:30:59 GMT')
92
-
93
- expect(() =>
94
- serialize('foo', 'bar', {
95
- expires: Date.now()
96
- })
97
- ).toThrowError(/option expires is invalid/)
98
- })
99
-
100
- it('sameSite', () => {
101
- expect(serialize('foo', 'bar', { sameSite: true })).toEqual(
102
- 'foo=bar; SameSite=Strict'
103
- )
104
- expect(serialize('foo', 'bar', { sameSite: 'Strict' })).toEqual(
105
- 'foo=bar; SameSite=Strict'
106
- )
107
- expect(serialize('foo', 'bar', { sameSite: 'strict' })).toEqual(
108
- 'foo=bar; SameSite=Strict'
109
- )
110
- expect(serialize('foo', 'bar', { sameSite: 'Lax' })).toEqual(
111
- 'foo=bar; SameSite=Lax'
112
- )
113
- expect(serialize('foo', 'bar', { sameSite: 'lax' })).toEqual(
114
- 'foo=bar; SameSite=Lax'
115
- )
116
- expect(serialize('foo', 'bar', { sameSite: 'None' })).toEqual(
117
- 'foo=bar; SameSite=None'
118
- )
119
- expect(serialize('foo', 'bar', { sameSite: 'none' })).toEqual(
120
- 'foo=bar; SameSite=None'
121
- )
122
- expect(serialize('foo', 'bar', { sameSite: false })).toEqual('foo=bar')
123
-
124
- expect(() =>
125
- serialize('foo', 'bar', {
126
- sameSite: 'foo'
127
- })
128
- ).toThrowError(/option sameSite is invalid/)
129
- })
130
-
131
- it('escaping', () => {
132
- expect(serialize('cat', '+ ')).toEqual('cat=%2B%20')
133
- })
134
-
135
- it('parse->serialize', () => {
136
- expect(parse(serialize('cat', 'foo=123&name=baz five'))).toEqual({
137
- cat: 'foo=123&name=baz five'
138
- })
139
-
140
- expect(parse(serialize('cat', ' ";/'))).toEqual({
141
- cat: ' ";/'
142
- })
143
- })
144
-
145
- it('unencoded', () => {
146
- expect(
147
- serialize('cat', '+ ', {
148
- encode: identity
149
- })
150
- ).toEqual('cat=+ ')
151
-
152
- expect(() =>
153
- serialize('cat', '+ \n', {
154
- encode: identity
155
- })
156
- ).toThrowError(/argument val is invalid/)
157
- })
158
- })
@@ -1,12 +0,0 @@
1
- {
2
- "extends": "../../tsconfig.json",
3
- "compilerOptions": {
4
- "noEmit": false,
5
- "declaration": true,
6
- "declarationDir": "./dist",
7
- "emitDeclarationOnly": true,
8
- "outDir": "./dist",
9
- "allowJs": true
10
- },
11
- "exclude": ["**/spec/**/*", "**/fixtures/**/*"]
12
- }