@yurkimus/cookies 0.0.7 → 0.1.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.
- package/package.json +2 -6
- package/readme.md +4 -80
- package/source/index.d.ts +2 -21
- package/source/index.js +26 -33
- package/deno.json +0 -12
- package/deno.lock +0 -27
package/package.json
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
{
|
|
2
2
|
"type": "module",
|
|
3
3
|
"name": "@yurkimus/cookies",
|
|
4
|
-
"version": "0.0
|
|
4
|
+
"version": "0.1.0",
|
|
5
5
|
"author": "yurkimus <yurkimus@gmail.com>",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|
|
8
8
|
"url": "https://github.com/yurkimus/cookies.git"
|
|
9
9
|
},
|
|
10
|
-
"exports": "./source/index.js"
|
|
11
|
-
"dependencies": {
|
|
12
|
-
"@yurkimus/curry": "0.1.0",
|
|
13
|
-
"@yurkimus/types": "0.2.1"
|
|
14
|
-
}
|
|
10
|
+
"exports": "./source/index.js"
|
|
15
11
|
}
|
package/readme.md
CHANGED
|
@@ -2,90 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
JavaScript-utilities to handle cookies everywhere.
|
|
4
4
|
|
|
5
|
-
## Table of Contents
|
|
6
|
-
|
|
7
|
-
- [Installation](#installation)
|
|
8
|
-
- [Exports](#exports)
|
|
9
|
-
- [parse](#parse)
|
|
10
|
-
- [read](#read)
|
|
11
|
-
- [serialize](#serialize)
|
|
12
|
-
- [License](#license)
|
|
13
|
-
|
|
14
|
-
## Installation
|
|
15
|
-
|
|
16
|
-
### npm
|
|
17
|
-
|
|
18
|
-
```
|
|
19
|
-
npm install @yurkimus/cookies
|
|
20
|
-
```
|
|
21
|
-
|
|
22
|
-
### urls
|
|
23
|
-
|
|
24
|
-
```
|
|
25
|
-
"@yurkimus/cookies": "npm:@yurkimus/cookies"
|
|
26
|
-
```
|
|
27
|
-
|
|
28
|
-
```
|
|
29
|
-
"@yurkimus/cookies": "github:yurkimus/cookies"
|
|
30
|
-
```
|
|
31
|
-
|
|
32
|
-
```
|
|
33
|
-
"@yurkimus/cookies": "https://raw.githubusercontent.com/yurkimus/cookies/main/source/index.js"
|
|
34
|
-
```
|
|
35
|
-
|
|
36
5
|
## Exports
|
|
37
6
|
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
#### Definition
|
|
41
|
-
|
|
42
|
-
```
|
|
43
|
-
read :: string -> string -> string
|
|
44
|
-
```
|
|
45
|
-
|
|
46
|
-
#### Example
|
|
47
|
-
|
|
48
|
-
```javascript
|
|
49
|
-
let cookie = 'name=John; age=30; role=admin'
|
|
50
|
-
|
|
51
|
-
let age = read('age', cookie) // => '30'
|
|
52
|
-
|
|
53
|
-
let [age, name] = ['age', 'name']
|
|
54
|
-
.map(key => read(key))
|
|
55
|
-
.map(reader => reader(cookie)) // => ['30', 'John']
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### parse
|
|
59
|
-
|
|
60
|
-
#### Definition
|
|
61
|
-
|
|
62
|
-
```
|
|
63
|
-
parse :: string -> object
|
|
64
|
-
```
|
|
65
|
-
|
|
66
|
-
#### Example
|
|
67
|
-
|
|
68
|
-
```javascript
|
|
69
|
-
parse('name=John; age=30; role=admin') // => { name: 'John', age: '30', role: 'admin' }
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### serialize
|
|
73
|
-
|
|
74
|
-
#### Definition
|
|
75
|
-
|
|
76
|
-
```
|
|
77
|
-
serialize :: string -> * -> [(string, string)] -> string
|
|
7
|
+
```typescript
|
|
8
|
+
parseCookies = (source: any) => Record<string, string | undefined>
|
|
78
9
|
```
|
|
79
10
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
```javascript
|
|
83
|
-
let attributes = [
|
|
84
|
-
['path', '/'],
|
|
85
|
-
['expires', 'Wed, 21 Oct 2026 07:28:00 GMT'],
|
|
86
|
-
]
|
|
87
|
-
|
|
88
|
-
serialize('name', 'John', attributes) // => 'name=John; path=/; expires=Wed, 21 Oct 2026 07:28:00 GMT'
|
|
11
|
+
```typescript
|
|
12
|
+
readCookie = (name: string, source: any) => string | undefined
|
|
89
13
|
```
|
|
90
14
|
|
|
91
15
|
## License
|
package/source/index.d.ts
CHANGED
|
@@ -1,21 +1,2 @@
|
|
|
1
|
-
export
|
|
2
|
-
|
|
3
|
-
interface read {
|
|
4
|
-
(key: string): (source: string) => string
|
|
5
|
-
|
|
6
|
-
(key: string, source: string): string
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export let read: read
|
|
10
|
-
|
|
11
|
-
interface serialize {
|
|
12
|
-
(name: string): (value: any) => (attributes: [string, string][]) => string
|
|
13
|
-
|
|
14
|
-
(name: string): (value: any, attributes: [string, string][]) => string
|
|
15
|
-
|
|
16
|
-
(name: string, value: any): (attributes: [string, string][]) => string
|
|
17
|
-
|
|
18
|
-
(name: string, value: any, attributes: [string, string][]): string
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
export let serialize: serialize
|
|
1
|
+
export function parseCookies(source: any): Record<string, string | undefined>;
|
|
2
|
+
export function readCookie(name: string, source: any): string | undefined;
|
package/source/index.js
CHANGED
|
@@ -1,43 +1,36 @@
|
|
|
1
|
-
import { curry } from '@yurkimus/curry'
|
|
2
|
-
import { is } from '@yurkimus/types'
|
|
3
|
-
|
|
4
1
|
/**
|
|
5
2
|
* Parses a cookie string into a list of key-value pairs.
|
|
3
|
+
*
|
|
4
|
+
* @param {*} source
|
|
5
|
+
*
|
|
6
|
+
* @returns {Record<string, string | undefined>}
|
|
7
|
+
*
|
|
8
|
+
* @throws {TypeError} When 'source' is not a 'string'
|
|
6
9
|
*/
|
|
7
|
-
export
|
|
8
|
-
if (
|
|
9
|
-
throw
|
|
10
|
+
export var parseCookies = source => {
|
|
11
|
+
if (typeof source !== 'string')
|
|
12
|
+
throw TypeError(`Parameter 'source' must be a 'string'.`)
|
|
10
13
|
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
14
|
+
if (source === '')
|
|
15
|
+
return {}
|
|
16
|
+
else
|
|
17
|
+
return source
|
|
18
|
+
.split('; ')
|
|
19
|
+
.map(string => string.split('='))
|
|
20
|
+
.reduce((object, [key, value]) => (object[key] = value, object), {})
|
|
15
21
|
}
|
|
16
22
|
|
|
17
23
|
/**
|
|
18
24
|
* Reads cookies from a cookie string using a provided list of keys.
|
|
19
|
-
*/
|
|
20
|
-
export let read = curry((key, source) => {
|
|
21
|
-
if (!is('String', source))
|
|
22
|
-
throw new TypeError(`Parameter 'source' must be a string.`)
|
|
23
|
-
|
|
24
|
-
return parse(source)[key]
|
|
25
|
-
})
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* Serializes a cookie from its components into a string.
|
|
29
25
|
*
|
|
30
|
-
* @
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* attributes = [['path', '/'], ['expires', 'Wed, 21 Oct 2026 07:28:00 GMT']],
|
|
35
|
-
* serialized = serialize(name, value, attributes); // => 'name=John; path=/; expires=Wed, 21 Oct 2026 07:28:00 GMT'
|
|
36
|
-
* ```
|
|
26
|
+
* @param {string} name
|
|
27
|
+
* @param {*} source
|
|
28
|
+
*
|
|
29
|
+
* @throws {TypeError} When 'source' is not a 'string'
|
|
37
30
|
*/
|
|
38
|
-
export
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
31
|
+
export var readCookie = (name, source) => {
|
|
32
|
+
if (typeof source !== 'string')
|
|
33
|
+
throw TypeError(`Parameter 'source' must be a 'string'.`)
|
|
34
|
+
|
|
35
|
+
return parseCookies(source)[name]
|
|
36
|
+
}
|
package/deno.json
DELETED
package/deno.lock
DELETED
|
@@ -1,27 +0,0 @@
|
|
|
1
|
-
{
|
|
2
|
-
"version": "4",
|
|
3
|
-
"specifiers": {
|
|
4
|
-
"npm:@yurkimus/curry@0.1.0": "0.1.0",
|
|
5
|
-
"npm:@yurkimus/types@0.2.1": "0.2.1"
|
|
6
|
-
},
|
|
7
|
-
"npm": {
|
|
8
|
-
"@yurkimus/curry@0.1.0": {
|
|
9
|
-
"integrity": "sha512-1eCQhNMLDZQpF2iOgSk7B6Mmg9tM65TsTV4jPsf5nk0yrhIlvouggm0HSTreYsvqgaFZPHEg60N1LcU2smpIHQ=="
|
|
10
|
-
},
|
|
11
|
-
"@yurkimus/types@0.2.1": {
|
|
12
|
-
"integrity": "sha512-eHABWuuMFq0Jo/HWK6I4YkHb3TrxiJyIVQaEL4GQUdcRiBNCRlL4UmHawaXHPG15LtWXEmNX1if4xgwcLklK7w=="
|
|
13
|
-
}
|
|
14
|
-
},
|
|
15
|
-
"workspace": {
|
|
16
|
-
"dependencies": [
|
|
17
|
-
"npm:@yurkimus/curry@0.1.0",
|
|
18
|
-
"npm:@yurkimus/types@0.2.1"
|
|
19
|
-
],
|
|
20
|
-
"packageJson": {
|
|
21
|
-
"dependencies": [
|
|
22
|
-
"npm:@yurkimus/curry@0.1.0",
|
|
23
|
-
"npm:@yurkimus/types@0.2.1"
|
|
24
|
-
]
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
}
|