-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: move kind helpers to internal.
- Loading branch information
Showing
4 changed files
with
51 additions
and
36 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/** | ||
* Internal use only. These functions should only be used as part of the initial validation of | ||
* the LDContext object. Thereafter, the Context object should be used. | ||
*/ | ||
import type { LDContext, LDMultiKindContext, LDSingleKindContext, LDUser } from '../../api'; | ||
import { TypeValidators } from '../../validators'; | ||
|
||
/** | ||
* Check if a context is a single kind context. | ||
* @param context | ||
* @returns true if the context is a single kind context. | ||
*/ | ||
export function isSingleKind(context: LDContext): context is LDSingleKindContext { | ||
if ('kind' in context) { | ||
return TypeValidators.String.is(context.kind) && context.kind !== 'multi'; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Check if a context is a multi-kind context. | ||
* @param context | ||
* @returns true if it is a multi-kind context. | ||
*/ | ||
export function isMultiKind(context: LDContext): context is LDMultiKindContext { | ||
if ('kind' in context) { | ||
return TypeValidators.String.is(context.kind) && context.kind === 'multi'; | ||
} | ||
return false; | ||
} | ||
|
||
/** | ||
* Check if a context is a legacy user context. | ||
* @param context | ||
* @returns true if it is a legacy user context. | ||
*/ | ||
export function isLegacyUser(context: LDContext): context is LDUser { | ||
return !('kind' in context) || context.kind === null || context.kind === undefined; | ||
} |
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
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