react-native-efilli-sdk
Version:
Efilli SDK for React Native - Consent Management Solution
50 lines (49 loc) • 1.51 kB
JavaScript
// src/models/Categories.tsx
Object.defineProperty(exports, "__esModule", { value: true });
exports.Categories = void 0;
/**
* Categories model representing the various consent categories that can be granted or denied
*/
class Categories {
/**
* Create a Categories instance
*/
constructor(essential = true, functional = false, marketing = false, other = false) {
this.essential = essential;
this.functional = functional;
this.marketing = marketing;
this.other = other;
}
/**
* Create a Categories instance from a plain object or JSON string
*/
static fromJSON(data) {
if (typeof data === 'string') {
try {
data = JSON.parse(data);
}
catch (e) {
console.error('Failed to parse Categories JSON:', e);
return new Categories();
}
}
if (!data || typeof data !== 'object') {
return new Categories();
}
const typedData = data;
return new Categories(typedData.essential === undefined ? true : !!typedData.essential, !!typedData.functional, !!typedData.marketing, !!typedData.other);
}
/**
* Convert to a plain object
*/
toJSON() {
return {
essential: this.essential,
functional: this.functional,
marketing: this.marketing,
other: this.other
};
}
}
exports.Categories = Categories;
;