@blinkk/editor
Version:
Structured content editor with live previews.
77 lines • 2.29 kB
JavaScript
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.FeatureManager = void 0;
const dataType_1 = require("@blinkk/selective-edit/dist/src/utility/dataType");
class FeatureManager {
constructor(config) {
this.config = config;
this.features = {};
this.internalSettings = {};
}
/**
* Determine if a feature is turned off.
*
* @param featureKey Key to represent the feature.
* @returns True if the feature is off or the default is off.
*/
isOff(featureKey) {
return !this.isOn(featureKey);
}
/**
* Determine if a feature is turned on.
*
* @param featureKey Key to represent the feature.
* @returns True if the feature is on or the default is on.
*/
isOn(featureKey) {
if (featureKey in this.features) {
return Boolean(this.features[featureKey]);
}
return this.config.defaultStatus;
}
/**
* Turn a feature off.
*
* @param featureKey Key to represent the feature.
* @returns false
*/
off(featureKey, settings) {
this.features[featureKey] = false;
if (settings) {
this.internalSettings[featureKey] = settings;
return settings;
}
return this.features[featureKey];
}
/**
* Turn a feature on.
*
* @param featureKey Key to represent the feature.
* @returns true
*/
on(featureKey, settings) {
this.features[featureKey] = true;
if (settings) {
this.internalSettings[featureKey] = settings;
return settings;
}
return this.features[featureKey];
}
set(featureKey, value) {
this.features[featureKey] = Boolean(value);
if (dataType_1.DataType.isObject(value)) {
this.internalSettings[featureKey] = value;
return this.internalSettings[featureKey];
}
return this.features[featureKey];
}
settings(featureKey) {
if (featureKey in this.internalSettings) {
return this.internalSettings[featureKey];
}
// Default to no settings.
return undefined;
}
}
exports.FeatureManager = FeatureManager;
//# sourceMappingURL=featureManager.js.map