14
14
* limitations under the License.
15
15
*/
16
16
17
+ /** @deprecated use IKeyAllowlist */
18
+ export type IKeyWhitelist < T > = IKeyAllowlist < T > ;
19
+ /** @deprecated use IKeyDenylist */
20
+ export type IKeyBlacklist < T > = IKeyDenylist < T > ;
21
+
17
22
// we use the empty object {} a lot in this public API
18
23
/* eslint-disable @typescript-eslint/ban-types */
19
24
20
- export interface IKeyWhitelist < T > {
25
+ export interface IKeyAllowlist < T > {
21
26
include : Array < keyof T > ;
22
27
}
23
28
24
- export interface IKeyBlacklist < T > {
29
+ export interface IKeyDenylist < T > {
25
30
exclude : Array < keyof T > ;
26
31
}
27
32
@@ -46,7 +51,7 @@ export function arraysEqual(arrA: any[], arrB: any[], compare = (a: any, b: any)
46
51
* of keys will be compared; otherwise, all keys will be compared.
47
52
* @returns true if items are equal.
48
53
*/
49
- export function shallowCompareKeys < T extends { } > ( objA : T , objB : T , keys ?: IKeyBlacklist < T > | IKeyWhitelist < T > ) {
54
+ export function shallowCompareKeys < T extends { } > ( objA : T , objB : T , keys ?: IKeyDenylist < T > | IKeyAllowlist < T > ) {
50
55
// treat `null` and `undefined` as the same
51
56
if ( objA == null && objB == null ) {
52
57
return true ;
@@ -122,7 +127,7 @@ export function getDeepUnequalKeyValues<T extends {}>(
122
127
/**
123
128
* Partial shallow comparison between objects using the given list of keys.
124
129
*/
125
- function shallowCompareKeysImpl < T > ( objA : T , objB : T , keys : IKeyBlacklist < T > | IKeyWhitelist < T > ) {
130
+ function shallowCompareKeysImpl < T > ( objA : T , objB : T , keys : IKeyDenylist < T > | IKeyAllowlist < T > ) {
126
131
return filterKeys ( objA , objB , keys ) . every ( key => {
127
132
return objA . hasOwnProperty ( key ) === objB . hasOwnProperty ( key ) && objA [ key ] === objB [ key ] ;
128
133
} ) ;
@@ -141,17 +146,17 @@ function isSimplePrimitiveType(value: any) {
141
146
return typeof value === "number" || typeof value === "string" || typeof value === "boolean" ;
142
147
}
143
148
144
- function filterKeys < T > ( objA : T , objB : T , keys : IKeyBlacklist < T > | IKeyWhitelist < T > ) {
145
- if ( isWhitelist ( keys ) ) {
149
+ function filterKeys < T > ( objA : T , objB : T , keys : IKeyDenylist < T > | IKeyAllowlist < T > ) {
150
+ if ( isAllowlist ( keys ) ) {
146
151
return keys . include ;
147
- } else if ( isBlacklist ( keys ) ) {
152
+ } else if ( isDenylist ( keys ) ) {
148
153
const keysA = Object . keys ( objA ) ;
149
154
const keysB = Object . keys ( objB ) ;
150
155
151
156
// merge keys from both objects into a big set for quick access
152
157
const keySet = arrayToObject ( keysA . concat ( keysB ) ) ;
153
158
154
- // delete blacklisted keys from the key set
159
+ // delete denied keys from the key set
155
160
keys . exclude . forEach ( key => delete keySet [ key ] ) ;
156
161
157
162
// return the remaining keys as an array
@@ -161,12 +166,12 @@ function filterKeys<T>(objA: T, objB: T, keys: IKeyBlacklist<T> | IKeyWhitelist<
161
166
return [ ] ;
162
167
}
163
168
164
- function isWhitelist < T > ( keys : any ) : keys is IKeyWhitelist < T > {
165
- return keys != null && ( keys as IKeyWhitelist < T > ) . include != null ;
169
+ function isAllowlist < T > ( keys : any ) : keys is IKeyAllowlist < T > {
170
+ return keys != null && ( keys as IKeyAllowlist < T > ) . include != null ;
166
171
}
167
172
168
- function isBlacklist < T > ( keys : any ) : keys is IKeyBlacklist < T > {
169
- return keys != null && ( keys as IKeyBlacklist < T > ) . exclude != null ;
173
+ function isDenylist < T > ( keys : any ) : keys is IKeyDenylist < T > {
174
+ return keys != null && ( keys as IKeyDenylist < T > ) . exclude != null ;
170
175
}
171
176
172
177
function arrayToObject ( arr : any [ ] ) {
0 commit comments