-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathindex.ts
More file actions
39 lines (34 loc) · 1.28 KB
/
index.ts
File metadata and controls
39 lines (34 loc) · 1.28 KB
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
import SplitIO from '../../../types/splitio';
import { ISettings } from '../../types';
import { isObject } from '../lang';
// function isSplitKeyObject(key: any): key is SplitIO.SplitKeyObject {
// return key !== undefined && key !== null && typeof key.matchingKey === 'string';
// }
// returns the matchingKey if the Key is defined as an object or the key itself if it is a string
export function getMatching(key: SplitIO.SplitKey): string {
return isObject(key) ? (key as SplitIO.SplitKeyObject).matchingKey : key as string;
}
// if the key is a string, there's no bucketingKey (undefined)
export function getBucketing(key: SplitIO.SplitKey): string | undefined {
return isObject(key) ? (key as SplitIO.SplitKeyObject).bucketingKey : undefined;
}
/**
* Verify type of key and return a valid object key used for get treatment for a
* specific split.
*/
export function keyParser(key: SplitIO.SplitKey): SplitIO.SplitKeyObject {
if (isObject(key)) {
return {
matchingKey: (key as SplitIO.SplitKeyObject).matchingKey,
bucketingKey: (key as SplitIO.SplitKeyObject).bucketingKey
};
} else {
return {
matchingKey: key as string,
bucketingKey: key as string
};
}
}
export function checkIfServerSide(settings: ISettings) {
return !settings.core.key;
}