@yurkimus/cookies 0.0.8 → 0.1.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.
@@ -0,0 +1,28 @@
1
+ name: Publish @yurkimus/cookies
2
+
3
+ on:
4
+ pull_request:
5
+ types: [ closed ]
6
+ branches:
7
+ - main
8
+
9
+ permissions:
10
+ id-token: write
11
+ contents: write
12
+
13
+ jobs:
14
+ publish:
15
+ runs-on: ubuntu-latest
16
+ if: github.event.pull_request.merged == true
17
+ steps:
18
+ - uses: actions/checkout@v5
19
+ with:
20
+ fetch-depth: 0
21
+ - uses: actions/setup-node@v6
22
+ with:
23
+ node-version: 24
24
+ - run: git config user.name "github-actions[bot]"
25
+ - run: git config user.email "github-actions[bot]@users.noreply.github.com"
26
+ - run: npm version patch
27
+ - run: npm publish
28
+ - run: git push --follow-tags
package/package.json CHANGED
@@ -1,15 +1,11 @@
1
1
  {
2
2
  "type": "module",
3
3
  "name": "@yurkimus/cookies",
4
- "version": "0.0.8",
4
+ "version": "0.1.1",
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.1",
13
- "@yurkimus/types": "0.2.3"
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
- ### read
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
- #### Example
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.js CHANGED
@@ -1,43 +1 @@
1
- import { curry } from '@yurkimus/curry'
2
- import { is } from '@yurkimus/types'
3
-
4
- /**
5
- * Parses a cookie string into a list of key-value pairs.
6
- */
7
- export let parse = source => {
8
- if (!is('String', source))
9
- throw new TypeError(`Parameter 'source' must be a string.`)
10
-
11
- return source
12
- .split('; ')
13
- .map(string => string.split('='))
14
- .reduce((object, [key, value]) => (object[key] = value, object), {})
15
- }
16
-
17
- /**
18
- * 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
- *
30
- * @example
31
- * ```
32
- * let name = 'name',
33
- * value = 'John',
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
- * ```
37
- */
38
- export let serialize = curry((name, value, attributes) =>
39
- name
40
- + '='
41
- + value
42
- + attributes.reduce((string, attribute) => string + '; ' + attribute.join('='), '')
43
- )
1
+ export let getCookie = (name, source) => new RegExp('(^| )' + name + '=([^;]+)').exec(source)?.[2] ?? ''
package/deno.json DELETED
@@ -1,12 +0,0 @@
1
- {
2
- "name": "@yurkimus/cookies",
3
-
4
- "version": "0.0.7",
5
-
6
- "exports": "./source/index.js",
7
-
8
- "imports": {
9
- "@yurkimus/curry": "npm:@yurkimus/curry@0.1.0",
10
- "@yurkimus/types": "npm:@yurkimus/types@0.2.1"
11
- }
12
- }
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
- }
package/source/index.d.ts DELETED
@@ -1,21 +0,0 @@
1
- export let parse: (source: string) => Record<string, string>
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