baseframe-js
Version:
Baseframe JS is a comprehensive suite of modular plugins and utilities designed for front-end development
14 lines (13 loc) • 547 B
JavaScript
const parseObjectFromString = (options) => {
let retObj = {};
if (typeof options === 'string') {
retObj = JSON.parse(options.replace(/:\s*"([^"]*)"/g, function (match, p1) {
return ': "' + p1.replace(/:/g, '@colon@') + '"';
}).replace(/:\s*'([^']*)'/g, function (match, p1) {
return ': "' + p1.replace(/:/g, '@colon@') + '"';
}).replace(/(['"])?([a-z0-9A-Z_]+)(['"])?\s*:/g, '"$2": ')
.replace(/@colon@/g, ':'));
}
return retObj;
};
export default parseObjectFromString;