Left and right trim string in javascript

I have a string format that is of this format {"message ":"System: you are now connected as ghi"}

I want to trim it such that I get this System: you are now connected as user as final string.
I guess in JS we cannot trim a string and we can only trim white spaces so how do I get this

how can i filter data Table with mat select?

i want just to filter my data table with multiple search , here is my code , i’m working on angular project , is there a solution to filter with multiple value ? Lead , DateFin , Priorite and Statut , i thnik that i can use switch for this 4 value . or is there another easier solution please.

this is my data table

dataSource: any = [
    {
      Ref: '1',
      Libelle: 'Ecommerce',
      Lead: 'Vector',
      Contact: 'Yassine',
      DateDebut: '20/02/2021',
      DateFin: '20/01/2022',
      DateModification: '12/03/2022',
      Priorite: 'auth',
      Statut: 'conception',
    },
    {
      Ref: '2',
      Libelle: 'Transport',
      Lead: 'Vector',
      Contact: 'Salim',
      DateDebut: '20/02/2021',
      DateFin: '20/01/2022',
      DateModification: '12/03/2022',
      Priorite: 'design',
      Statut: 'conception',
    },
    {
      Ref: '3',
      Libelle: 'Ecole',
      Lead: 'Vector',
      Contact: 'Yassine',
      DateDebut: '10/05/2021',
      DateFin: '20/02/2022',
      DateModification: '12/03/2022',
      Priorite: 'auth',
      Statut: 'développement',
    },
    {
      Ref: '4',
      Libelle: 'livraison',
      Lead: 'Antoine',
      Contact: 'Salim',
      DateDebut: '10/05/2021',
      DateFin: '20/02/2022',
      DateModification: '12/03/2022',
      Priorite: 'design',
      Statut: 'développement',
    },
    {
      Ref: '5',
      Libelle: 'Food',
      Lead: 'Antoine',
      Contact: 'Yassine',
      DateDebut: '07/03/2021',
      DateFin: '20/02/2022',
      DateModification: '10/04/2022',
      Priorite: 'design',
      Statut: 'conception',
    },
    {
      Ref: '5',
      Libelle: 'Food',
      Lead: 'Antoine',
      Contact: 'Yassine',
      DateDebut: '07/03/2021',
      DateFin: '20/02/2022',
      DateModification: '10/04/2022',
      Priorite: 'design',
      Statut: 'conception',
    },
    {
      Ref: '5',
      Libelle: 'Food',
      Lead: 'Antoine',
      Contact: 'Yassine',
      DateDebut: '07/03/2021',
      DateFin: '20/02/2022',
      DateModification: '10/04/2022',
      Priorite: 'design',
      Statut: 'conception',
    },
]

this is my filter component

<div class="row m-0 w-100">
  <div class="col-md-6 px-1 col-12">
    <div class="w-100 form-group">
      <div class="CR_FormSelect">
        <mat-label>{{ labelLead }}</mat-label>
        <mat-form-field class="form-control mb-2">
          <mat-select>
            <mat-option
              *ngFor="let item of dataSource; let i = index"
              [value]="item.Lead"
              >{{ item.Lead }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </div>
    </div>
  </div>
  <div class="col-md-6 px-1 col-12">
    <div class="w-100 form-group">
      <div class="CR_FormSelect">
        <mat-label>{{ labelDateFin }}</mat-label>
        <mat-form-field class="form-control mb-2">
          <mat-select>
            <mat-option *ngFor="let item of dataSource" [value]="item.DateFin">
              {{ item.DateFin }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </div>
    </div>
  </div>
</div>
<div class="row m-0 w-100">
  <div class="col-md-6 px-1 col-12">
    <div class="w-100 form-group">
      <div class="CR_FormSelect">
        <mat-label>{{ labelStatut }}</mat-label>
        <mat-form-field class="form-control mb-2">
          <mat-select>
            <mat-option *ngFor="let item of dataSource" [value]="item.Statut">
              {{ item.Statut }}
            </mat-option>
          </mat-select>
        </mat-form-field>
      </div>
    </div>
  </div>
  <div class="col-md-6 px-1 col-12">
    <div class="w-100 form-group">
      <div class="CR_FormSelect">
        <mat-label>{{ labelPriorite }}</mat-label>
        <mat-form-field class="form-control mb-2">
          <mat-select>
            <mat-option *ngFor="let item of dataSource" [value]="item.Priorite">
              {{ item.Priorite }}</mat-option
            >
          </mat-select>
        </mat-form-field>
      </div>
    </div>
  </div>
</div>

<div class="row m-0">
  <div class="col-12 px-1">
    <button
      mat-raised-button
      class="CR_btn CR_B_act ml-auto d-block"
      (click)="showSearchResult($event)"
    >
      Voir le resultat
    </button>
  </div>
</div>

here my function

  searchAdvanced(value: any) {
    this.advancedFiltredData = this.dataSource.filter(
      (projet: any) => projet.Lead === value
    );
    console.log(this.advancedFiltredData);
  }

Issue with Conditional Statements in React: Only Registering First Statement

I’m pretty new to react, and I’m trying to create a rating component with both whole and half stars using conditional statements. The issue that I’m having is that the correct number of stars is not showing up. For instance, I have the rating set at 4.5, and I’m only seeing one star. When I blocked out all the conditional statements before the 4.5 statement, it correctly shows 4.5 stars. I’m not sure what I’m doing wrong, and I would really appreciate any help or guidance on how to fix this issue.
Thank you!

import React, {useState} from 'react';
import { createReview, detailsProduct } from '../actions/productActions';
import { useDispatch, useSelector } from 'react-redux';
import {FaStar} from 'react-icons/fa';
import {FaStarHalf} from 'react-icons/fa';


 function StarRating () {
 const productDetails = useSelector((state) => state.productDetails);
 const { loading, error, product } = productDetails;
 var rating = product.rating;

if (rating = 1)
{
    return (

                   <FaStar />
    );
};

if (rating >= 1.5 && rating < 2 ){
    return (
                 <div>
                    <FaStar/>
                    <FaStarHalf/>
                 </div>
        );
};

if (rating >= 2 && rating < 2.5){
    return (
    <div>
     {[...Array(2)].map((star, i) => {
          return (
            <div>
               <FaStar/>
            </div>
       );   
     })}
     </div>
     )
   
    
}

if (rating >= 2.5 && rating < 3){
    return (
        <div>
     {[...Array(2)].map((star, i) => {
          return (
            <div>
               <FaStar/>
            </div>
       );   
     })}
        <div>
           <FaStarHalf/>
        </div>
        </div>
);         
}

if (rating >= 3 && rating < 3.5){
    return (
        <div>
        {[...Array(3)].map((star, i) => {
             return (
               <div>
                  <FaStar/>
               </div>
          );   
        })}
        </div>
);   
}

if (rating >= 3.5 && rating < 4){
    return (
        <div>
        {[...Array(3)].map((star, i) => {
             return (
               <div>
                  <FaStar/>
               </div>
          );   
        })}
           <div>
              <FaStarHalf/>
           </div>
           </div>
);   
}
if (rating >= 4 && rating < 3.5){
    return (
        <div>
        {[...Array(4)].map((star, i) => {
             return (
               <div>
                  <FaStar/>
               </div>
          );   
        })}
        </div>
);   
}
if (rating >= 4.5 && rating < 5 ){
    return (
        <div>
        {[...Array(4)].map((star, i) => {
             return (
               <div>
                  <FaStar/>
               </div>
          );   
        })}
           <div>
              <FaStarHalf/>
           </div>
           </div>
);   
}

if (rating >= 5){
    return (
        <div>
        {[...Array(5)].map((star, i) => {
             return (
               <div>
                  <FaStar/>
               </div>
          );   
        })}
        </div>
);   
}
};
export default StarRating;

SvelteKit build (w/ adapter-node) 404 on newly created static files

Using @sveltejs/adapter-node: 1.0.0-next.61 and @sveltejs/kit: ^1.0.0-next.225

The following issue occurs only on the build version of the app, and not on the dev server, on which it doesn’t occur.

When uploading a new file, my app keeps returning 404 regarding those newly created files as though the app is blind to those. Interestingly enough, said images are found when restarting the server.

The creation request succeeds: POST REQUEST 200

The file is correctly created on the filesystem and should be loaded by the page as seen in the json response which lists all files to be loaded on the page: file exists

However, when attempting to fetch the file, the server responds with a 404 although the path to it is correct: 404

parse line-separated json objects in html table

I can’t change json format. The data store in new line.
json file:

{"ProgMode":"on","wait_h":"5","wait_m":"5","output":"1"}
{"ProgMode":"off","wait_h":"10","wait_m":"10","output":"2"}

I using below code but without bracket ([]) in json file, it doesn’t work.

    var ReqJson = new XMLHttpRequest();
function response(){
    if(this.readyState == 4 && this.status == 200){
        var myObj = JSON.parse(this.responseText);
        const dbParam = JSON.stringify({table:"ProgramView",limit:20});
        let text = "<table class='table my-0'>"
        for (let x in myObj) {
        text += '<tr><td>' + myObj[x].wait_h + ':' + myObj[x].wait_m + ':' + myObj[x].output + '</td></tr>';
        }
        text += "</table>"    
        document.getElementById("dynamic_table").innerHTML = text;
    }
}

function ProccessConfig(){
    ReqJson.open("POST", "Programs.json", true);
    ReqJson.onreadystatechange = response;
    ReqJson.send()
}
ProccessConfig();

So how can I parse json that is stored with new lines and without comma and brackets?

How to use js variable in scss?

In vite project, I defined an env variable in .env:

VITE_THEME=1

And I have a variables.scss file to define a variable:

$theme-color: red;

I can use import.meta.env.VITE_THEME to get VITE_THEME in js, but now I want to use it in variables.scss to change the theme-color like:

$theme-color: import.meta.env.VITE_THEME == 1 ? red : yellow;

How can I do this?

error – Error: Must initialize before using hooks

I have just created a fresh Next app, and after adding line no. 6, I’m getting error. Why. Please answer it ASAP. Thanks in advance

like this —
enter image description here

import Image from "next/image";
import styles from "../styles/Home.module.css";
import { useConnectWallet, useSetChain, useWallets } from "@web3-onboard/react";

const Home = () => {
  const [{ wallet }, connect, disconnect] = useConnectWallet();
  const [{ chains, connectedChain, settingChain }, setChain] = useSetChain();
  const connectedWallets = useWallets();
  return (
    <div className={styles.container}>
      <Head>
        <title>New - emax</title>
        <meta name="description" content="Generated by create next app" />
        <link rel="icon" href="/favicon.ico" />
      </Head>
      <main className={styles.main}>
        <p>Instantly deploy your Next.js site to a public URL with Vercel.</p>
      </main>
    </div>
  );
};```

Text disabled when using GSAP

I’m using the GSAP library for JS animations, and for some reason, when using the animations, my text (p tags, a tags, navbars…) are disabled and I can’t click on them anymore for further animations, which is a bit annoying.

Does anyone know how to fix that?

const landingMsg = document.querySelector(".landing-msg")
const navBar = document.querySelector("nav")
const whoBtn = document.querySelector(".who")
const whoWhen = document.querySelector(".who-when")

const tl = new TimelineLite({ paused: true })

gsap.fromTo(
  ".landing-msg p",
  1,
  { opacity: "0", y: "100" },
  { opacity: "1", y: "0", ease: Bounce.easeOut }
)

gsap.fromTo(
  ".landing-msg p",
  1,
  { opacity: "1" },
  { opacity: "0", delay: "2", ease: Power2.easeInOut }
)

gsap.fromTo(
  "nav",
  1,
  { opacity: "0", y: "-30" },
  { opacity: "1", y: "0", delay: "1.7", ease: Power2.easeInOut }
)

tl.to(".who-when", 1, { opacity: "1", ease: Power2.easeInOut })

whoBtn.addEventListener("click", () => {
  tl.play()
})

Knowing which Touch object is which in Javascript

I want to know which Touch object is which.

First attempt

I attempted to identify the Touch objects by storing the index in a variable
and getting the Touch object from the TouchList with the index. But the problem with this method is when there are 3 Touch objects in the TouchList like this:

[1, 2, 3]

Then when the user lifts 1 the Touch object will be removed like this:

[2, 3]

My program will start to confuse Touch object 2 as 1.

Second attempt

I also tried to identify the Touch objects by storing it in a variable
and checking if the Touch object matches the one in the variable.
But that did not work because it is not the same object from before.

Loading a module with plain javascript is not working

I am importing a module with plain js file like so:

import * as Highcharts from 'highcharts';

Highcharts.chart('container', {

    title: {
        text: 'Solar Employment Growth by Sector, 2010-2016'
    },

    subtitle: {
        text: 'Source: thesolarfoundation.com'
    },

    yAxis: {
        title: {
            text: 'Number of Employees'
        }
    },

    xAxis: {
        accessibility: {
            rangeDescription: 'Range: 2010 to 2017'
        }
    },

    legend: {
        layout: 'vertical',
        align: 'right',
        verticalAlign: 'middle'
    },

    plotOptions: {
        series: {
            label: {
                connectorAllowed: false
            },
            pointStart: 2010
        }
    },

    series: [{
        name: 'Installation',
        data: [43934, 52503, 57177, 69658, 97031, 119931, 137133, 154175]
    }, {
        name: 'Manufacturing',
        data: [24916, 24064, 29742, 29851, 32490, 30282, 38121, 40434]
    }, {
        name: 'Sales & Distribution',
        data: [11744, 17722, 16005, 19771, 20185, 24377, 32147, 39387]
    }, {
        name: 'Project Development',
        data: [null, null, 7988, 12169, 15112, 22452, 34400, 34227]
    }, {
        name: 'Other',
        data: [12908, 5948, 8105, 11248, 8989, 11816, 18274, 18111]
    }],

    responsive: {
        rules: [{
            condition: {
                maxWidth: 500
            },
            chartOptions: {
                legend: {
                    layout: 'horizontal',
                    align: 'center',
                    verticalAlign: 'bottom'
                }
            }
        }]
    }

});

and imported to index.html file as module like this:

<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <figure>
        <div id="container"></div>
    </figure>
    <script type="module" src="./index.js"></script>
</body>

</html>

but the Higcharts not available with my browser. getting error as:

Failed to resolve module specifier "highcharts". Relative references must start with either "/", "./", or "../".

how to import modules in plain js files?

How to add obectID from on schema to another in mongoDB?

I’m working on a multivendor cake selling project.
the situation is the user can customize their cakes.
to store that in mongo I can do simple post method and add it to mongo schema but the user info(id,name,phone,address) should be there too.
how can I store the user info in the customize cake schema?

code I wrote is below.

exports.addCustomCake=(req,res)=>{
customCakeModel({
    user_id:req.saved_user._id,
    order_By:req.saved_user.name,
    phone:req.saved_user.phone,
    address:req.saved_user.address
    weight:req.body.weight,
    flavour:req.body.flavour,
    shape:req.body.shape,
    layers:req.body.layers,
    sponge:req.body.sponge,
    cakeType:req.body.cakeType,
    creamLevel:req.body.creamLevel,
    fondantLevel:req.body.fondantLevel,
    fondantCreamLevel:req.body.fondantCreamLevel,
    paintCake:req.body.paintCake,
    fillings:req.body.fillings,
    effects:req.body.effects,
    writingOnCake:req.body.writingOnCake,
}).save((err,customCake)=>{
    if(!err){
        res.status(200).json({
            status:'success',
            result:customCake,
            message:'Custom cake added...'
        });
    }else{
        res.status(404).json({
            result:err,
            message:'Custom cake add failed.'
        })
    }
})

}

How to implement an abstract method in Typescript

I have created the Controller abstract class with the abstract method executeImpl, once I instantiate it and run

const exampleController = new ExampleController;
exampleController.execute(req, res);

In the classes that I have extended this abstract class the executeImpl method is implemented

The error appears that:

TypeError: this.executeImpl is not a function
export abstract class Controller {
  protected abstract executeImpl(
    req: NextApiRequest,
    res: NextApiResponse
  ): void | any;

  public async execute(
    req: NextApiRequest,
    res: NextApiResponse
  ): Promise<void> {
    try {
      await this.executeImpl(req, res);
    } catch (err) {
      console.log(req.url);
      console.error(err);
    }
  }
}

It doesn’t seem to recognize it within this

Disable a function for a specific time

I currently have a function that scans a barcode or QR code and returns the result:

    function onScanSuccess(decodedText, decodedResult) {
        console.log(`Code scanned = ${decodedText}`, decodedResult);
    }
    var html5QrcodeScanner = new Html5QrcodeScanner(
        "qr-reader", { fps: 10, qrbox: 250 });
    html5QrcodeScanner.render(onScanSuccess);

It works great but the problem i have is that it scans the code very fast and multiple times.

enter image description here

Is there a way to timeout the function so it only return the scans every second?

Rotated Ellipse Collision Detection – Konva

I am currently working on Ellipse collision detection. I found a calculation for ellipse collison but it is not working for rotated ellipse with certain angle. I have the angle of rotation and ellipse coordinates , semi-major and semi-minor axis but the could not be able to fix the issue. Is there any library available for it or can you help me with this Problem.

Here is the calculation i have,

var dx= mousepointx – x;
var dy=mousepointy – y;

a- semi- major axis
b – semi minor axis
mousepointx, mousepointy- the point which i check for collision

((dxdx)/(aa)+(dydy)/(bb) <= 1);

and for rotated ellipse which i am currently having,

(((aa ) (Math.pow(Math.sin(angle), 2)) + bb * (Math.pow(Math.cos(angle), 2)) ) * dxdx + 2 * (bb – aa) * (Math.sin(angle)) * (Math.cos(angle)) * (dx * dy) + ((a * a) * (Math.pow(Math.cos(angle), 2)) + (bb) * (Math.pow(Math.sin(angle), 2)) ) * (dydy) <= aab*b );

which is not working. Thanks for the help.