module.exports = function exportFlags(obj, flags) {
'use strict;';
const errorName = 'apg-exp: constructor: flags: ';
let error = null;
const readonly = {
writable: false,
enumerable: false,
configurable: true,
};
obj.flags = '';
obj.global = false;
obj.sticky = false;
obj.unicode = false;
obj.debug = false;
const TRUE = true;
while (TRUE) {
if (typeof flags === 'undefined' || flags === null) {
break;
}
if (typeof flags !== 'string') {
error = `${errorName}Invalid flags supplied to constructor: must be null, undefined or string: '${typeof flags}'`;
break;
}
if (flags === '') {
break;
}
const f = flags.toLowerCase().split('');
for (let i = 0; i < f.length; i += 1) {
switch (f[i]) {
case 'd':
obj.debug = true;
break;
case 'g':
obj.global = true;
break;
case 'u':
obj.unicode = true;
break;
case 'y':
obj.sticky = true;
break;
default:
error = `${errorName}Invalid flags supplied to constructor: '${flags}'`;
return error;
}
}
if (obj.debug) {
obj.flags += 'd';
}
if (obj.global) {
obj.flags += 'g';
}
if (obj.unicode) {
obj.flags += 'u';
}
if (obj.sticky) {
obj.flags += 'y';
}
break;
}
Object.defineProperty(obj, 'flags', readonly);
Object.defineProperty(obj, 'global', readonly);
Object.defineProperty(obj, 'debug', readonly);
Object.defineProperty(obj, 'unicode', readonly);
Object.defineProperty(obj, 'sticky', readonly);
return error;
};