-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6294f87
commit 0d36ba8
Showing
7 changed files
with
58 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export { ParsedCookie, SplitStringOptions } from './interfaces'; | ||
export { parseNetscapeFile, parseNetscapeString } from './parseNetscape'; | ||
export { parseCookieString } from './parseCookie'; | ||
export { ParsedCookie, SplitStringOptions } from './interfaces'; | ||
export { serializeCookieString as serializeToCookieString } from './serializeCookie'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import { join, map, pipe } from 'ramda'; | ||
import { isArray } from 'ramda-adjunct'; | ||
|
||
import { ParsedCookie } from './interfaces'; | ||
import { cookieToNameValuePair } from './utils'; | ||
|
||
/** | ||
* Serializes a single or a `ParsedCookie` array to a separated key=value sequence like: | ||
* | ||
* ``` | ||
* 'a=b; c=d; e=f;' | ||
* ``` | ||
*/ | ||
export function serializeCookieString(cookie: ParsedCookie | ParsedCookie[]): string { | ||
return isArray(cookie) ? pipe(map(cookieToNameValuePair), join(';'))(cookie) : cookieToNameValuePair(cookie); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { serializeToCookieString } from '../src'; | ||
|
||
describe('Parse Cookie String', () => { | ||
const parsedCookies = [ | ||
{ name: 'a', value: 'b' }, | ||
{ name: 'c', value: 'd' } | ||
]; | ||
|
||
it('Should generate a valid `name=value` from ParsedCookie', () => { | ||
expect(serializeToCookieString(parsedCookies[0])).toBe('a=b'); | ||
expect(serializeToCookieString(parsedCookies[1])).toBe('c=d'); | ||
}); | ||
|
||
it('Should generate a valid `name=value` pairs from a ParsedCookie array', () => { | ||
expect(serializeToCookieString(parsedCookies)).toBe('a=b;c=d'); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters