@nordcraft/core 1.0.17 → 1.0.19

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.
@@ -8,3 +8,8 @@ export declare const isTextHeader: (header?: string | null) => boolean;
8
8
  export declare const isEventStreamHeader: (header?: string | null) => boolean;
9
9
  export declare const isJsonStreamHeader: (header?: string | null) => boolean;
10
10
  export declare const isImageHeader: (header?: string | null) => boolean;
11
+ /**
12
+ * Returns an object with headers from a Headers object
13
+ * Duplicate header values (set-cookie for instance) are encoded as a comma-separated string
14
+ */
15
+ export declare const mapHeadersToObject: (headers: Headers) => Record<string, string>;
@@ -33,4 +33,20 @@ export const isImageHeader = (header) => {
33
33
  }
34
34
  return /^image\//.test(header);
35
35
  };
36
+ /**
37
+ * Returns an object with headers from a Headers object
38
+ * Duplicate header values (set-cookie for instance) are encoded as a comma-separated string
39
+ */
40
+ export const mapHeadersToObject = (headers) => {
41
+ const headersObject = {};
42
+ for (const [key, value] of headers.entries()) {
43
+ if (headersObject[key]) {
44
+ headersObject[key] += `, ${value}`;
45
+ }
46
+ else {
47
+ headersObject[key] = value;
48
+ }
49
+ }
50
+ return headersObject;
51
+ };
36
52
  //# sourceMappingURL=headers.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"headers.js","sourceRoot":"","sources":["../../src/api/headers.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAsB,EAAE,EAAE;IACrD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;IACD,OAAO,+BAA+B,CAAC,IAAI,CAAC,MAAM,CAAC,CAAA;AACrD,CAAC,CAAA;AAED,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,MAAsB,EAAE,EAAE;IACrD,IAAI,OAAO,MAAM,KAAK,QAAQ,EAAE,CAAC;QAC/B,OAAO,KAAK,CAAA;IACd,CAAC;IAC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ependencies": {
7
- "@types/react": "19.1.5"
7
+ "@types/react": "19.1.6"
8
8
  },
9
9
  "scripts": {
10
10
  "build": "tsc",
@@ -14,5 +14,5 @@
14
14
  },
15
15
  "files": ["dist", "src"],
16
16
  "main": "dist/index.js",
17
- "version": "1.0.17"
17
+ "version": "1.0.19"
18
18
  }
@@ -1,4 +1,4 @@
1
- import { describe, expect, it, test } from '@jest/globals'
1
+ import { describe, expect, it, test } from 'bun:test'
2
2
  import { valueFormula } from '../formula/formulaUtils'
3
3
  import {
4
4
  createApiRequest,
@@ -0,0 +1,17 @@
1
+ import { mapHeadersToObject } from './headers'
2
+
3
+ describe('mapHeadersToObject()', () => {
4
+ test('it maps Headers to a plain object', () => {
5
+ const headers = mapHeadersToObject(
6
+ new Headers([
7
+ ['accept', 'application/json'],
8
+ ['origin', 'my.origin.com'],
9
+ ['set-cookie', 'sessionId=12345'],
10
+ ['set-cookie', 'userId=67890'],
11
+ ]),
12
+ )
13
+ expect(headers['accept']).toEqual('application/json')
14
+ expect(headers['origin']).toEqual('my.origin.com')
15
+ expect(headers['set-cookie']).toBe('sessionId=12345, userId=67890')
16
+ })
17
+ })
@@ -39,3 +39,19 @@ export const isImageHeader = (header?: string | null) => {
39
39
  }
40
40
  return /^image\//.test(header)
41
41
  }
42
+
43
+ /**
44
+ * Returns an object with headers from a Headers object
45
+ * Duplicate header values (set-cookie for instance) are encoded as a comma-separated string
46
+ */
47
+ export const mapHeadersToObject = (headers: Headers) => {
48
+ const headersObject: Record<string, string> = {}
49
+ for (const [key, value] of headers.entries()) {
50
+ if (headersObject[key]) {
51
+ headersObject[key] += `, ${value}`
52
+ } else {
53
+ headersObject[key] = value
54
+ }
55
+ }
56
+ return headersObject
57
+ }
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from '@jest/globals'
1
+ import { describe, expect, test } from 'bun:test'
2
2
  import crypto from 'crypto'
3
3
  import { deepSortObject } from './collections'
4
4
  import { sha1, stableStringify } from './sha1'
@@ -1,4 +1,4 @@
1
- import { describe, expect, test } from '@jest/globals'
1
+ import { describe, expect, test } from 'bun:test'
2
2
  import { validateUrl } from './url'
3
3
 
4
4
  describe('validateUrl()', () => {