change stroke-dashoffset base on data attribute

I have 3 circles with an svg i’m trying to change the stroke-dashoffset base on the data attribute data-num to have different size of circle that match the value of data-num

I’m trying the code below but the value of stroke-dashoffset donesn’t change

How can i make this and keep the animation for the circle?

const numbers = document.querySelectorAll('.number');
const svgEl = document.querySelectorAll('svg circle');
const counters = Array(numbers.length);
const intervals = Array(counters.length);
counters.fill(0);

numbers.forEach((number, index) => {
    intervals[index] = setInterval(() => {
        if(counters[index] === parseInt(number.dataset.num)){
            clearInterval(counters[index]);
        }else{
            counters[index] += 1;
            number.innerHTML = counters[index] + "%";
            svgEl[index].style.strokeDashoffset = 472 - 472 * parseInt(number.dataset.num / 100);
        }
    }, 20)
})
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-size: 16px;
}

.skill-container {
    height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
}

.skill-container .skill {
    position: relative;
    margin-right: 40px;
}

.skill-container .skill .outer {
    height: 160px;
    width: 160px;
    border-radius: 50%;
    padding: 20px;
    box-shadow: 6px 6px 10px -1px rgba(0 0 0 /.15), -6px -6px 10px -1px rgba(255 255 255 / .7);
}

.skill-container .skill .outer .inner {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 120px;
    width: 120px;
    border-radius: 50%;
    box-shadow: inset 4px 4px 6px -1px rgba(0 0 0/ .2),
        inset -4px -4px 6px -1px rgba(255 255 255 /.7),
        -.5px -.5px 0px rgba(255 255 255 / 1),
        .5px .5px 0px rgba(0 0 0 /.15),
        0px 12px 10px -10px rgba(0 0 0 / 0.05);
}

.skill-container .skill .outer .inner .number {
    font-weight: 800;
}

.skill-container .skill:nth-child(1) .outer .inner .number {
    color: #f75023;
}

.skill-container .skill:nth-child(2) .outer .inner .number {
    color: #4fa0ff;
}

.skill-container .skill:nth-child(3) .outer .inner .number {
    color: #7811f7;
}

circle {
    fill: none;
    stroke: #f75023;
    stroke-width: 20px;
    stroke-dasharray: 472;
    stroke-dashoffset:472;
    animation: anim linear 2s forwards;
}

@keyframes anim {
    100% {
        stroke-dashoffset: 70;
    }
}

svg {
    position: absolute;
    top: 0;
    left: 0;
}

.skill-container .skill:nth-child(1) circle {
    stroke: #f75023;
}

.skill-container .skill:nth-child(2) circle {
    stroke: #4fa0ff;
}

.skill-container .skill:nth-child(3) circle {
    stroke: #7811f7;
}
    <div class="skill-container">
        <div class="skill">
            <div class="outer">
                <div class="inner">
                    <div class="number" data-num="90">
                        90%
                    </div>
                </div>
            </div>
            <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="160px" height="160px">
                <defs>
                    <linearGradient id="GradientColor">
                        <stop offset="0%" stop-color="#e91e63" />
                        <stop offset="100%" stop-color="#673ab7" />
                    </linearGradient>
                </defs>
                <circle cx="80" cy="80" r="70" stroke-linecap="round" />
            </svg>
        </div>
        <div class="skill">
            <div class="outer">
                <div class="inner">
                    <div class="number" data-num="80">
                        80%
                    </div>
                </div>
            </div>
            <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="160px" height="160px">
                <defs>
                    <linearGradient id="GradientColor">
                        <stop offset="0%" stop-color="#e91e63" />
                        <stop offset="100%" stop-color="#673ab7" />
                    </linearGradient>
                </defs>
                <circle cx="80" cy="80" r="70" stroke-linecap="round" />
            </svg>
        </div>
        <div class="skill">
            <div class="outer">
                <div class="inner">
                    <div class="number" data-num="85">
                        85%
                    </div>
                </div>
            </div>
            <svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="160px" height="160px">
                <defs>
                    <linearGradient id="GradientColor">
                        <stop offset="0%" stop-color="#e91e63" />
                        <stop offset="100%" stop-color="#673ab7" />
                    </linearGradient>
                </defs>
                <circle cx="80" cy="80" r="70" stroke-linecap="round" />
            </svg>
        </div>
    </div>

Async function calling external function twice instead of once

i am trying to use async await in my code but i am having some issues. I am trying to initiate a transaction anytime there is a free modem port. Currently,these are the number of resources in my database

open ports: 1

queued transactions: 3

let ttyUSB0mtnmodem = serialportgsm.Modem();
ussd(ttyUSB0mtnmodem);

async function searchForFreePorts() {
    while (true) {
        await db.read();
        let freePorts = await db.data.mtnPorts.filter(obj => obj.status == "free");
        let queuedTrans = await db.data.mtnQueue.filter(obj => obj.status == "queued");

        if (freePorts.length > 0) { //if there are any open ports, proceed

            await freePorts.forEach((port, i) => {
                if (i < queuedTrans.length) { // if free ports is less than the queued transactions, continue loop
                    console.log("here");
                    let transaction = queuedTrans[i];

                    initiateWithdrawal(port, transaction);
                }
            })

        }
        await sleep(1000);

    }
}
searchForFreePorts();


function initiateWithdrawal(port, transaction) {

    let dev = port.dev + "mtnmodem";

    eval(dev).on('open', async () => {

        console.log(`nModem Sucessfully Opened`);
        //set port status to busy

        //perform transaction
        //when done,remove from queued transactions and set port status to free
        await eval(dev).close();
     })

    eval(dev).on('close', data => {
        //whole message data
        console.log(`Event Close: ` + JSON.stringify(data));
      });

    eval(dev).open('/dev/' + port.dev, options);

}

the issue here is that, the first initiateWithdrawal() call opens the modem once and performs the first transaction correctly, but whenever it’s called again,it opens the modem twice even though only one port is free.

first call logs

using : ttyUSB0 mtn

Modem Sucessfully Opened

second call logs

using : ttyUSB0 mtn

Modem Sucessfully Opened

using : ttyUSB0 mtn

Modem Sucessfully Opened

is there anything i am doing wrong?

How to block user from accessing other tabs in Shiny unless the user clicks a button?

My question is similar to Shiny how to block the user from accessing a tab?

But what I need here is:
-Block other tabs unless the user clicks on a submit button
-Automatically move to the other tab once that submit button is clicked. Here is an example code

library(shiny)

ui <- shinyUI(navbarPage(
  "",
  tabPanel(
    h1("Tab1"), 
    value = "nav1",
    mainPanel(
      br(),
      h2("The user must press this button to access the other tab."),
      br(),
      shiny::actionButton('button', 'press the button', onclick = "$(tab).removeClass('disabled')")
    )
  ),
  tabPanel(
    h1("Tab2"),
    value = "nav2",
    uiOutput("tab2contents")
  ),
  tags$script(
    '
    var tab = $('a[data-value="nav2"]').parent().addClass("disabled");
    $(function(){
      $(tab.parent()).on("click", "li.disabled", function(e) {
        e.preventDefault();
        return false;
      });
    });
    '
  )
))    

server <- shinyServer(function(input, output) {

})

# Run the application
shinyApp(ui = ui, server = server)

In the above code, the 2nd tab is blocked unless the button is clicked, but how can I update this further so that once the button is clicked the user is automatically taken to the 2nd tab?

htaccess for React app using React router hosted on cpanel

So I have a react single page application that I am hosting on cpanel. I have a pretty common issue from what I have been researching but none of the post in SO have helped me so far.

I am using React Router which I know is purely client-side routing. The problem is when the user refreshes the page on a url such as https://example.com/privacypolicy I get the stand Not Found error 404.

My folder structure in cpanel is as follows:

home/mysite
public_html
  all the folder from build folder (after npm run build locally)
  index.html(important for the post)
  .htaccess(important for the post)

The htaccess file is as follows:

RewriteBase /
RewriteRule ^index.html$ - [L]
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.html [L]

I was hoping this was going to redirect all the requests to index.html and therefore react would know which component to render once that has been redirected.

It isn’t and I’m a bit lost on what I’m doing wrong.

Any help is appreciated 🙂

Upload image to the server and insert into php mysql database how can i link the image to the correct row with an ID and upload successfully?

I’m using an HTML form to fill in data related to a company this form allows employees to post customers information each time a customer orders something however the requirements must include uploading an image via the form to the server the images will be stored in a file named images and then each time we POST via form it insert the data and information to the database using PHP MySql noting that it’s 7.4 PHP version kindly please help us with posting the images

i have successfully used this code but since there is a structure of how this works it’s a little hard because html form is internal and it’s called from external file so HTML form is within the script in a file called “customer_form.php” and externally we have add_customer.php which includes the php part of this code ,

My question is as follows:

I have uploaded images to the server successfully
I have inserted to database successfully

Issue that it posts the link of the image in the column called “S_Image” however it’s always choosing the last row before the inserting row what i mean it’s the last row – 1 and it’s like impossible to link it with the next coming row when posting information even i used WHERE condition and still maybe because next ID is not generated yet and when inserting data ID is still not known or shown within the form ..

I need to post the LINK (URL) of the images to the right and correct location this requires something with the post command or database insertion kindly please help if possible , many thanks.

HTML FRONT END SIDE

 <div class="form-group">
        <label for="S_Image">Upload Image</label>
            <input name="PIC" value="<?php echo htmlspecialchars($edit ? $customer['S_Image'] : '', ENT_QUOTES, 'UTF-8'); ?>" placeholder="Upload Image" class="form-control"  type="file" accept="image/png, image/gif, image/jpeg">
    </div> 

PHP SERVER SIDE

<?php


function generateRandomString($length = 10) {
    $characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
    $charactersLength = strlen($characters);
    $randomString = '';
    for ($i = 0; $i < $length; $i++) {
        $randomString .= $characters[rand(0, $charactersLength - 1)];
    }
    return $randomString;
}

// If upload button is clicked ...
if (isset($_POST['upload'])) {
##########################
$PIC = "";
$filename = $_FILES["PIC"]["name"];
$fileEXE = end(explode(".",$filename));
$File_type = $_FILES["PIC"]["type"];
$AllowedEXE = array('image/jpeg', 'image/gif', 'image/png');
$tempname = $_FILES["PIC"]["tmp_name"];  
$newName = generateRandomString().".".$fileEXE;
$folder = "images/".$newName;
if(in_array($File_type, $AllowedEXE)){
if(move_uploaded_file($tempname, $folder)){$PIC = $newName;}
}
###########################
 if(!empty($PIC)){

$servername = "localhost";
$username = "";
$password = "";
$dbname = "";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);
// Check connection
if ($conn->connect_error) {
  die("Connection failed: " . $conn->connect_error);
}


    // Get all the submitted data from the form
    $sql = "INSERT INTO S (S_Image) VALUES ('$PIC')";

--------------------------
// note i also tried this but it didn't work ID is still not known because it will be posted next
  SELECT * FROM S ORDER BY ID DESC LIMIT 1;
SELECT * FROM S WHERE id=(SELECT max(id) FROM S);

 $id = "SELECT id FROM S WHERE id = id+1";

------------------
$sql = "INSERT INTO S (S_Image) VALUES ('$PIC') WHERE id = $id";

    // Execute query
   if ($conn->query($sql) === TRUE) {
echo'DONE!';
       
   } else {
  echo "Error: " . $sql . "<br>" . $conn->error;
}
 }
 
}
 ?>

I know i made mistakes but i tried so much with all possible commands and failed still system is not getting next ID will be posted even tried to get it from $_POST[‘id’] method and enter manually and add it to where condition still it doesn’t work.

thank you.

Unresolved function or method send(), even if everything works ( WebStorm, discord.js )

I’m trying to create a bot with WebStorm using Node.js

This is my code:

const Discord = require( "discord.js" )
const client = new Discord.Client(
    {
        intents: ["GUILDS", "GUILD_MEMBERS", "GUILD_MESSAGES"]
    }
)

client.login( "token" )

client.on( "ready", () => {
    console.log( "Discord bot is online." )
} )

client.on( "messageCreate", ( message ) => {
    if( message.content === "!ph" ){
        message.channel.send( "hello" )
    }
} )

Even if everything works, in the event “messageCreate” when I do message.channel.send() the ide gives me this warning: “Unresolved function or method send() ” suggesting me to create the send method. Does anyone know how to fix it, because they don’t recognize the method but then running it works anyway? Thank you.

Next.js Jest 28 – Can’t transform SVG files

I am using Next.js 12.0.7 and Jest 28.1.0. And, also using the next-react-svg library to import my SVG files into the components. Here is my jest.config.js file –

// jest.config.js

const nextJest = require("next/jest");

const createJestConfig = nextJest({
  dir: "./",
});

const customJestConfig = {
  setupFilesAfterEnv: ["<rootDir>/jest.setup.js"],
  moduleNameMapper: {
    "^@/(.*)$": "<rootDir>/src/$1",
  },
  moduleDirectories: ["node_modules", "<rootDir>/"],
  modulePathIgnorePatterns: ["<rootDir>/tests/"],
  testEnvironment: "jest-environment-jsdom",
  transform: {
    "^.+\.tsx?$": "ts-jest",
    "^.+\.svg$": "<rootDir>/__mocks__/jest-svg-transformer.js",
  },
};

module.exports = createJestConfig(customJestConfig);

And here is the jest-svg-transformer.js file where I am trying to mock the SVG files –

// __mocks__/jest-svg-transformer.js

const path = require("path");

module.exports = {
  process(src, filePath) {
    if (path.extname(filePath) !== ".svg") {
      return src;
    }

    const name = `svg-${path.basename(filePath, ".svg")}`
      .split(/W+/)
      .map((x) => `${x.charAt(0).toUpperCase()}${x.slice(1)}`)
      .join("");

    return `
      const React = require('react');
      function ${name}(props) {
        return React.createElement(
          'svg',
          Object.assign({}, props, {'data-file-name': ${name}.name})
        )
      }
      module.exports = ${name}
            `;
  },
};

I have mentioned the error below which I’m getting when trying to run yarn test or jest.

Warning: React.jsx: type is invalid -- expected a string (for built-in components) or a class/function (for composite components) but got: object.
    
    Check the render method of `Loader`.
        at text (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/src/modules/common/components/Loader/index.tsx:5:34)
        at div
        at LoginPage (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/src/modules/auth/components/LoginPage/index.tsx:17:47)
        at Login
        at Provider (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-redux/lib/components/Provider.js:21:20)

      15 |         <p className={styles.text}>
      16 |           <small>{text}</small>
    > 17 |         </p>
         |                                                     ^
      18 |       ) : (
      19 |         ""
      20 |       )}

      at printWarning (node_modules/react/cjs/react-jsx-runtime.development.js:117:30)
      at error (node_modules/react/cjs/react-jsx-runtime.development.js:93:5)
      at jsxWithValidation (node_modules/react/cjs/react-jsx-runtime.development.js:1152:7)
      at Object.jsxWithValidationDynamic [as jsx] (node_modules/react/cjs/react-jsx-runtime.development.js:1209:12)
      at Loader (src/modules/common/components/Loader/index.tsx:17:58)
      at renderWithHooks (node_modules/react-dom/cjs/react-dom.development.js:14985:18)
      at mountIndeterminateComponent (node_modules/react-dom/cjs/react-dom.development.js:17811:13)

  console.error
    Error: Uncaught [Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
    
    Check the render method of `Loader`.]
        at reportException (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:66:24)
        at innerInvokeEventListeners (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:343:9)
        at invokeEventListeners (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:276:3)
        at HTMLUnknownElementImpl._dispatch (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:223:9)
        at HTMLUnknownElementImpl.dispatchEvent (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
        at HTMLUnknownElement.dispatchEvent (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34)
        at Object.invokeGuardedCallbackDev (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
        at invokeGuardedCallback (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
        at beginWork$1 (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:23964:7)
        at performUnitOfWork (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22779:12) {
      detail: Error: Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.
      
      Check the render method of `Loader`.
          at createFiberFromTypeAndProps (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:25058:21)
          at createFiberFromElement (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:25086:15)
          at reconcileSingleElement (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:14052:23)
          at reconcileChildFibers (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:14112:35)
          at reconcileChildren (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:16990:28)
          at updateHostComponent (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:17632:3)
          at beginWork (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:19080:14)
          at HTMLUnknownElement.callCallback (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:3945:14)
          at HTMLUnknownElement.callTheUserObjectsOperation (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
          at innerInvokeEventListeners (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:340:25)
          at invokeEventListeners (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:276:3)
          at HTMLUnknownElementImpl._dispatch (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:223:9)
          at HTMLUnknownElementImpl.dispatchEvent (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
          at HTMLUnknownElement.dispatchEvent (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34)
          at Object.invokeGuardedCallbackDev (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:3994:16)
          at invokeGuardedCallback (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:4056:31)
          at beginWork$1 (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:23964:7)
          at performUnitOfWork (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22779:12)
          at workLoopSync (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22707:5)
          at renderRootSync (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22670:7)
          at performSyncWorkOnRoot (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22293:18)
          at scheduleUpdateOnFiber (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:21881:7)
          at updateContainer (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:25482:3)
          at /Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:26021:7
          at unbatchedUpdates (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22431:12)
          at legacyRenderSubtreeIntoContainer (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:26020:5)
          at Object.render (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:26103:10)
          at /Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@testing-library/react/dist/pure.js:101:25
          at batchedUpdates$1 (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom.development.js:22380:12)
          at act (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14)
          at Object.render (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@testing-library/react/dist/pure.js:97:26)
          at Object.<anonymous> (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/__tests__/index.test.tsx:9:11)
          at Promise.then.completed (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/utils.js:333:28)
          at new Promise (<anonymous>)
          at callAsyncCircusFn (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/utils.js:259:10)
          at _callCircusTest (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/run.js:277:40)
          at processTicksAndRejections (node:internal/process/task_queues:95:5)
          at _runTest (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/run.js:209:3)
          at _runTestsForDescribeBlock (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/run.js:97:9)
          at _runTestsForDescribeBlock (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/run.js:91:9)
          at run (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/run.js:31:3)
          at runAndTransformResultsToJestFormat (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapterInit.js:135:21)
          at jestAdapter (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-circus/build/legacy-code-todo-rewrite/jestAdapter.js:92:19)
          at runTestInternal (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-runner/build/runTest.js:411:16)
          at runTest (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-runner/build/runTest.js:499:34)
          at TestRunner.runTests (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-runner/build/index.js:145:12)
          at TestScheduler.scheduleTests (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@jest/core/build/TestScheduler.js:317:13)
          at runJest (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@jest/core/build/runJest.js:407:19)
          at _run10000 (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@jest/core/build/cli/index.js:339:7)
          at runCLI (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/@jest/core/build/cli/index.js:190:3)
          at Object.run (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/jest-cli/build/cli/index.js:155:37),
      type: 'unhandled exception'
    }

      at VirtualConsole.<anonymous> (node_modules/jest-environment-jsdom/build/index.js:70:23)
      at reportException (node_modules/jsdom/lib/jsdom/living/helpers/runtime-script-errors.js:70:28)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:343:9)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:276:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:223:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)

  console.error
    The above error occurred in the <div> component:
    
        at div
        at div
        at text (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/src/modules/common/components/Loader/index.tsx:5:34)
        at div
        at LoginPage (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/src/modules/auth/components/LoginPage/index.tsx:17:47)
        at Login
        at Provider (/Users/prosenjitchowdhury/dev/multiplyr/dhaka-frontend/node_modules/react-redux/lib/components/Provider.js:21:20)
    
    Consider adding an error boundary to your tree to customize error handling behavior.
    Visit https://reactjs.org/link/error-boundaries to learn more about error boundaries.

      at logCapturedError (node_modules/react-dom/cjs/react-dom.development.js:20085:23)
      at update.callback (node_modules/react-dom/cjs/react-dom.development.js:20118:5)
      at callCallback (node_modules/react-dom/cjs/react-dom.development.js:12318:12)
      at commitUpdateQueue (node_modules/react-dom/cjs/react-dom.development.js:12339:9)
      at commitLifeCycles (node_modules/react-dom/cjs/react-dom.development.js:20736:11)
      at commitLayoutEffects (node_modules/react-dom/cjs/react-dom.development.js:23426:7)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)

 FAIL  __tests__/index.test.tsx
  Home
    ✕ renders a heading (37 ms)

  ● Home › renders a heading

    Element type is invalid: expected a string (for built-in components) or a class/function (for composite components) but got: object.

    Check the render method of `Loader`.

       7 | describe("Home", () => {
       8 |   it("renders a heading", () => {
    >  9 |     render(
         |           ^
      10 |       <Provider store={store}>
      11 |         <Login />
      12 |       </Provider>

      at createFiberFromTypeAndProps (node_modules/react-dom/cjs/react-dom.development.js:25058:21)
      at createFiberFromElement (node_modules/react-dom/cjs/react-dom.development.js:25086:15)
      at reconcileSingleElement (node_modules/react-dom/cjs/react-dom.development.js:14052:23)
      at reconcileChildFibers (node_modules/react-dom/cjs/react-dom.development.js:14112:35)
      at reconcileChildren (node_modules/react-dom/cjs/react-dom.development.js:16990:28)
      at updateHostComponent (node_modules/react-dom/cjs/react-dom.development.js:17632:3)
      at beginWork (node_modules/react-dom/cjs/react-dom.development.js:19080:14)
      at HTMLUnknownElement.callCallback (node_modules/react-dom/cjs/react-dom.development.js:3945:14)
      at HTMLUnknownElement.callTheUserObjectsOperation (node_modules/jsdom/lib/jsdom/living/generated/EventListener.js:26:30)
      at innerInvokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:340:25)
      at invokeEventListeners (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:276:3)
      at HTMLUnknownElementImpl._dispatch (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:223:9)
      at HTMLUnknownElementImpl.dispatchEvent (node_modules/jsdom/lib/jsdom/living/events/EventTarget-impl.js:94:17)
      at HTMLUnknownElement.dispatchEvent (node_modules/jsdom/lib/jsdom/living/generated/EventTarget.js:241:34)
      at Object.invokeGuardedCallbackDev (node_modules/react-dom/cjs/react-dom.development.js:3994:16)
      at invokeGuardedCallback (node_modules/react-dom/cjs/react-dom.development.js:4056:31)
      at beginWork$1 (node_modules/react-dom/cjs/react-dom.development.js:23964:7)
      at performUnitOfWork (node_modules/react-dom/cjs/react-dom.development.js:22779:12)
      at workLoopSync (node_modules/react-dom/cjs/react-dom.development.js:22707:5)
      at renderRootSync (node_modules/react-dom/cjs/react-dom.development.js:22670:7)
      at performSyncWorkOnRoot (node_modules/react-dom/cjs/react-dom.development.js:22293:18)
      at scheduleUpdateOnFiber (node_modules/react-dom/cjs/react-dom.development.js:21881:7)
      at updateContainer (node_modules/react-dom/cjs/react-dom.development.js:25482:3)
      at node_modules/react-dom/cjs/react-dom.development.js:26021:7
      at unbatchedUpdates (node_modules/react-dom/cjs/react-dom.development.js:22431:12)
      at legacyRenderSubtreeIntoContainer (node_modules/react-dom/cjs/react-dom.development.js:26020:5)
      at Object.render (node_modules/react-dom/cjs/react-dom.development.js:26103:10)
      at node_modules/@testing-library/react/dist/pure.js:101:25
      at batchedUpdates$1 (node_modules/react-dom/cjs/react-dom.development.js:22380:12)
      at act (node_modules/react-dom/cjs/react-dom-test-utils.development.js:1042:14)
      at Object.render (node_modules/@testing-library/react/dist/pure.js:97:26)
      at Object.<anonymous> (__tests__/index.test.tsx:9:11)
      at TestScheduler.scheduleTests (node_modules/@jest/core/build/TestScheduler.js:317:13)
      at runJest (node_modules/@jest/core/build/runJest.js:407:19)
      at _run10000 (node_modules/@jest/core/build/cli/index.js:339:7)
      at runCLI (node_modules/@jest/core/build/cli/index.js:190:3)

Test Suites: 1 failed, 1 total
Tests:       1 failed, 1 total
Snapshots:   0 total
Time:        0.966 s, estimated 1 s
Ran all test suites.
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

This is the test that is failing –

// __tests__/index.test.tsx

import { render, screen } from "@testing-library/react";
import "@testing-library/jest-dom";
import { Provider } from "react-redux";
import { store } from "@/store";
import Login from "@/pages/login";

describe("Home", () => {
  it("renders a heading", () => {
    render(
      <Provider store={store}>
        <Login />
      </Provider>
    );

    const heading = screen.getByTestId("page-loader-element");

    expect(heading).toBeInTheDocument();
  });
});

This is the component that is throwing me the error –

// src/modules/common/components/Loader/index.tsx

import React from "react";
import Logo from "@/assets/icons/Logo.svg";
import styles from "./Loader.module.scss";

export default function Loader({ text }: { text?: string }) {
  return (
    <div
      className="d-flex flex-column justify-content-center align-items-center w-100 my-3"
      data-testid="page-loader-element"
    >
      <div className="animate__animated animate__pulse animate__infinite    infinite">
        <Logo />
      </div>
      {text ? (
        <p className={styles.text}>
          <small>{text}</small>
        </p>
      ) : (
        ""
      )}
    </div>
  );
}

Here is my jest.setup.js file –

// jest.setup.js

import "@testing-library/jest-dom/extend-expect";

These are the versions of the related libraries I’m using –

// package.json

// ...
"dependencies": {
    "next": "^12.0.7",
    "next-react-svg": "1.1.3",
    // ...
},
"devDependencies": {
    // ...
    "@types/jest": "^28.1.1",
    "babel-jest": "^28.1.0",
    "jest": "^28.1.0",
    "jest-cli": "28.1.0",
    "jest-environment-jsdom": "^28.1.0",
    "jest-svg-transformer": "^1.0.0",
    "ts-jest": "^28.0.4",
    "typescript": "4.4.3"
},
"resolutions": {
    "@types/react": "17.0.2",
    "@types/react-dom": "17.0.2"
},
//...

And finally, this is what my current tsconfig.json file looks like –

// tsconfig.json

{
  "compilerOptions": {
    // ...
    "target": "es5",
    "lib": ["dom", "dom.iterable", "esnext"],
    "baseUrl": ".",
    "paths": {
      "@/*": ["src/*"]
    },
  },
  "include": [
    "next-env.d.ts",
    "additional.d.ts",
    "decs.d.ts",
    "**/*.ts",
    "**/*.tsx",
    "jest.setup.js"
  ],
  "exclude": ["node_modules", "playwright.config.ts"],
  "ts-node": {
    "transpileOnly": true,
    "files": true,
    "compilerOptions": {
      "rootDir": "."
    }
  }
}

I tried using the jest-svg-transformer library also. But no luck!

ckEditor Error : editor-isreadonly-has-no-setter

I’m using ckeditor5 balloon block mode in nuxt project.
I have used online builder and downloaded build files , add the build files to my project and importing them into my editor component and using it!
the only problem that I have is that when the page loads ,
I get an error : editor-isreadonly-has-no-setter.
I tried binding v-model to the editor but the value won’t be updated!
note : I have used ckeditor5 classic mode identical to the way that I’m using Balloon Block, donno really what’s going on!
this is my component :

<template>
  <ckeditor
    :id="id"
    v-bind="$attrs"
    :editor="classicEditor"
    :config="editorConfig"
    v-on="$listeners"
  />
</template>

<script>
let ClassicEditor
let CKEditor

if (process.client) {
  ClassicEditor = require('@/plugins/ckeditor/ckeditor')
  CKEditor = require('@ckeditor/ckeditor5-vue2')
} else {
  CKEditor = { component: { template: '<div></div>' } }
}

export default {
  name: 'CKEditor',

  components: {
    ckeditor: CKEditor.component,
  },

  props: {
    fillErr: {
      type: Boolean,
      default: false,
      required: false,
    },
    minHeight: {
      type: String,
      default: '350px',
      required: false,
    },
    label: {
      type: String,
      default: '',
      required: false,
    },
  },

  data() {
    return {
      classicEditor: ClassicEditor,
      editorConfig: {
        language: 'fa',
        contentsLangDirection: 'rtl',
      },
      editorElement: null,
      id: null,
    }
  },

  computed: {
    value() {
      return this.$attrs.value
    },
  },

  created() {
    this.id = this.uuidv4()
  },

  mounted() {
    if (!document.getElementById('editorFaTranslate')) {
      const faScript = document.createElement('script')
      faScript.setAttribute('charset', 'utf-8')
      faScript.setAttribute('type', 'text/js')
      faScript.setAttribute('id', 'editorFaTranslate')
      faScript.setAttribute(
        'src',
        require('@@/plugins/ckeditor/translations/fa.js')
      )
      document.head.appendChild(faScript)
    }

    const intervalId = setInterval(() => {
      const ckEditor = document.getElementById(this.id)
      if (ckEditor) {
        clearInterval(intervalId)
        this.editorElement = ckEditor
      }
    })
  },

  methods: {
    uuidv4() {
      return 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(
        /[xy]/g,
        function (c) {
          const r = (Math.random() * 16) | 0
          const v = c === 'x' ? r : (r & 0x3) | 0x8
          return v.toString(16)
        }
      )
    },
    insertTextAtTheEnd(text) {
      function findCorrectPosition(htmlStr) {
        const lastIndexOfHTMLTag = htmlStr.lastIndexOf('</')
        const lastUlTag = htmlStr.lastIndexOf('</ul>')
        const lastOlTag = htmlStr.lastIndexOf('</ol>')
        if (
          lastUlTag === lastIndexOfHTMLTag ||
          lastOlTag === lastIndexOfHTMLTag
        ) {
          const lastLiTag = htmlStr.lastIndexOf('</li>')
          return lastLiTag
        }
        return lastIndexOfHTMLTag
      }
      const currentString = this.value
      const correctIndex = findCorrectPosition(currentString)
      const firstHalf = currentString.substring(0, correctIndex)
      const secondHalf = currentString.substring(correctIndex)
      const newString = `${firstHalf}${text}${secondHalf}`
      this.$emit('input', newString)
    },
  },
}
</script>

I would welcome any idea!

Specific Webpage Word-Counter Needed with a Logical Semantic Twist, a Delay and an exact placement

The following question has NOT already an answer in Stack Overflow.

Based on many broad unspecific undetailed and ambiguous questions and many broader answers like here I have created a very specific and very precisely formulated question that, unlike the other broader questions on this site, have no space for ambiguity.


This question narrows down the quest for a logical word-count in a semantically different way and differs thus from other questions as well as it allows for precise and useful answer with a practical implemenatation anywhere on the page where one wants to count and or to show the counter after a preset delay, that relieves the code from causing any overhead while the words are still being fetched.

You are free to fork into the link above or the many many other works already wandering around elsewhere, and tweak it for your specific answer of this question.

You are free to use jQuery library 3.6.0 if you wish so make one with zero-dependencies on jQuery.


Given the following HTML syntax, I want to count the number of words in <article>.

These could be a word starting from two characters up.
The meaning of the English word a or o is hereby not counted as a meaningful word.
Only words from two letters up need to be counted to reflect substance and contents.

Include words in normal html tags like <p> <h1> <h2> <h3> <em> <i> <strong> <mark> or <td>.

Only elements that are <article> and inside a <section> or a <hgroup> should be counted. All else should be skipped.

Dashed-words can count as one word: the space around the words is the defining factor.

<article>
  <hgroup>
    <hr>word word word word word</h1>
    <h2>word word word word word</h2>
  </hgroup>

  <something>Ignored Ignored</something>

  <section>
    <p>word word</p>
    <p><em>Word Word word</em></p>
    <p><i>Word Word word</i></p>
    <p>word word</p>
    <p><strong>Word Word word</strong></p>
    <p><mark>Word Word word</mark></p>
    <p>word word</p>
  </section>

  <something>Ignored Ignored</something>

  <section>
    <h3>word word word word word</h3>
    <ul>
      <li>word word word word</li>
      <li>word word word word</li>
      <li>word word word word</li>
    </ul>
    <p>word word</p>
    <p>word word</p>
    <table>...<td>Maandag</td><td>Dinsdag</td>...
    </table>
    <p>a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a</p>
  </section>   
</article>

The proces should be delayed 500ms to make sure no extra pressure is put on the overhead of the other complex Javascript gallery scripts etcettera. Then after 500ms it should write the numer of words inside an html element, say for example <wordcount>.

 <wordcount></wordcount>

In the example above, the correct word count should be: ???
(15 for the three headings, 10 in unstyled paragraphs, 12 in styled elements and 12 in list items and 2 in table data.)

 <wordcount>51</wordcount>

Insert each div inside next div (jQuery)

How can I insert div.one into his next div.two with jquery?

What it is:

<div id="list">
 <div class="box one"></div>
 <div class="box two"></div>
 <div class="box one"></div>
 <div class="box two"></div>
 <div class="box one"></div>
 <div class="box two"></div>
</div>

What I want:

<div id="list">
  <div class="box two">
    <div class="box one"></div>
  </div>
  <div class="box two">
    <div class="box one"></div>
  </div>
  <div class="box two">
    <div class="box one"></div>
  </div>
</div>

What I tried (but it insert all div.one in every div.two):

$("#list .box.one").each(function() {
    $(this).prependTo(".box.two").next();
});

Whats my fail?

I am unable to generate (or print) the data retrieved from the data base in PDF using JSPDF

Hi i am new to Javascript and i am unable to print the data which is retrived from the database.
Here the concept is when i upload a file, i should get the data to be displayed in the browser and i want to print the retrieved data in PDF. i could able to retrieve that data when i am generating with .xlxs format but for PDF format i couldnt.
[enter image description here][1]
Please see the code and kindly help me out with the correct code.

<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>DATA VALIDATION</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.39/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.39/esri/css/esri.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://js.arcgis.com/3.39/"></script>

    <!-- <script src="jspdf.debug.js"></script> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="script.js"></script>

   
</head>

<body class="tundra">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer"
        data-dojo-props="design:'headline', gutters:'false'">
        <div class="width-100" id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'"
            style="height:58px;text-align:left;font-weight:bold;font-size:14px;color:#400D12; height: 95px;">
            <div class="row" style="margin: 0;">
                <div class="col-sm-1">
                    <img src="logo.png" style="width: 250px; margin: 4px;" />
                </div>
                <div class="col-sm-11" style="text-align: center;">
                    <h3>DMT DATA VALIDATION</h3>
                </div>
            </div>
        </div>
        <div class="width-100" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
            <div id="spinner">
                <img src="loader.gif" style="height: 50px;" />
            </div>
            <div data-dojo-type="dijit/layout/ContentPane" style="height: 80px;">
                <div class="row" style="margin: 0; border-bottom: 1px solid grey;">
                    <div class="col-sm-5">
                        <div class="disp-inline">
                            <label style="display: inline-block;margin-left: 5px;" for="selectTemplate">Select
                                Template</label>
                            <select id="selectTemplate"
                                style="width: 325px; padding: 5px; margin: 5px; display: inline-block;">
                                <option value="AddressingData">Addressing Data</option>
                                <option value="HardLandscaping">Hard Landscaping</option>
                                <option value="IrrigationFacilities">Irrigation Facilities</option>
                                <option value="ParkingFacilities">Parking Facilities</option>
                                <option value="PedestrianAndCycling">Pedestrian And Cycling</option>
                                <option value="PublicTransportFacilities">Public Transport Facilities</option>
                                <option value="RoadAuxiliaryFeatures">Road Auxiliary Features</option>
                                <option value="RoadNavigation">Road Navigation</option>
                                <option value="RoadStructuresAndFurniture">Road Structures And Furniture</option>
                                <option value="SignsAndSignPoles">Signs And Sign Poles</option>
                                <option value="SoftLandscaping">Soft Landscaping</option>
                                <option value="StormwaterFacilities">Storm water Facilities</option>
                                <option value="StreetlightingFacilities">Street lighting Facilities</option>
                                <option value="StreetlightingPowerAndControlSystem">Street lighting Power And Control
                                    System
                                </option>
                                <option value="TrafficControl">Traffic Control</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-5">
                        <div class="disp-inline" style="margin-top: 14px;">
                            <form encType="multipart/form-data" method="post" id="gdbzipUploadForm">
                                <div className="field">
                                    <label style="display: inline-block;" className="file-upload" title="Upload ZIP"
                                        for='UploadzipFile'>Upload GDB
                                    </label>
                                    <input style="display: inline-block;width: 325px;" type="file" name="file"
                                        id="UploadzipFile" accept='.zip' />
                                </div>
                            </form>
                            <!-- <div>
                                <label style="display: inline-block;" className="file-upload" title="Upload ZIP"
                                    for='UploadzipFile'>  Html to PDF  
                                </label>
                                <button onclick="javascript:createPdf()" id="cmd">Generate PDF</button>
                            </div> -->
                        </div>
                    </div>
                    <div class="col-sm-2">
                        <div style="display: inline-block; margin-top: 14px;">
                            <a style="cursor: pointer; display: none;" href="#" id="downloadreflink">
                                <i class="glyphicon glyphicon-download"></i>
                                Download Report
                            </a>                            
                        </div>
                        <div style="display: inline-block; margin-top: 14px;">
                            <a onclick="javascript:createPdf()" style="cursor: pointer; display: none;" href="#" id="generatePdf">
                                <i class="glyphicon glyphicon-download"></i>
                                Generate PDF Report
                            </a>                            
                        </div>
                    </div>
                </div>
            </div>
            <div id="gridDiv" data-dojo-type="dijit/layout/ContentPane">
            </div>
        </div>
        <div class="width-100" id="bottomdiv" data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region:'bottom'" style="height: 50px;">
            <label id="errorlabel" style="display: none; color: red;"></label>
        </div>
    </div>

</body>

</html>
html,
        body {
            height: 100%;
            width: 100%;
        }

        #mainWindow {
            height: 100%;
            width: 100%;

        }

        .width-100 {
            width: 100% !important;
        }

        #map {
            font-family: sans-serif;
            height: calc(100% - 90px);
            width: 100%;
            border-top: 1px solid grey;
        }

        html,
        body {
            margin: 0;
            padding: 0;
        }

        .disp-inline {
            display: inline-block;
            margin: 5px;
        }

        .dijitBorderContainer-child {
            left: 0 !important;
        }

        .dojoxGrid {
            width: 100% !important;
        }

        /* (A) FULL SCREEN WRAPPER */
        #spinner {
            position: fixed;
            top: 0;
            left: 0;
            z-index: 9999;
            width: 100vw;
            height: 100vh;
            background: rgba(0, 0, 0, 0.7);
            transition: opacity 0.2s;
        }

        /* (B) CENTER LOADING SPINNER */
        #spinner img {
            position: absolute;
            top: 50%;
            left: 50%;
            transform: translate(-50%);
        }

        /* (C) SHOW & HIDE */
        #spinner {
            visibility: hidden;
            opacity: 0;
        }

        #spinner.show {
            visibility: visible;
            opacity: 1;
        }

        .dojoxGridArrowButtonChar {
            display: inline-block !important;
        }

        .dojoxGridColCaption {
            display: inline-block;
        }
<!DOCTYPE html>
<html>

<head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8">

    <meta name="viewport" content="initial-scale=1, maximum-scale=1,user-scalable=no">
    <title>DATA VALIDATION</title>
    <link rel="stylesheet" href="https://js.arcgis.com/3.39/dijit/themes/tundra/tundra.css">
    <link rel="stylesheet" href="https://js.arcgis.com/3.39/esri/css/esri.css">
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <link rel="stylesheet" href="style.css">
    
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
    <script src="https://js.arcgis.com/3.39/"></script>

    <!-- <script src="jspdf.debug.js"></script> -->
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jspdf/1.2.61/jspdf.debug.js"></script>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
    <script src="script.js"></script>

   
</head>

<body class="tundra">
    <div id="mainWindow" data-dojo-type="dijit/layout/BorderContainer"
        data-dojo-props="design:'headline', gutters:'false'">
        <div class="width-100" id="header" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'top'"
            style="height:58px;text-align:left;font-weight:bold;font-size:14px;color:#400D12; height: 95px;">
            <div class="row" style="margin: 0;">
                <div class="col-sm-1">
                    <img src="logo.png" style="width: 250px; margin: 4px;" />
                </div>
                <div class="col-sm-11" style="text-align: center;">
                    <h3>DMT DATA VALIDATION</h3>
                </div>
            </div>
        </div>
        <div class="width-100" data-dojo-type="dijit/layout/ContentPane" data-dojo-props="region:'center'">
            <div id="spinner">
                <img src="loader.gif" style="height: 50px;" />
            </div>
            <div data-dojo-type="dijit/layout/ContentPane" style="height: 80px;">
                <div class="row" style="margin: 0; border-bottom: 1px solid grey;">
                    <div class="col-sm-5">
                        <div class="disp-inline">
                            <label style="display: inline-block;margin-left: 5px;" for="selectTemplate">Select
                                Template</label>
                            <select id="selectTemplate"
                                style="width: 325px; padding: 5px; margin: 5px; display: inline-block;">
                                <option value="AddressingData">Addressing Data</option>
                                <option value="HardLandscaping">Hard Landscaping</option>
                                <option value="IrrigationFacilities">Irrigation Facilities</option>
                                <option value="ParkingFacilities">Parking Facilities</option>
                                <option value="PedestrianAndCycling">Pedestrian And Cycling</option>
                                <option value="PublicTransportFacilities">Public Transport Facilities</option>
                                <option value="RoadAuxiliaryFeatures">Road Auxiliary Features</option>
                                <option value="RoadNavigation">Road Navigation</option>
                                <option value="RoadStructuresAndFurniture">Road Structures And Furniture</option>
                                <option value="SignsAndSignPoles">Signs And Sign Poles</option>
                                <option value="SoftLandscaping">Soft Landscaping</option>
                                <option value="StormwaterFacilities">Storm water Facilities</option>
                                <option value="StreetlightingFacilities">Street lighting Facilities</option>
                                <option value="StreetlightingPowerAndControlSystem">Street lighting Power And Control
                                    System
                                </option>
                                <option value="TrafficControl">Traffic Control</option>
                            </select>
                        </div>
                    </div>
                    <div class="col-sm-5">
                        <div class="disp-inline" style="margin-top: 14px;">
                            <form encType="multipart/form-data" method="post" id="gdbzipUploadForm">
                                <div className="field">
                                    <label style="display: inline-block;" className="file-upload" title="Upload ZIP"
                                        for='UploadzipFile'>Upload GDB
                                    </label>
                                    <input style="display: inline-block;width: 325px;" type="file" name="file"
                                        id="UploadzipFile" accept='.zip' />
                                </div>
                            </form>
                            <!-- <div>
                                <label style="display: inline-block;" className="file-upload" title="Upload ZIP"
                                    for='UploadzipFile'>  Html to PDF  
                                </label>
                                <button onclick="javascript:createPdf()" id="cmd">Generate PDF</button>
                            </div> -->
                        </div>
                    </div>
                    <div class="col-sm-2">
                        <div style="display: inline-block; margin-top: 14px;">
                            <a style="cursor: pointer; display: none;" href="#" id="downloadreflink">
                                <i class="glyphicon glyphicon-download"></i>
                                Download Report
                            </a>                            
                        </div>
                        <div style="display: inline-block; margin-top: 14px;">
                            <a onclick="javascript:createPdf()" style="cursor: pointer; display: none;" href="#" id="generatePdf">
                                <i class="glyphicon glyphicon-download"></i>
                                Generate PDF Report
                            </a>                            
                        </div>
                    </div>
                </div>
            </div>
            <div id="gridDiv" data-dojo-type="dijit/layout/ContentPane">
            </div>
        </div>
        <div class="width-100" id="bottomdiv" data-dojo-type="dijit/layout/ContentPane"
            data-dojo-props="region:'bottom'" style="height: 50px;">
            <label id="errorlabel" style="display: none; color: red;"></label>
        </div>
    </div>

</body>

</html>

DomParser JS changes attribute values

I have a weird problem and are looking for an alternative or solution to the following:

I have the following xml stored in a string:

'<revision id="2832276" title="`~!@#$%^&amp;amp;*()_-+={}|\\][:&amp;quot;;&amp;apos;&amp;lt;&amp;gt;,./_æåøÆÅØ_色" type="major" date="2022-05-25T13:53:28.650" comment="`~!@#$%^&amp;amp;*()_-+={}|\\][:&amp;quot;;&amp;apos;&amp;lt;&amp;gt;,./_æåøÆÅØ_"/>'

now if notice the values of title it changes I copy paste it into chrome or if i use the DOM parser:

.getElementsByTagName('revision')[0].getAttribute('title')

I get:

'`~!@#$%^&amp;*()_-+={}|\\][:&quot;;&apos;&lt;&gt;,./_æåøÆÅØ_色'

I have initialized the DOMParser like:

xmlDoc = parser.parseFromString(
                        xml,
                        'application/xml'
                    );