18 lines
No EOL
528 B
TypeScript
18 lines
No EOL
528 B
TypeScript
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
|
// See LICENSE.txt for license information.
|
|
|
|
export default function keyMirror<T extends {}>(obj: T): { [K in keyof T]: K } {
|
|
if (!(obj instanceof Object && !Array.isArray(obj))) {
|
|
throw new Error('keyMirror(...): Argument must be an object.');
|
|
}
|
|
|
|
const ret: any = {};
|
|
for (const key in obj) {
|
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
continue;
|
|
}
|
|
|
|
ret[key] = key;
|
|
}
|
|
return ret;
|
|
} |