2023-05-19 16:53:55 +00:00
|
|
|
/**
|
|
|
|
* Internal dependencies
|
|
|
|
*/
|
|
|
|
import { getAdminSetting } from '../admin-settings';
|
|
|
|
import { Feature } from './types';
|
|
|
|
|
|
|
|
const ADMIN_SETTINGS_FEATURES_NAME = 'features';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get the feature flag from admin settings.
|
|
|
|
*
|
2023-08-29 22:40:45 +00:00
|
|
|
* @param featureId The feature id
|
2023-05-19 16:53:55 +00:00
|
|
|
* @return The feature flag
|
|
|
|
*/
|
|
|
|
export function getFeature( featureId: string ): Feature | undefined {
|
|
|
|
const features = getAdminSetting( ADMIN_SETTINGS_FEATURES_NAME );
|
|
|
|
return features && features[ featureId ];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the feature is enabled.
|
|
|
|
*
|
2023-08-29 22:40:45 +00:00
|
|
|
* @param featureId The feature id
|
2023-05-19 16:53:55 +00:00
|
|
|
* @return `true` or `false` if the given feature is enabled
|
|
|
|
*/
|
|
|
|
export function isFeatureEnabled( featureId: string ): boolean {
|
|
|
|
const feature = getFeature( featureId );
|
|
|
|
return Boolean( feature?.is_enabled );
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns if the feature is experimental.
|
|
|
|
*
|
2023-08-29 22:40:45 +00:00
|
|
|
* @param featureId The feature id
|
2023-05-19 16:53:55 +00:00
|
|
|
* @return `true` or `false` if the given feature is experimental
|
|
|
|
*/
|
|
|
|
export function isFeatureExperimental( featureId: string ): boolean {
|
|
|
|
const feature = getFeature( featureId );
|
|
|
|
return Boolean( feature?.is_experimental );
|
|
|
|
}
|