Last active
September 26, 2018 11:57
-
-
Save lancetw/80f98935e4387d0bc7128db9e07f1027 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let user = new User(filterByProps(form, [ | |
'username', | |
'displayname' | |
])) | |
function filterByProps(obj: any, props: string[]): any { | |
if (!props) return obj | |
let ret = {} | |
Object.keys(obj).forEach(key => { | |
if (props.some(prop => prop === key)) { | |
ret[key] = clone(obj[key]) | |
} | |
}) | |
return ret | |
} | |
export interface user { | |
username: email | username | |
firstname?: string | |
lastname?: string | |
displayname?: string | |
} | |
export class User implements user { | |
username: email | username | |
firstname?: string | |
lastname?: string | |
displayname?: string | |
constructor(user?: user) { | |
Object.assign(this, user) | |
} | |
} | |
export function clone(obj: any): any { | |
return JSON.parse(JSON.stringify(obj)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment