Travis build: 1511
This commit is contained in:
72
README.md
72
README.md
@ -494,6 +494,7 @@ _30s.average(1, 2, 3);
|
||||
* [`isBrowser`](#isbrowser)
|
||||
* [`mostPerformant`](#mostperformant)
|
||||
* [`nthArg`](#ntharg)
|
||||
* [`objectToQueryString`](#objecttoquerystring)
|
||||
* [`parseCookie`](#parsecookie)
|
||||
* [`prettyBytes`](#prettybytes-)
|
||||
* [`randomHexColorCode`](#randomhexcolorcode)
|
||||
@ -1724,8 +1725,8 @@ const join = (arr, separator = ',', end = separator) =>
|
||||
i === arr.length - 2
|
||||
? acc + val + end
|
||||
: i === arr.length - 1
|
||||
? acc + val
|
||||
: acc + val + separator,
|
||||
? acc + val
|
||||
: acc + val + separator,
|
||||
''
|
||||
);
|
||||
```
|
||||
@ -4273,10 +4274,10 @@ const getMeridiemSuffixOfInteger = num =>
|
||||
num === 0 || num === 24
|
||||
? 12 + 'am'
|
||||
: num === 12
|
||||
? 12 + 'pm'
|
||||
: num < 12
|
||||
? (num % 12) + 'am'
|
||||
: (num % 12) + 'pm';
|
||||
? 12 + 'pm'
|
||||
: num < 12
|
||||
? (num % 12) + 'am'
|
||||
: (num % 12) + 'pm';
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -5488,11 +5489,11 @@ Throws an exception if `n` is a negative number.
|
||||
const factorial = n =>
|
||||
n < 0
|
||||
? (() => {
|
||||
throw new TypeError('Negative numbers are not allowed!');
|
||||
})()
|
||||
throw new TypeError('Negative numbers are not allowed!');
|
||||
})()
|
||||
: n <= 1
|
||||
? 1
|
||||
: n * factorial(n - 1);
|
||||
? 1
|
||||
: n * factorial(n - 1);
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -6703,8 +6704,8 @@ const deepClone = obj => {
|
||||
return Array.isArray(obj) && obj.length
|
||||
? (clone.length = obj.length) && Array.from(clone)
|
||||
: Array.isArray(obj)
|
||||
? Array.from(obj)
|
||||
: clone;
|
||||
? Array.from(obj)
|
||||
: clone;
|
||||
};
|
||||
```
|
||||
|
||||
@ -6792,13 +6793,13 @@ const deepMapKeys = (obj, f) =>
|
||||
Array.isArray(obj)
|
||||
? obj.map(val => deepMapKeys(val, f))
|
||||
: typeof obj === 'object'
|
||||
? Object.keys(obj).reduce((acc, current) => {
|
||||
? Object.keys(obj).reduce((acc, current) => {
|
||||
const val = obj[current];
|
||||
acc[f(current)] =
|
||||
val !== null && typeof val === 'object' ? deepMapKeys(val, f) : (acc[f(current)] = val);
|
||||
return acc;
|
||||
}, {})
|
||||
: obj;
|
||||
: obj;
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -6869,9 +6870,9 @@ const dig = (obj, target) =>
|
||||
target in obj
|
||||
? obj[target]
|
||||
: Object.values(obj).reduce((acc, val) => {
|
||||
if (acc !== undefined) return acc;
|
||||
if (typeof val === 'object') return dig(val, target);
|
||||
}, undefined);
|
||||
if (acc !== undefined) return acc;
|
||||
if (typeof val === 'object') return dig(val, target);
|
||||
}, undefined);
|
||||
```
|
||||
|
||||
<details>
|
||||
@ -7127,8 +7128,7 @@ Otherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes(
|
||||
const hasKey = (obj, key) => {
|
||||
if (key.includes('.')) {
|
||||
let _key = key.split('.')[0];
|
||||
if (typeof obj[_key] === 'object')
|
||||
return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));
|
||||
if (typeof obj[_key] === 'object') return hasKey(obj[_key], key.slice(key.indexOf('.') + 1));
|
||||
}
|
||||
return Object.keys(obj).includes(key);
|
||||
};
|
||||
@ -7139,7 +7139,9 @@ const hasKey = (obj, key) => {
|
||||
|
||||
```js
|
||||
let obj = {
|
||||
a: 1, b: { c: 4 }, 'd.e': 5
|
||||
a: 1,
|
||||
b: { c: 4 },
|
||||
'd.e': 5
|
||||
};
|
||||
hasKey(obj, 'a'); // true
|
||||
hasKey(obj, 'b'); // true
|
||||
@ -9366,6 +9368,36 @@ last(1, 2, 3, 4, 5); // 5
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### objectToQueryString
|
||||
|
||||
Returns a query string generated from the key-value pairs of the given object.
|
||||
|
||||
Use `Array.prototype.reduce()` on `Object.entries(queryParameters)` to create the query string.
|
||||
Determine the `symbol` to be either `?` or `&` based on the `index` and concatenate `val` to `queryString` only if it's a string.
|
||||
Return the `queryString` or an empty string when the `queryParameters` are falsy.
|
||||
|
||||
```js
|
||||
const objectToQueryString = queryParameters => {
|
||||
return queryParameters
|
||||
? Object.entries(queryParameters).reduce((queryString, [key, val], index) => {
|
||||
const symbol = index === 0 ? '?' : '&';
|
||||
queryString += (typeof val === 'string') ? `${symbol}${key}=${val}` : '';
|
||||
return queryString;
|
||||
}, '')
|
||||
: '';
|
||||
};
|
||||
```
|
||||
|
||||
<details>
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
objectToQueryString({page: '1', size: '2kg', key: undefined}); // '?page=1&size=2kg'
|
||||
```
|
||||
</details>
|
||||
|
||||
<br>[⬆ Back to top](#contents)
|
||||
|
||||
### parseCookie
|
||||
|
||||
Parse an HTTP Cookie header string and return an object of all cookie name-value pairs.
|
||||
|
||||
Reference in New Issue
Block a user