forked from microsoft/BotFramework-WebChat
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathdeprecateObject.ts
More file actions
40 lines (36 loc) · 946 Bytes
/
Copy pathdeprecateObject.ts
File metadata and controls
40 lines (36 loc) · 946 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import warnOnce from './warnOnce';
const PROPERTY_DENYLIST = new Set<string | symbol>([
'__defineGetter__',
'__defineSetter__',
'__lookupGetter__',
'__lookupSetter__',
'__proto__',
'constructor',
'hasOwnProperty',
'isPrototypeOf',
'propertyIsEnumerable',
'prototype',
'toString',
'valueOf'
]);
export default function deprecateNamespace<T extends { [key: string | symbol]: any }>(
namespace: T,
message: string
): T {
const warnDeprecation = warnOnce(message);
return new Proxy<T>(namespace, {
get(target, p) {
if (
!PROPERTY_DENYLIST.has(p) &&
(typeof p === 'string'
? Object.getOwnPropertyNames(target).includes(p)
: Object.getOwnPropertySymbols(target).includes(p))
) {
warnDeprecation(p);
// Only can get own properties.
// eslint-disable-next-line security/detect-object-injection
return target[p];
}
}
});
}