2018-03-05 18:58:53 +00:00
|
|
|
import qs from 'query-string';
|
2018-01-02 18:04:50 +00:00
|
|
|
import has from 'lodash/has';
|
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
interface IObjectValue {
|
|
|
|
[key: string]: any;
|
|
|
|
}
|
|
|
|
|
|
|
|
export function objectContainsObjectKeys(
|
|
|
|
checkingObject: IObjectValue,
|
|
|
|
containingObject: IObjectValue
|
|
|
|
) {
|
2018-01-02 18:04:50 +00:00
|
|
|
const checkingObjectKeys = Object.keys(checkingObject);
|
|
|
|
const containsAll = checkingObjectKeys.map(key => has(containingObject, key));
|
|
|
|
return containsAll.every(isTrue => isTrue);
|
|
|
|
}
|
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
export function getKeyByValue(object: IObjectValue, value: any) {
|
2017-09-26 23:03:38 +00:00
|
|
|
return Object.keys(object).find(key => object[key] === value);
|
|
|
|
}
|
2017-10-11 05:04:49 +00:00
|
|
|
|
|
|
|
export function getParam(query: { [key: string]: string }, key: string) {
|
|
|
|
const keys = Object.keys(query);
|
|
|
|
const index = keys.findIndex(k => k.toLowerCase() === key.toLowerCase());
|
|
|
|
if (index === -1) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return query[keys[index]];
|
|
|
|
}
|
|
|
|
|
2018-03-05 18:58:53 +00:00
|
|
|
export function getParamFromURL(url: string, param: string): string | undefined {
|
|
|
|
return qs.parse(qs.extract(url))[param];
|
|
|
|
}
|
|
|
|
|
2017-10-11 05:04:49 +00:00
|
|
|
export function isPositiveInteger(n: number) {
|
|
|
|
return Number.isInteger(n) && n > 0;
|
|
|
|
}
|
2018-01-20 20:06:28 +00:00
|
|
|
|
2018-03-07 23:36:05 +00:00
|
|
|
export const getValues = (...args: any[]) =>
|
2018-01-20 20:06:28 +00:00
|
|
|
args.reduce((acc, currArg) => [...acc, ...Object.values(currArg)], []);
|