Travis build: 1516
This commit is contained in:
79
README.md
79
README.md
@ -1725,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,
|
||||
''
|
||||
);
|
||||
```
|
||||
@ -4274,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>
|
||||
@ -5489,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>
|
||||
@ -6704,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;
|
||||
};
|
||||
```
|
||||
|
||||
@ -6793,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>
|
||||
@ -6870,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>
|
||||
@ -7120,17 +7120,19 @@ get(obj, 'selector.to.val', 'target[0]', 'target[2].a'); // ['val to select', 1,
|
||||
|
||||
Returns `true` if the target value exists in a JSON object, `false` otherwise.
|
||||
|
||||
Check if the key contains `.`, use `String.prototype.split('.')[0]` to get the first part and store as `_key`.
|
||||
Use `typeof` to check if the contents of `obj[key]` are an `object` and, if so, call `hasKey` with that object and the remainder of the `key`.
|
||||
Otherwise, use `Object.keys(obj)` in combination with `Array.prototype.includes()` to check if the given `key` exists.
|
||||
Check if `keys` is non-empty and use `Array.prototype.every()` to sequentially check its keys to internal depth of the object, `obj`.
|
||||
Use `Object.prototype.hasOwnProperty()` to check if `obj` does not have the current key or is not an object, stop propagation and return `false`.
|
||||
Otherwise assign the key's value to `obj` to use on the next iteration.
|
||||
|
||||
Return `false` beforehand if given key list is empty.
|
||||
|
||||
```js
|
||||
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));
|
||||
}
|
||||
return Object.keys(obj).includes(key);
|
||||
const hasKey = (obj, keys) => {
|
||||
return (keys.length > 0) && keys.every(key => {
|
||||
if (typeof obj !== 'object' || !obj.hasOwnProperty(key)) return false;
|
||||
obj = obj[key];
|
||||
return true;
|
||||
});
|
||||
};
|
||||
```
|
||||
|
||||
@ -7141,14 +7143,15 @@ const hasKey = (obj, key) => {
|
||||
let obj = {
|
||||
a: 1,
|
||||
b: { c: 4 },
|
||||
'd.e': 5
|
||||
'b.d': 5
|
||||
};
|
||||
hasKey(obj, 'a'); // true
|
||||
hasKey(obj, 'b'); // true
|
||||
hasKey(obj, 'b.c'); // true
|
||||
hasKey(obj, 'd.e'); // true
|
||||
hasKey(obj, 'd'); // false
|
||||
hasKey(obj, 'f'); // false
|
||||
hasKey(obj, ['a']); // true
|
||||
hasKey(obj, ['b']); // true
|
||||
hasKey(obj, ['b', 'c']); // true
|
||||
hasKey(obj, ['b.d']); // true
|
||||
hasKey(obj, ['d']); // false
|
||||
hasKey(obj, ['c']); // false
|
||||
hasKey(obj, ['b', 'f']); // false
|
||||
```
|
||||
</details>
|
||||
|
||||
@ -9380,10 +9383,10 @@ Return the `queryString` or an empty string when the `queryParameters` are falsy
|
||||
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;
|
||||
}, '')
|
||||
const symbol = index === 0 ? '?' : '&';
|
||||
queryString += typeof val === 'string' ? `${symbol}${key}=${val}` : '';
|
||||
return queryString;
|
||||
}, '')
|
||||
: '';
|
||||
};
|
||||
```
|
||||
@ -9392,7 +9395,7 @@ const objectToQueryString = queryParameters => {
|
||||
<summary>Examples</summary>
|
||||
|
||||
```js
|
||||
objectToQueryString({page: '1', size: '2kg', key: undefined}); // '?page=1&size=2kg'
|
||||
objectToQueryString({ page: '1', size: '2kg', key: undefined }); // '?page=1&size=2kg'
|
||||
```
|
||||
</details>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user