What is the process for assigning a regular expression to an object?

As I work on editing a configuration file, I'm encountering some issues where things aren't quite functioning as expected.

Below is the code snippet I am working with:

config.module.rules.unshift( {
        test: "/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/",
        use: [ 'raw-loader' ]
    }
);


fs.writeFileSync("C:\\temp\\config.txt", JSON.stringify(config) );

This results in a file that contains the following content...

{
    "test": "/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+.svg$/",
    "use": [
            "raw-loader"
           ]
},

However, the value for "test" appears to be incorrect. I want it to be set as follows:

{
    test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
    use: [ 'raw-loader' ]
}

It's important to note that there are no quotes around the regular expression string in the desired output.

If I attempt to utilize the modified code like this:

config.module.rules.unshift( {
        test: /ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/,
        use: [ 'raw-loader' ]
    }
);


fs.writeFileSync("C:\\temp\\config.txt", JSON.stringify(config) );

Here's the result I end up with instead:

{
    "test": {},
    "use": [ "raw-loader" ]
},

To achieve the correct outcome, I need the value of test to be:

/ckeditor5-[^/\\]+[/\\]theme[/\\]icons[/\\][^/\\]+\.svg$/

Answer №1

I seem to be heading in the wrong direction. Many individuals have mentioned that the JSON Serialiser is altering the result to {}, rather than the expected value. Upon inspecting the object closely, it appears to be correctly configured.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating a Delicious Earth Progress Pie

I'm looking to incorporate a unique progress bar design on my website, similar to this one: The progress pie Can anyone guide me on how to create a progress pie with an image inside it that changes color as it moves? ...

Python HDFS: File cannot be read

Having some trouble reading a file from hdfds with Python: from hdfs.client import Client import json,requests if __name__ == '__main__': cl = Client("http://hostName:port") print cl.list("/myDir/") with cl.read("/myDir/myFile.json") ...

Tips for editing bootstrap-vue table columns using non-Latin characters?

I need to create a table using the Cyrillic alphabet, but the keys of the object must be in the Latin alphabet within the program. Example : export default { data() { return { wmsFields: ['№', 'Наименование', ...

Implementing a keypress function that can handle duplicate names

HTML <input name="pm" type="text" value="0"/> <input name="pm" type="text" value="0"/> <input name="pm" type="text" value="0"/> <input name="total" type="text" value="0" disabled="disabled"/> Javascript $('[name="pm"]' ...

How can I include a query parameter in a Rails API GET request?

I'm currently working on a project with a basic Item model where both "/items" and "/items.json" are functioning properly. However, I am now looking to enhance the API by adding a search parameter like "/items.json?skuid=123" so that only Items with t ...

Encountering a Console warning while working with the Material UI menu. Seeking advice on how to resolve this issue as I am integrating HTML within a text

Caution: PropType validation failed. The prop text provided to LinkMenuItem is invalid as it should be a string, not an object. Please review the render method of Menu. Below is the code snippet: var menuItems = [ // text is not valid text { route: &ap ...

Adjusting the color of a value in justGage requires a few simple steps to

Is it possible to modify the color and design of the text in the Value parameter of justGage after creating the gauge? My goal is to change the text color to blue with an underline to give it a link-like appearance. Appreciate your assistance. ...

Retrieve the value of a JSONObject from a JSON data structure

I have the JSON data below: { "TestMetrics": { "ProcessPID": "7887", "MemSwapped": "0", "Uptime": "407", "webTiming": "{\"domainLookupStart\":3,\"domainLookupEnd\":67}" } } My goal is to e ...

How can I upload a folder with subfolders and keep the structure intact?

I'm working on a form that allows me to upload a folder containing both files and subfolders with more files inside. I managed to upload the folder successfully, but when I check my directory, all the files are in one folder without the subfolders. My ...

I am unable to utilize the Web Share API for sharing a file within my React app written in TypeScript

Trying to launch a WebApp for sharing files has been quite a challenge. After some thorough research, I stumbled upon the Web Share API which seemed like the perfect solution based on standard practices. The documentation provided a clear outline of how it ...

Utilizing variables effectively in Ansible for URI requests

Currently facing an issue with replacing values and creating a json template in ansible for sending via the uri module to a webserver. Seeking assistance from anyone who can help? It appears that ansible is converting all double brackets in the json to si ...

Executing program through Socket.io alert

My NodeJS server sends notifications to clients when certain actions are performed, such as deleting a row from a grid. Socket.io broadcasts this information to all connected clients. In the example of deleting a row, one approach could be adding an `acti ...

The TypeScript inference feature is not functioning correctly

Consider the following definitions- I am confused why TypeScript fails to infer the types correctly. If you have a solution, please share! Important Notes: * Ensure that the "Strict Null Check" option is enabled. * The code includes c ...

Verify whether the number begins with 0 or 00

Could someone please help me figure out how to use regex to determine if a number starts with 0 or 00? I attempted it but I am new to regex: preg_match("/^[0][0-9]+$/", $number) ...

Verify the value of the variable matches the key of the JavaScript object array and retrieve the corresponding value

array = { event: [{ key: "value", lbl: "value" }], event1: [{ key: "value", lbl: "value" }] var variable; if(variable in array){ //need to handle this case } I am looking for a function that takes the name of an ar ...

Creating Effective Links from Names

I am currently working on a project that involves generating proper links from proper names... For instance: T & J Automotive is being generated as /t-j-automotive However, I am facing an issue when trying to convert the link back to the original nam ...

What are the steps to automatically populate the location or name in the trip advisor widget?

I have encountered an issue with my website where I have multiple hotel lists but the trip advisor widget only shows one. Is there a solution, such as a script or other method, that can use variables to automatically set the location or name in the widget? ...

Ensuring Uniform Data Types Across Objects (Using Typescript)

After much trial and error, I have finally reached this point where everything seems to be working perfectly. function test<types extends Record<string,any>>(dict: dictionary<types>){} type dictionary<types extends Record<string, a ...

Mastering the utilization of API routes within the Next JS 13 App Router framework

As a newcomer to React JS and Next.js, I recently made the switch from using the Page Router API in Next.js to utilizing the new App Router introduced in Next.js 13. Previously, with the Page Router, creating a single GET request involved nesting your "JS ...

Tips for Ensuring a JavaScript Contact Form Submits Successfully

Snippet of HTML Code for Contact Form: Contact Me <label for="Name">Name:</label> <input type="text" name="name" id="Name" accesskey="N" tabindex="1"> ...