@kavach/cookie 1.0.0-next.6 → 1.0.0

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.
Files changed (51) hide show
  1. package/README.md +1 -1
  2. package/package.json +14 -24
  3. package/src/index.js +45 -51
  4. package/.turbo/turbo-coverage.log +0 -23
  5. package/.turbo/turbo-format.log +0 -16
  6. package/.turbo/turbo-lint.log +0 -6
  7. package/.turbo/turbo-prepublishOnly.log +0 -4
  8. package/.turbo/turbo-test:ci.log +0 -15
  9. package/.turbo/turbo-upgrade.log +0 -23
  10. package/CHANGELOG.md +0 -16
  11. package/LICENSE +0 -21
  12. package/coverage/base.css +0 -224
  13. package/coverage/block-navigation.js +0 -87
  14. package/coverage/favicon.png +0 -0
  15. package/coverage/index.html +0 -116
  16. package/coverage/index.js.html +0 -697
  17. package/coverage/lcov-report/base.css +0 -224
  18. package/coverage/lcov-report/block-navigation.js +0 -87
  19. package/coverage/lcov-report/favicon.png +0 -0
  20. package/coverage/lcov-report/index.html +0 -116
  21. package/coverage/lcov-report/index.js.html +0 -697
  22. package/coverage/lcov-report/prettify.css +0 -1
  23. package/coverage/lcov-report/prettify.js +0 -2
  24. package/coverage/lcov-report/sort-arrow-sprite.png +0 -0
  25. package/coverage/lcov-report/sorter.js +0 -196
  26. package/coverage/lcov.info +0 -270
  27. package/coverage/prettify.css +0 -1
  28. package/coverage/prettify.js +0 -2
  29. package/coverage/sort-arrow-sprite.png +0 -0
  30. package/coverage/sorter.js +0 -196
  31. package/coverage/tmp/coverage-97784-1672213805039-17.json +0 -1
  32. package/coverage/tmp/coverage-97784-1672213805123-14.json +0 -1
  33. package/coverage/tmp/coverage-97784-1672213805177-12.json +0 -1
  34. package/coverage/tmp/coverage-97784-1672213805233-11.json +0 -1
  35. package/coverage/tmp/coverage-97784-1672213805285-9.json +0 -1
  36. package/coverage/tmp/coverage-97784-1672213805338-8.json +0 -1
  37. package/coverage/tmp/coverage-97784-1672213805395-13.json +0 -1
  38. package/coverage/tmp/coverage-97784-1672213805450-10.json +0 -1
  39. package/coverage/tmp/coverage-97784-1672213805504-15.json +0 -1
  40. package/coverage/tmp/coverage-97784-1672213805557-7.json +0 -1
  41. package/coverage/tmp/coverage-97784-1672213805609-6.json +0 -1
  42. package/coverage/tmp/coverage-97784-1672213805660-16.json +0 -1
  43. package/coverage/tmp/coverage-97784-1672213805714-3.json +0 -1
  44. package/coverage/tmp/coverage-97784-1672213805770-4.json +0 -1
  45. package/coverage/tmp/coverage-97784-1672213805823-5.json +0 -1
  46. package/dist/index.d.ts +0 -34
  47. package/dist/index.d.ts.map +0 -1
  48. package/spec/parse.spec.js +0 -91
  49. package/spec/serialize.spec.js +0 -169
  50. package/tsconfig.json +0 -8
  51. package/vitest.config.js +0 -6
package/dist/index.d.ts DELETED
@@ -1,34 +0,0 @@
1
- /**
2
- * Parse a cookie header.
3
- *
4
- * Parse the given cookie header string into an object
5
- * The object has the various cookies as keys(names) => values
6
- *
7
- * @param {string} str
8
- * @param {object} [options]
9
- * @return {object}
10
- * @public
11
- */
12
- export function parse(str: string, options?: object): object;
13
- /**
14
- * Serialize data into a cookie header.
15
- *
16
- * Serialize the a name value pair into a cookie string suitable for
17
- * http headers. An optional options object specified cookie parameters.
18
- *
19
- * serialize('foo', 'bar', { httpOnly: true })
20
- * => "foo=bar; httpOnly"
21
- *
22
- * @param {string} name
23
- * @param {string} val
24
- * @param {object} [options]
25
- * @return {string}
26
- * @public
27
- */
28
- export function serialize(name: string, val: string, options?: object): string;
29
- declare namespace _default {
30
- export { parse };
31
- export { serialize };
32
- }
33
- export default _default;
34
- //# sourceMappingURL=index.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.js"],"names":[],"mappings":"AA+BA;;;;;;;;;;GAUG;AAEH,2BANW,MAAM,YACN,MAAM,GACL,MAAM,CAsCjB;AAED;;;;;;;;;;;;;;GAcG;AAEH,gCAPW,MAAM,OACN,MAAM,YACN,MAAM,GACL,MAAM,CA2FjB"}
@@ -1,91 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import { parse } from '../src/index.js'
3
-
4
- describe('Cookie Parser', () => {
5
- it('argument validation', () => {
6
- expect(parse.bind()).toThrowError(/argument str must be a string/)
7
- expect(parse.bind(null, 42)).toThrowError(/argument str must be a string/)
8
- })
9
-
10
- it('basic', () => {
11
- expect(parse('foo=bar')).toEqual({ foo: 'bar' })
12
- expect(parse('foo=123')).toEqual({ foo: '123' })
13
- })
14
-
15
- it('ignore spaces', () => {
16
- expect(parse('FOO = bar; baz = raz')).toEqual({
17
- FOO: 'bar',
18
- baz: 'raz'
19
- })
20
- })
21
-
22
- it('escaping', () => {
23
- expect(parse('foo="bar=123456789&name=Magic+Mouse"')).toEqual({
24
- foo: 'bar=123456789&name=Magic+Mouse'
25
- })
26
-
27
- expect(parse('email=%20%22%2c%3b%2f')).toEqual({ email: ' ",;/' })
28
- })
29
-
30
- it('ignore escaping error and return original value', () => {
31
- expect(parse('foo=%1;bar=bar')).toEqual({ foo: '%1', bar: 'bar' })
32
- })
33
-
34
- it('ignore non values', () => {
35
- expect(parse('foo=%1;bar=bar;HttpOnly;Secure')).toEqual({
36
- foo: '%1',
37
- bar: 'bar'
38
- })
39
- })
40
-
41
- it('unencoded', () => {
42
- expect(
43
- parse('foo="bar=123456789&name=Magic+Mouse"', {
44
- decode: function (v) {
45
- return v
46
- }
47
- })
48
- ).toEqual({ foo: 'bar=123456789&name=Magic+Mouse' })
49
-
50
- expect(
51
- parse('email=%20%22%2c%3b%2f', {
52
- decode: function (v) {
53
- return v
54
- }
55
- })
56
- ).toEqual({ email: '%20%22%2c%3b%2f' })
57
- })
58
-
59
- it('dates', () => {
60
- expect(
61
- parse('priority=true; expires=Wed, 29 Jan 2014 17:43:25 GMT; Path=/', {
62
- decode: function (v) {
63
- return v
64
- }
65
- })
66
- ).toEqual({
67
- priority: 'true',
68
- Path: '/',
69
- expires: 'Wed, 29 Jan 2014 17:43:25 GMT'
70
- })
71
- })
72
-
73
- it('missing value', () => {
74
- expect(
75
- parse('foo; bar=1; fizz= ; buzz=2', {
76
- decode: function (v) {
77
- return v
78
- }
79
- })
80
- ).toEqual({ bar: '1', fizz: '', buzz: '2' })
81
- })
82
-
83
- it('assign only once', () => {
84
- expect(parse('foo=%1;bar=bar;foo=boo')).toEqual({ foo: '%1', bar: 'bar' })
85
- expect(parse('foo=false;bar=bar;foo=true'), {
86
- foo: 'false',
87
- bar: 'bar'
88
- })
89
- expect(parse('foo=;bar=bar;foo=boo')).toEqual({ foo: '', bar: 'bar' })
90
- })
91
- })
@@ -1,169 +0,0 @@
1
- import { describe, expect, it } from 'vitest'
2
- import cookie from '../src/index.js'
3
-
4
- describe('Cookie Serialize', () => {
5
- it('basic', () => {
6
- expect(cookie.serialize('foo', 'bar')).toEqual('foo=bar')
7
- expect(cookie.serialize('foo', 'bar baz')).toEqual('foo=bar%20baz')
8
- expect(cookie.serialize('foo', '')).toEqual('foo=')
9
- expect(cookie.serialize.bind(cookie, 'foo\n', 'bar')).toThrowError(
10
- /argument name is invalid/
11
- )
12
- expect(cookie.serialize.bind(cookie, 'foo\u280a', 'bar')).toThrowError(
13
- /argument name is invalid/
14
- )
15
- expect(
16
- cookie.serialize.bind(cookie, 'foo', 'bar', { encode: 42 })
17
- ).toThrowError(/option encode is invalid/)
18
- })
19
-
20
- it('path', () => {
21
- expect(cookie.serialize('foo', 'bar', { path: '/' })).toEqual(
22
- 'foo=bar; Path=/'
23
- )
24
- expect(
25
- cookie.serialize.bind(cookie, 'foo', 'bar', {
26
- path: '/\n'
27
- })
28
- ).toThrowError(/option path is invalid/)
29
- })
30
-
31
- it('secure', () => {
32
- expect(cookie.serialize('foo', 'bar', { secure: true })).toEqual(
33
- 'foo=bar; Secure'
34
- )
35
- expect(cookie.serialize('foo', 'bar', { secure: false })).toEqual('foo=bar')
36
- })
37
-
38
- it('domain', () => {
39
- expect(cookie.serialize('foo', 'bar', { domain: 'example.com' })).toEqual(
40
- 'foo=bar; Domain=example.com'
41
- )
42
- expect(
43
- cookie.serialize.bind(cookie, 'foo', 'bar', {
44
- domain: 'example.com\n'
45
- })
46
- ).toThrowError(/option domain is invalid/)
47
- })
48
-
49
- it('httpOnly', () => {
50
- expect(cookie.serialize('foo', 'bar', { httpOnly: true })).toEqual(
51
- 'foo=bar; HttpOnly'
52
- )
53
- })
54
-
55
- it('maxAge', () => {
56
- expect(() =>
57
- cookie.serialize('foo', 'bar', {
58
- maxAge: 'buzz'
59
- })
60
- ).toThrowError(/option maxAge is invalid/)
61
-
62
- expect(() =>
63
- cookie.serialize('foo', 'bar', {
64
- maxAge: Infinity
65
- })
66
- ).toThrowError(/option maxAge is invalid/)
67
-
68
- expect(cookie.serialize('foo', 'bar', { maxAge: 1000 })).toEqual(
69
- 'foo=bar; Max-Age=1000'
70
- )
71
- expect(cookie.serialize('foo', 'bar', { maxAge: '1000' })).toEqual(
72
- 'foo=bar; Max-Age=1000'
73
- )
74
- expect(cookie.serialize('foo', 'bar', { maxAge: 0 })).toEqual(
75
- 'foo=bar; Max-Age=0'
76
- )
77
- expect(cookie.serialize('foo', 'bar', { maxAge: '0' })).toEqual(
78
- 'foo=bar; Max-Age=0'
79
- )
80
- expect(cookie.serialize('foo', 'bar', { maxAge: null })).toEqual('foo=bar')
81
- expect(cookie.serialize('foo', 'bar', { maxAge: undefined })).toEqual(
82
- 'foo=bar'
83
- )
84
- expect(cookie.serialize('foo', 'bar', { maxAge: 3.14 })).toEqual(
85
- 'foo=bar; Max-Age=3'
86
- )
87
- })
88
-
89
- it('expires', () => {
90
- expect(
91
- cookie.serialize('foo', 'bar', {
92
- expires: new Date(Date.UTC(2000, 11, 24, 10, 30, 59, 900))
93
- })
94
- ).toEqual('foo=bar; Expires=Sun, 24 Dec 2000 10:30:59 GMT')
95
-
96
- expect(
97
- cookie.serialize.bind(cookie, 'foo', 'bar', {
98
- expires: Date.now()
99
- })
100
- ).toThrowError(/option expires is invalid/)
101
- })
102
-
103
- it('sameSite', () => {
104
- expect(cookie.serialize('foo', 'bar', { sameSite: true })).toEqual(
105
- 'foo=bar; SameSite=Strict'
106
- )
107
- expect(cookie.serialize('foo', 'bar', { sameSite: 'Strict' })).toEqual(
108
- 'foo=bar; SameSite=Strict'
109
- )
110
- expect(cookie.serialize('foo', 'bar', { sameSite: 'strict' })).toEqual(
111
- 'foo=bar; SameSite=Strict'
112
- )
113
- expect(cookie.serialize('foo', 'bar', { sameSite: 'Lax' })).toEqual(
114
- 'foo=bar; SameSite=Lax'
115
- )
116
- expect(cookie.serialize('foo', 'bar', { sameSite: 'lax' })).toEqual(
117
- 'foo=bar; SameSite=Lax'
118
- )
119
- expect(cookie.serialize('foo', 'bar', { sameSite: 'None' })).toEqual(
120
- 'foo=bar; SameSite=None'
121
- )
122
- expect(cookie.serialize('foo', 'bar', { sameSite: 'none' })).toEqual(
123
- 'foo=bar; SameSite=None'
124
- )
125
- expect(cookie.serialize('foo', 'bar', { sameSite: false })).toEqual(
126
- 'foo=bar'
127
- )
128
-
129
- expect(
130
- cookie.serialize.bind(cookie, 'foo', 'bar', {
131
- sameSite: 'foo'
132
- })
133
- ).toThrowError(/option sameSite is invalid/)
134
- })
135
-
136
- it('escaping', () => {
137
- expect(cookie.serialize('cat', '+ ')).toEqual('cat=%2B%20')
138
- })
139
-
140
- it('parse->serialize', () => {
141
- expect(
142
- cookie.parse(cookie.serialize('cat', 'foo=123&name=baz five'))
143
- ).toEqual({
144
- cat: 'foo=123&name=baz five'
145
- })
146
-
147
- expect(cookie.parse(cookie.serialize('cat', ' ";/'))).toEqual({
148
- cat: ' ";/'
149
- })
150
- })
151
-
152
- it('unencoded', () => {
153
- expect(
154
- cookie.serialize('cat', '+ ', {
155
- encode: function (value) {
156
- return value
157
- }
158
- })
159
- ).toEqual('cat=+ ')
160
-
161
- expect(
162
- cookie.serialize.bind(cookie, 'cat', '+ \n', {
163
- encode: function (value) {
164
- return value
165
- }
166
- })
167
- ).toThrowError(/argument val is invalid/)
168
- })
169
- })
package/tsconfig.json DELETED
@@ -1,8 +0,0 @@
1
- {
2
- "extends": "shared-config/jsconfig.json",
3
- "include": ["src/**/*.js"],
4
- "compilerOptions": {
5
- "outDir": "dist",
6
- "checkJs": false
7
- }
8
- }
package/vitest.config.js DELETED
@@ -1,6 +0,0 @@
1
- import { defineConfig } from 'vite'
2
- import { testConfig } from 'shared-config'
3
-
4
- export default defineConfig({
5
- test: testConfig
6
- })