Error coming every time I try to run my code

Error: The module ‘?C:Usersncid1OneDriveDesktopBobloxnode_modulesbetter-sqlite3buildReleasebetter_sqlite3.node’
was compiled against a different Node.js version using
NODE_MODULE_VERSION 83. This version of Node.js requires
NODE_MODULE_VERSION 108. Please try re-compiling or re-installing
the module (for instance, using npm rebuild or npm install).

How do we trigger an onClick event on all element inside an imaginary rectangle with a given coordinate in vanilla javascript?

How do we trigger an onClick event on all element inside an imaginary rectangle with a given coordinate in vanilla javascript? Let’s assume that we have a rectangle with the following xy coordinate (0,30) (0,40) (30,30) (30,40), and I want to trigger an onClick event on every DOM element with class .select-element inside of that rectangle. How do I do this? Is it possible?

I saw there’s this method

Document.elementFromPoint()

But triggering this method for every coordinate seems like a bad idea for performance issues.

https://developer.mozilla.org/en-US/docs/Web/API/Document/elementFromPoint Also, it is relative to the viewport, and doesn’t accept a flag for using the absolute coordinate of a DOM element.

How do I implement the findAllHobbyists function that takes a hobby, and an object consisting of peoples names mapped to their respective hobbies?

// The function should return an Array containing the names of the people (in any order) that enjoy the hobby. I had this question on my first test for a job as a software engineer. I still have a lot to learn and practice, but any help on this question is appreciated! Below is what I have so far:

  function findAllHobbyists(hobby, hobbies) {
    let hobbyists = [];
    for (let hobby of hobbies) {
        for (let hobbyists of hobby.hobbyists) {
            if (!hobbyists.includes(hobby)) {
                hobbyists.push(hobby);
            }
        }
    }
        return [hobbyists];
  };
  
  var hobbies = {
    "Steve": ['Fashion', 'Piano', 'Reading'],
    "Patty": ['Drama', 'Magic', 'Pets'],
    "Chad": ['Puzzles', 'Pets', 'Yoga']
  };
  
  console.log(findAllHobbyists('Yoga', hobbies));

Applying pan limits to d3.js SVG viewbox when zoomed using translateExtent

Trying to limit the panning on my svg viewbox to the bottom right corner of the svg when zoomed. I have seen a few similar questions on here already but am still yet to find a working answer.

In my code below you’ll see that the zooming is working but with extent and translateExtent the panning ceases to work. As soon as I comment these 2 functions out the panning works but the limits are wrong (they are the coordinates of the bottom right hand corner of the svg but this causes the whole svg to be out of view).
I understand the current extent and translateExtent values are probably incorrect but I have played around with loads of different values and have failed to see any logical consistency to work with. For example setting the translateExtent to, say, [[0,0], [3000, 3000]] I’d expect the panning to be far greater than normal and be able to pan way off screen, however panning just stops working altogether?

I’m clearly misunderstanding something here. Please can someone tell me where I’m going wrong!
Thanks.

Live code here:
https://jsfiddle.net/9b7w4z58/1/

Image below illustrates how I intend the svg to look when panned fully.

enter image description here

HTML, JS calculator output number as NaN

I was trying to create a simple demo calculator and I got the output as NaN. I think it is something with the JS calling the input values. Please refer to the below code.

<!DOCTYPE html>
<html>
  <head>
    <title>Calculator</title>
  </head>
  <body>
    <div>
      <header id="screen"></header>
      <table>
        <tbody>
          <tr>
            <td>First Number:</td>
            <td name="firstNoInput"><input type="text" /></td>
          </tr>
          <tr>
            <td>Second Number:</td>
            <td name="secondNoInput"><input type="text" /></td>
          </tr>
          <tr>
            <td><button type="submit" onclick="addition()">+</button></td>
            <td><button type="submit" onclick="subtraction()">-</button></td>
          </tr>
          <tr>
            <td><button type="submit" onclick="multiplication()">*</button></td>
            <td><button type="submit" onclick="division()">/</button></td>
          </tr>
        </tbody>
      </table>
    </div>

    <script type="text/javascript">
      var num1 = document.getElementsByName(firstNoInput).value;
      var num2 = document.getElementsByName(secondNoInput).value;
      var ans;

      function addition() {
        ans = num1 + num2;
        document.getElementById("screen").innerHTML = ans;
      }

      function subtraction() {
        ans = num1 - num2;
        document.getElementById("screen").innerHTML = ans;
      }

      function multiplication() {
        ans = num1 * num2;
        document.getElementById("screen").innerHTML = ans;
      }

      function division() {
        ans = num1 / num2;
        document.getElementById("screen").innerHTML = ans;
      }
    </script>
  </body>
</html>

I even used the following code (convert values into strings), but it didn’t work.

var num1 = parseInt(document.getElementsByName(firstNoInput).value);
var num2 = parseInt(document.getElementsByName(secondNoInput).value);

Can anyone help?

Error with useAuth working with react router dom in react js

i am begginer in react , i need to protect a page with my login , but this not works , this is the error : Uncaught TypeError: Auth_context__WEBPACK_IMPORTED_MODULE_1_.useAuth() is null
here is my code…

import { useState, useCallback} from "react";
import { useNavigate } from "react-router-dom";
import { useAuth } from "./Auth.context";

const Login = () => {
const [username, setUsername] = useState("");
const { setUser } = useAuth();
const navigate = useNavigate();

const login = useCallback(
    (e) => {
        e.preventDefault();
        setUser({ username });
        navigate("/home");
    },
    [setUser, username]
);

return(
    <div>
        <h1>Inicie sesion</h1>
        <form onSubmit={login}>
            <input value={username}
            onChange={(e) => setUsername(e.target.value)}
            placeholder="Escriba el nombre de usuario"
            />
            <button type="submit">Login</button>
        </form>
    </div>
);

};

export default Login

Insert text into HTML/CSS e-mail with function from a different file

I have a html/css e-mail template that I want to use to send users e-mails for things like welcoming after signing up, send secret codes, and general purpose e-mails.

I need to “inject” this html template it with custom text instead of the lorem ipsum it currently contains.

I want to make a javascript function that inserts given text into my html template, this way my e-mail service can send custom e-mail to users based on their e-mail and custom messages throughout my node app as certain events are triggered.

I have a html/css e-mail in the file generalContact.html

I am unsure of 1 how “export” it so that makeEmail.js has access to the template and 2 how to format the html email so it can accept custom input text.

Do I have to assign the template to a variable first somehow?

Any help/guidance would be appreciated, thank you.

makeEmail.js

const htmlTemplate = require("generalContact.html")

const makeEmail = (bodyText) => {
      // How can I access the HTML file and insert the above input into it?
      return emailWithTextInserted 
}

module.exports = makeEmail

generalContact.html

<!DOCTYPE html PUBLIC "-//W3C/...." "http://www.w3.org/.....">
<html xmlns="http://www.w3.org......">
  <head>
    <title></title>
  </head>
  <body>
    <center>
      <tr>
        <td>
          This is Photoshop's version of Lorem Ipsum. Proin gravida nibh vel
          velit auctor aliquet. Aenean sollicitudin, lorem quis bibendum auctor,
          nisi elit consequat ipsum, nec sagittis sem nibh id elit. Duis
          <a>
          sit amet nibh vulputate cursus a sit amet mauris.<br /><br />

          Mauris in erat justo. Nullam ac urna eu felis dapibus condimentum sit
          amet a augue. Sed non neque elit. Sed ut imperdiet nisi. Proin
          condimentum fermentum nunc. Etiam
          <a>
          erat sed fermentum feugiat, velit mauris egestas quam, ut aliquam
          massa nisl quis neque. Suspendisse in orci enim.
        </td>
      </tr>
    </center>
  </body>
</html>

forEach returning undefined

This function goes through the arrays and in each object, add the 1st number and subtract the 2nd number

eg. number([[10,0],[3,5],[5,8]]) = (10-0) + (3-5) + (5-8) Total should equal 5

Problem: I’m using a forEach loop but it returns undefined, when I console.log the number shows 5.

var number = function(busStops){
  var total = 0;
  busStops.forEach(function(n){
    total = total + n[0] - n[1];
    return total;
  })
}

Is there a way to generate an object from another object by taking all its properties with except of one?

Having the initial object of this shape:

const initial = { a: 'a', b: 'b', c: 'c', d: 'd', ..., z: 'z' };

The result should contain all properties but without ‘b’ for example. I know there is a method like

const result = (({ a, b, c, d, ..., z }) => ({ a, c, d, ..., z }))(initial)

but in the case of an object with too many properties it’s too much code.

Is there a shorter way to do that?

JSON & API call is returning undefined

I’m trying to learn about basic API calls; I’m having issue with ‘dialing in’ to specific array objects in this Star Wars API.

I can console.log(json.people) or (json.planets), but cannot seem to go further than this, i.e. console.log(json.people.results) to show me an array of characters and associated data, as this shows as undefined…

I have attempted to parse / stringify the json, but am hitting a wall…

Would anybody be able to point me in the right direction?

Many thanks!

function getData() {

    url = "https://swapi.dev/api/?format=json";
    fetch(url).then((Response) => {
            return Response.json();
        })

        .then((json) => {
            console.log(json.people.results);
            console.log(json.planets);
        });      
}

getData();

page.evaluate runs for hours

I am trying to crawl the contents of a website and it works most of the time (finishes in minutes) but sometimes it takes up to 8 hours. I’ve managed to pinpoint the issue and it is fired in the page.evaluate part. Looking at the website in headless mode=false it just loads infinitely (after a click).

The code is the following:

    console.log("Test");
    let value = await page.evaluate((sel) => {
        let element = document.querySelector(sel);
        return element? element.innerHTML: null;
    },selector);
    console.log("Test2");

How to migrate modify a collections of object array in mongodb?

I have the following schema mongoose, but have a app in production with collections. This is a simplification of a much larger problem, reduced for better understanding.

This is only a sample basic.

export const ListSchema = new Schema({
  listaItemsIds: [
    {
        type: Schema.Types.ObjectId,
        ref: 'Items',
        default: [],
    },
  ],
});

I need to migrate all the data to the following model.

export const ListSchema = new Schema({
  listaItemsIds: [
    {
      item: {
        type: Schema.Types.ObjectId,
        ref: 'Items',
        default: [],
      },
      property1: {
        type: Number,
        required: false,
        default: 0,
      },
      property2: {
        type: Number,
        required: false,
        default: 0,
      },
    },
  ],
});

The following document

{
        "_id" : ObjectId("62bade11ff94fb9e5a0f5236"),
        "listaItemsIds" : [
                ObjectId("62a118a9167d269d38a4c806"),
                ObjectId("62baef0cff94fb9e5a0f53e3"),
                ObjectId("627bb4d61119d5ce2201b7df")
        ],
        "__v" : 37
}

it is necessary to transform

{
        "_id" : ObjectId("62bade11ff94fb9e5a0f5236"),
        "listaItemsIds" : [
                {
                    item:ObjectId("62a118a9167d269d38a4c806"),
                    property1:55,
                    property2:75,
                },
                {
                    item:ObjectId("62baef0cff94fb9e5a0f53e3"),
                    property1:55,
                    property2:75,
                },
                {
                    item:ObjectId("627bb4d61119d5ce2201b7df"),
                    property1:55,
                    property2:75,
                },              
        ],
        "__v" : 37
}

I have tried the following code snippet with no results.

db.ListSchemas.updateMany({},
    [
    {$set: {"listaItemsIds.$[elem]":
    {
      item:"listaItemsIds.$[elem]",
      property1:0,
      property2:0,
    }}}
    ]
    );

Surely someone with more experience can help me.

Cannot resolve type entity i6.CommonModule to symbol

We have a problem with our nativescript application. We recently migrated our nativescript project version 4.1.1 to 8.2.3. Now we are running into several problems that we are not able to solve.

I’m encountering webpack compilation error while running ‘ns run android’ command.

Please find the error message here

So we would really appreciate help with this problem. We know that we probably didn’t provide enough information, but we just don’t know what information is needed. So just let us know and we deliver.

Thanks for your help

typescript – create object from values in array

let’s say I have a model definition like this.

export interface Basicdata {
    materialnumber: number;
    type: string;
    materialclass: string;
}

I furthermore have an array with values, which match exactly the order of the Basicdata model, i.e.

["10003084", "S", "CLIP"]

I am searching for a way to create the object from these values in the array.
What I did is creating an empty object and iterating through the object keys, while assigning the array values.

const singleRow = rows[0];

const newBD: Basicdata = {
 materialnumber: 0,
 type: '',
 materialclass: '',  
}

for (let key in newBD) {
 newBD.materialnumber = singleRow[0];
 newBD.type = singleRow[1];
 newBD. materialclass = singleRow[];
}

But surely there is a better, more elegant way to do that, no?
I looked into map and reduce but could find a way.

Thank you.