I am currently tackling a project that involves converting a string into a JavaScript object. Despite researching various solutions and seeking answers, I have been unable to find one that addresses my specific issue.
Here's the challenge: I need to extract the content from a JS file that resembles the following structure (retrieved via a simple HTTP get request):
initiateOptions({
fullscreen: true,
showController: true,
introModal: true,
client: {
name: 'Easyfairs - Flanders Expo',
city: 'Gent',
googlePlaceId: 'xxx'
},
preloadImages: {
client: 'easyfairs_flandersexpo'
},
languages: ['EN','FR','NL'],
logo: 'images/logo_wit.png',
css: ['https://fonts.googleapis.com/css?family=PT+Sans', '/css/event-
room-card.css', '/css/easyfairs.css'],
color: '#99cc33',
explainerImage: ['media/explainerImage.png'],
/*customTexts: {
switchYes: [{ "language":"NL", "text":"Beurs" },{ "language":"EN",
"text":"Exhibition" },{ "language":"FR", "text":"Exhibition" }],
switchNo: [{ "language":"NL", "text":"Leeg" },{ "language":"EN",
"text":"Empty" },{ "language":"FR", "text":"Vide" }]
},*/
});
I need to access the data within this file by converting it into a JavaScript object for proper manipulation. The content is retrieved as a string, allowing me to remove the surrounding function using string manipulation techniques.
The structure consists of a JavaScript object enclosed within a function, which also includes commented lines. Converting this format has proven to be challenging, and while eval() might solve the issue, I prefer not to rely on it.
Is there anyone out there who can provide guidance? Thank you in advance.
PS: Due to the project's established workflow, I have limited control over its structure, necessitating adaptation to the existing format.