Travis build: 1226
This commit is contained in:
55
README.md
55
README.md
@ -344,9 +344,11 @@ average(1, 2, 3);
|
|||||||
* [`hexToRGB`](#hextorgb-)
|
* [`hexToRGB`](#hextorgb-)
|
||||||
* [`httpGet`](#httpget)
|
* [`httpGet`](#httpget)
|
||||||
* [`httpPost`](#httppost)
|
* [`httpPost`](#httppost)
|
||||||
|
* [`parseCookie`](#parsecookie)
|
||||||
* [`prettyBytes`](#prettybytes)
|
* [`prettyBytes`](#prettybytes)
|
||||||
* [`randomHexColorCode`](#randomhexcolorcode)
|
* [`randomHexColorCode`](#randomhexcolorcode)
|
||||||
* [`RGBToHex`](#rgbtohex)
|
* [`RGBToHex`](#rgbtohex)
|
||||||
|
* [`serializeCookie`](#serializecookie)
|
||||||
* [`timeTaken`](#timetaken)
|
* [`timeTaken`](#timetaken)
|
||||||
* [`toDecimalMark`](#todecimalmark)
|
* [`toDecimalMark`](#todecimalmark)
|
||||||
* [`toOrdinalSuffix`](#toordinalsuffix)
|
* [`toOrdinalSuffix`](#toordinalsuffix)
|
||||||
@ -5588,6 +5590,37 @@ Logs: {
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### parseCookie
|
||||||
|
|
||||||
|
Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
|
||||||
|
|
||||||
|
Use `String.split(';')` to separate key-value pairs from each other.
|
||||||
|
Use `Array.map()` and `String.split('=')` to separate keys from values in each pair.
|
||||||
|
Use `Array.reduce()` and `decodeURIComponent()` to create an object with all key-value pairs.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const parseCookie = str =>
|
||||||
|
str
|
||||||
|
.split(';')
|
||||||
|
.map(v => v.split('='))
|
||||||
|
.reduce((acc, v) => {
|
||||||
|
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
parseCookie('foo=bar; equation=E%3Dmc%5E2'); // { foo: 'bar', equation: 'E=mc^2' }
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### prettyBytes
|
### prettyBytes
|
||||||
|
|
||||||
Converts a number in bytes to a human-readable string.
|
Converts a number in bytes to a human-readable string.
|
||||||
@ -5669,6 +5702,28 @@ RGBToHex(255, 165, 1); // 'ffa501'
|
|||||||
<br>[⬆ Back to top](#table-of-contents)
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
|
### serializeCookie
|
||||||
|
|
||||||
|
Serialize a cookie name-value pair into a Set-Cookie header string.
|
||||||
|
|
||||||
|
Use template literals and `encodeURIComponent()` to create the appropriate string.
|
||||||
|
|
||||||
|
```js
|
||||||
|
const serializeCookie = (name, val) => `${encodeURIComponent(name)}=${encodeURIComponent(val)}`;
|
||||||
|
```
|
||||||
|
|
||||||
|
<details>
|
||||||
|
<summary>Examples</summary>
|
||||||
|
|
||||||
|
```js
|
||||||
|
serializeCookie('foo', 'bar'); // 'foo=bar'
|
||||||
|
```
|
||||||
|
|
||||||
|
</details>
|
||||||
|
|
||||||
|
<br>[⬆ Back to top](#table-of-contents)
|
||||||
|
|
||||||
|
|
||||||
### timeTaken
|
### timeTaken
|
||||||
|
|
||||||
Measures the time taken by a function to execute.
|
Measures the time taken by a function to execute.
|
||||||
|
|||||||
File diff suppressed because one or more lines are too long
@ -8,7 +8,13 @@ Use `Array.reduce()` and `decodeURIComponent()` to create an object with all key
|
|||||||
|
|
||||||
```js
|
```js
|
||||||
const parseCookie = str =>
|
const parseCookie = str =>
|
||||||
str.split(';').map(v => v.split('=')).reduce((acc,v) => {acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim()); return acc},{});
|
str
|
||||||
|
.split(';')
|
||||||
|
.map(v => v.split('='))
|
||||||
|
.reduce((acc, v) => {
|
||||||
|
acc[decodeURIComponent(v[0].trim())] = decodeURIComponent(v[1].trim());
|
||||||
|
return acc;
|
||||||
|
}, {});
|
||||||
```
|
```
|
||||||
|
|
||||||
```js
|
```js
|
||||||
|
|||||||
Reference in New Issue
Block a user