@tdb/util
Version:
Shared helpers and utilities.
18 lines (17 loc) • 428 B
text/typescript
/**
* Converts the cookies into a simple object of
* property functions only.
*/
export function toObject<T>(obj: object, ctx?: any) {
const result = {};
Object.keys(obj)
.map(key => ({ key, prop: obj[key] }))
.filter(({ prop }) => prop.isProp)
.forEach(({ key, prop }) => {
const value = prop(undefined, { ctx });
if (value) {
result[key] = value;
}
});
return result as T;
}