@kavach/cookie 1.0.0-next.9 → 1.0.1

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.
@@ -1,196 +0,0 @@
1
- /* eslint-disable */
2
- var addSorting = (function() {
3
- 'use strict';
4
- var cols,
5
- currentSort = {
6
- index: 0,
7
- desc: false
8
- };
9
-
10
- // returns the summary table element
11
- function getTable() {
12
- return document.querySelector('.coverage-summary');
13
- }
14
- // returns the thead element of the summary table
15
- function getTableHeader() {
16
- return getTable().querySelector('thead tr');
17
- }
18
- // returns the tbody element of the summary table
19
- function getTableBody() {
20
- return getTable().querySelector('tbody');
21
- }
22
- // returns the th element for nth column
23
- function getNthColumn(n) {
24
- return getTableHeader().querySelectorAll('th')[n];
25
- }
26
-
27
- function onFilterInput() {
28
- const searchValue = document.getElementById('fileSearch').value;
29
- const rows = document.getElementsByTagName('tbody')[0].children;
30
- for (let i = 0; i < rows.length; i++) {
31
- const row = rows[i];
32
- if (
33
- row.textContent
34
- .toLowerCase()
35
- .includes(searchValue.toLowerCase())
36
- ) {
37
- row.style.display = '';
38
- } else {
39
- row.style.display = 'none';
40
- }
41
- }
42
- }
43
-
44
- // loads the search box
45
- function addSearchBox() {
46
- var template = document.getElementById('filterTemplate');
47
- var templateClone = template.content.cloneNode(true);
48
- templateClone.getElementById('fileSearch').oninput = onFilterInput;
49
- template.parentElement.appendChild(templateClone);
50
- }
51
-
52
- // loads all columns
53
- function loadColumns() {
54
- var colNodes = getTableHeader().querySelectorAll('th'),
55
- colNode,
56
- cols = [],
57
- col,
58
- i;
59
-
60
- for (i = 0; i < colNodes.length; i += 1) {
61
- colNode = colNodes[i];
62
- col = {
63
- key: colNode.getAttribute('data-col'),
64
- sortable: !colNode.getAttribute('data-nosort'),
65
- type: colNode.getAttribute('data-type') || 'string'
66
- };
67
- cols.push(col);
68
- if (col.sortable) {
69
- col.defaultDescSort = col.type === 'number';
70
- colNode.innerHTML =
71
- colNode.innerHTML + '<span class="sorter"></span>';
72
- }
73
- }
74
- return cols;
75
- }
76
- // attaches a data attribute to every tr element with an object
77
- // of data values keyed by column name
78
- function loadRowData(tableRow) {
79
- var tableCols = tableRow.querySelectorAll('td'),
80
- colNode,
81
- col,
82
- data = {},
83
- i,
84
- val;
85
- for (i = 0; i < tableCols.length; i += 1) {
86
- colNode = tableCols[i];
87
- col = cols[i];
88
- val = colNode.getAttribute('data-value');
89
- if (col.type === 'number') {
90
- val = Number(val);
91
- }
92
- data[col.key] = val;
93
- }
94
- return data;
95
- }
96
- // loads all row data
97
- function loadData() {
98
- var rows = getTableBody().querySelectorAll('tr'),
99
- i;
100
-
101
- for (i = 0; i < rows.length; i += 1) {
102
- rows[i].data = loadRowData(rows[i]);
103
- }
104
- }
105
- // sorts the table using the data for the ith column
106
- function sortByIndex(index, desc) {
107
- var key = cols[index].key,
108
- sorter = function(a, b) {
109
- a = a.data[key];
110
- b = b.data[key];
111
- return a < b ? -1 : a > b ? 1 : 0;
112
- },
113
- finalSorter = sorter,
114
- tableBody = document.querySelector('.coverage-summary tbody'),
115
- rowNodes = tableBody.querySelectorAll('tr'),
116
- rows = [],
117
- i;
118
-
119
- if (desc) {
120
- finalSorter = function(a, b) {
121
- return -1 * sorter(a, b);
122
- };
123
- }
124
-
125
- for (i = 0; i < rowNodes.length; i += 1) {
126
- rows.push(rowNodes[i]);
127
- tableBody.removeChild(rowNodes[i]);
128
- }
129
-
130
- rows.sort(finalSorter);
131
-
132
- for (i = 0; i < rows.length; i += 1) {
133
- tableBody.appendChild(rows[i]);
134
- }
135
- }
136
- // removes sort indicators for current column being sorted
137
- function removeSortIndicators() {
138
- var col = getNthColumn(currentSort.index),
139
- cls = col.className;
140
-
141
- cls = cls.replace(/ sorted$/, '').replace(/ sorted-desc$/, '');
142
- col.className = cls;
143
- }
144
- // adds sort indicators for current column being sorted
145
- function addSortIndicators() {
146
- getNthColumn(currentSort.index).className += currentSort.desc
147
- ? ' sorted-desc'
148
- : ' sorted';
149
- }
150
- // adds event listeners for all sorter widgets
151
- function enableUI() {
152
- var i,
153
- el,
154
- ithSorter = function ithSorter(i) {
155
- var col = cols[i];
156
-
157
- return function() {
158
- var desc = col.defaultDescSort;
159
-
160
- if (currentSort.index === i) {
161
- desc = !currentSort.desc;
162
- }
163
- sortByIndex(i, desc);
164
- removeSortIndicators();
165
- currentSort.index = i;
166
- currentSort.desc = desc;
167
- addSortIndicators();
168
- };
169
- };
170
- for (i = 0; i < cols.length; i += 1) {
171
- if (cols[i].sortable) {
172
- // add the click event handler on the th so users
173
- // dont have to click on those tiny arrows
174
- el = getNthColumn(i).querySelector('.sorter').parentElement;
175
- if (el.addEventListener) {
176
- el.addEventListener('click', ithSorter(i));
177
- } else {
178
- el.attachEvent('onclick', ithSorter(i));
179
- }
180
- }
181
- }
182
- }
183
- // adds sorting functionality to the UI
184
- return function() {
185
- if (!getTable()) {
186
- return;
187
- }
188
- cols = loadColumns();
189
- loadData();
190
- addSearchBox();
191
- addSortIndicators();
192
- enableUI();
193
- };
194
- })();
195
-
196
- window.addEventListener('load', addSorting);
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 | undefined): 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 | undefined): 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,iCAEL,MAAM,CAsCjB;AAED;;;;;;;;;;;;;;GAcG;AAEH,gCAPW,MAAM,OACN,MAAM,iCAEL,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
- })