JS import in Vue Single File Component Leads to Error

Here is a sample template I have constructed:


<template>
</template>

<script>
const Vue = require("vue")

</script>

This compiles cleanly and causes no issues. However if I do:


<template>
</template>

<script>
import Vue from "vue"

</script>

I get this error:

process-update.js:32 
        
       TypeError: Cannot set properties of undefined (setting 'render')
    at normalizeComponent (componentNormalizer.js:24:1)
    at Module../components/test.vue (test.vue:8:27)
    at __webpack_require__ (bootstrap:853:1)
    at hotApplyInternal (bootstrap:749:1)
    at Object.hotApply [as apply] (bootstrap:411:1)
    at cb (process-update.js:76:1)
    at process-update.js:91:1

Does anyone know what may be going on?
Thanks in advance!

Where to learn Javascript framework/library authoring?

Any search I try to make on this subject only yields results for learning existing JS frameworks. But I want to know what these guys know to write such frameworks themselves. When I checked out @headlessui/react for example, thinking it had simple enough components from which I can understand some basics of library development, I find they’re still quite complex—the code structure, modular architecture, component organization and data flow… All that could be overwhelming. Very much different from what I would write if I were to create a simple, reusable component the best way I could think of!

I think it’s more than just JavaScript design patterns I need to know. I’d like to write code and build things that people would use, but I find out there’s still much I need to know. Can someone help me as to what resources/books can launch me in that direction? I’ve tried many times but never found what I was looking for. I already know and understand JavaScript so it makes me wonder where these guys are learning from.

how to sum each specific rendered row horizontally on jquery datatable

I get data for datasrc from sql query and I display for each column using

"data": "attribute", "name": "name",
                    "render": function (data, type, full, meta) {}

I can’t get calculate value from sql query, I have to get each rendred value of specific row to sum and put the result in each column horizontally
exemple bellow of eachrow : row 1 col1 + row 1 col2 + row 1 col3 and put te result in row 1 col4

and the same for all horizontal ligne.

Rows                  Col1        Col2      Col3    Col4  col5      col6      col7 
1                      12         1         23       36    string    string   string
2                       1         0          5       6     string    
3                       6         2          9       16    string    

for this jquery datatable serverside Showing 1-10:

"autoWidth": true,
            "processing": true,
            "serverSide": true,
            "ajax": {
                'type': 'POST',
                'url': 
                'dataSrc':function (json) {
                   

                    return json.data;
                },
                'complete': function (response) {
                   
                }
            },
            "columns": [
                {"data": "id"},
               {"data": "attribute", "name": "name",
                    "render": function (data, type, full, meta) {}
}
                    ---
                  ---

Getting the best possible time from a list of trajectories

I have a problem I am working on as homework and I am having trouble figuring out how to solve it and if the approach I am taking can be optimized.

The problem is the following:

As an input I received this :

const inputFull = `08:20;Paris;Berlin
5
09:20;Paris;Amsterdam;03:20
08:30;Paris;Bruxelles;01:20
10:00;Bruxelles;Amsterdam;02:10
12:30;Amsterdam;Berlin;06:10
11:30;Bruxelles;Berlin;09:20`;

The first line is: start_date, start_city, finish_city
The second line is: Number of lines that will follow
The third line is: a list of all trajectories in this format: start_date, start_city, finish_city, duration (HH: mm)

My expected output: the best you can reach the finish_city ( in this case 18:40 )
and the trajectory will be ( line 2 -> line 3 -> line 4 )

This is what I implemented so far, I hit a dead-end I know I am supposed to use recursion but not sure how?

const bestTime = (
  startTime,
  startCity,
  finishCity,
  listTravelSize,
  listTravel
) => {
  var startTimeIter;
  var startCityIter;
  const markTime = [];
  const listTravelSecondIter = [];
  // check only cities that start with the same start city
  const listTravelFiltered = checkCities(listTravel, startCity, startTime);
  // recursion part
  listTravelFiltered.map((item) => {
    // item is of ListTravel type
    startTimeIter = sumTime(item.startTime, item.duration);
    startCityIter = item.finishCity;
    // check if the finish city is the same as the finish city
    if (startCityIter === finishCity) {
      markTime.push(startTimeIter); // first duration + 
    }
    const travel = {
      startTime: startTimeIter,
      startCity: startCityIter,
      finishCity: finishCity,
      duration: item.duration,
    };
    listTravelSecondIter.push(travel);
  });
  bestTime(
    startTimeIter,
    startCityIter,
    finishCity,
    listTravelSecondIter.length,
    listTravelSecondIter
  );
};

React.js – Styled components – center image in direct div parent with other objects

I understand that question looks pretty easy, but I haven’t found anything helping me.

I have an image inside a div, and I want that image to be centered in that div even if I add, for example, a text.

Here is some code and images to better understand that problem :

If I only have my image in my div (with solid border), all is well :

<div>
    <img height = '75px' width = '75px' src={USDCoin}/> 
</div>      

enter image description here

But adding a text, I can’t figure out how to keep the image in the center of the div (well aligned with the grey lines) and the text below that :

<div>
    <img height = '75px' width = '75px' src={USDCoin}/> 
    test
</div>  

enter image description here

Thank you in advance for your precious help !

Discord.js || Can bot track ban list?

There are a lot of to ban a user in a server, you can do it manually or with another bot. I want my bot to scan a banlist, and if someone will get banned, it will send a message “user (id) has been banned

I started writing smt but now, I had no idea what can I do to check it.

client.on('guildBanAdd', messsage =>{

  try {
  const banList = await message.guild.fetchBans();
  if (bannedUser) await message.channel.send(`${bannedUser.tag} is banned.`);
  
})

Unable to center element horizontally and vertically

I’m making my personal website (available at https://wnetmc.github.io/ and all my code is on https://github.com/wnetMC/wnetmc.github.io) and I think i broke something because the text “wnet” and the links are not centered anymore. Yet I am using

<div class="content d-flex align-items-center">

and

<div class="container text-center">

I know this question will get downvoted to hell but if someone could answer, id really appreciate it. Thank you.

edit: entire website seems to be broken on github pages, but works fine when i download it… I don’t know what’s happening.

.env setup to hide key

I’m fairly new to javascript and wanted to hide my API key. Can’t seem to get dotenv to work. I’ve followed the steps on the dotemv documentation but no luck. First i ran “npm install dotenv –save” which added the following files/folders into my project

  • Node_modules folder
  • package-lock.json
  • package.json

app.js

import "dotenv/config"; 
import express from "express";
require("dotenv").config();

console.log(process.env.API_KEY);
const API = API_KEY;

.env

API_KEY = "123"

Uncaught TypeError: Failed to resolve module specifier “dotenv/config”. Relative references must start with either “/”, “./”, or “../”.

I tried adding the “/” and “./” but the same error. it’s in the same location.

Custom crop method isn’t working in iPhone

Im facing this STRANGEST issue in my website. The method given below takes a base64 string and the crop, zoom and rotation values and returns a modified base64 string. This method works absolutely fine on all the android devices and desktops. But when an iPhone is used, this methods returns a base64 string that when converted is a plain black image. I have no clue why its behaving like this on all the iPhones.

Extra info : This only happens for the HEIF images that are automatically converted to jpeg when a user selects them from the iPhone’s gallery. For other formats like jpg and png the method works fine even on iPhone.

Here’s the crop method

async function getCroppedImg(imageSrc, pixelCrop, rotation) {

        console.log('imagesrc : ', imageSrc)
        const image = await createImage(imageSrc);
        const canvas = document.createElement("canvas");
        const ctx = canvas.getContext("2d");
        const maxSize = Math.max(image.width, image.height);
        const safeArea = 2 * ((maxSize / 2) * Math.sqrt(2));
        canvas.width = safeArea;
        canvas.height = safeArea;

        ctx.translate(safeArea / 2, safeArea / 2);
        ctx.rotate(getRadianAngle(rotation));
        ctx.translate(-safeArea / 2, -safeArea / 2);
        ctx.drawImage(
            image,
            safeArea / 2 - image.width * 0.5,
            safeArea / 2 - image.height * 0.5
        );

        const data = ctx.getImageData(0, 0, safeArea, safeArea);
        canvas.width = pixelCrop.width;
        canvas.height = pixelCrop.height;

        ctx.putImageData(
            data,
            0 - safeArea / 2 + image.width * 0.5 - pixelCrop.x,
            0 - safeArea / 2 + image.height * 0.5 - pixelCrop.y
        );

        // As Base64 string
        return canvas.toDataURL("image/jpeg");
    }

const createImage = (url) =>
        new Promise((resolve, reject) => {
            const image = new Image();
            image.addEventListener("load", () => resolve(image));
            image.addEventListener("error", (error) => reject(error));
            image.setAttribute("crossOrigin", "anonymous");
            image.src = url;
        });

function getRadianAngle(degreeValue) {
        return (degreeValue * Math.PI) / 180;
    }

object Object Keeps Persisting on my Static S3 Website [duplicate]

I have tried the JSON.stringify method and the Console.Log method and neither have worked for me. I am hosting a static S3 website with APIGateway, Lambda, and DynamoDB.

const countEl = document.getElementById('count');


updateVisitCount();
//Testinglllll
function updateVisitCount() {
 fetch('https://8zsb3och04.execute-api.us-east- 
 2.amazonaws.com/Prod')
  .then(response => {
   return response.json()
    })
     .then(data => {

    let countEl = data;
     console.log(data)
      document.getElementById('count').innerHTML = data;
        })
}[Dynamo Table][1]

ref prop is not passed, TypeError: null is not an object (evaluating ‘inputRef.current.focus’)

I am making a custom input component


const CustomInput = (props) => {
  console.log(props);
  return (
    <TextInput
      {...props}
      ref={props.ref}
      placeholder={props.placeholder}
      style={{ ...styles.text, ...props.style }}
    />
  );
};

in the file I want to use it I have

const ForgottenPasswordScreen = (props) => {
...
const inputRef = React.createRef();

  useEffect(() => {
    inputRef.current.focus();
  }, []);
...

<CustomInput
          placeholder={"E-mail..."}
          value={email.value}
          ref={inputRef}
          onChangeText={(text) => setEmail({ value: text, error: "" })}
        />
...

If I am using normal TextInput there is no problem, but when I try to use my CustomInput,
i get the error

TypeError: null is not an object (evaluating ‘inputRef.current.focus’)

I don’t get why ref={props.ref} is not doing the job. I thought that ref will be passed to my component too. How to pass ref properly ?

asp:GridView allow Edit button, but remove Update and Cancel buttons

This one is pretty straightforward. The asp:GridView automatically adds an Edit hyperlink to the left of every column like this:

enter image description here

which is fine because I need that functionality anyways. However, I’ve made it so clicking the Edit hyperlink brings up a new panel that allows the user to edit more properties than are shown in the GridView, so I don’t want the Update and Cancel buttons to appear after clicking Edit.

enter image description here

Ive added the Edit functionality by implementing an event handler that Handles GridView.RowCommand when e.CommandName = “Edit”. I would like to just keep the Edit hyperlink there, or maybe programatically click Cancel, or really anything that will keep the Update and Cancel hyperlinks from showing when the user finishes working with the Edit panel. I’ve tried calling the event handler and sending in args with e.CommandName = “Cancel” but that didn’t work.

Another option I’m willing to explore is removing the Edit button entirely and making my event handler handle a different event, but I haven’t found any good resources for that either. Mostly it’s people trying to disable an Edit button that they’ve manually created on certain rows. I didn’t create this Edit hyperlink, though, and I can’t get it to go away.

How to return each separate item in a for loop

I am using a for loop to loop and extract the names of “people in space” from an API. The variable “people” in the for loop returns all 13 names of the people in space as a string. I then want to insert each name into a list using a template literal. When I run the code as I have it, only the first name shows up on the page 13 times. How do I adjust the code so that all 13 names show up, and not 1 name 13 times?

const peopleInSpace = async function() {
    try {
        const res = await fetch('http://api.open-notify.org/astros.json');
        const data = await res.json();

        for(let i = 0; i < data.people.length; i++) {
            const people = data.people[i].name;
            console.log(people);

            const markup = `
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>
            <li class="list--item"><span>Name:</span> ${people} <span>Craft:</span> ISS</li>

            
            
            `;
            peopleContainer.innerHTML = markup;
            
        }

Text wrapping, right aligned icon, and button height with Bootstrap 5 button with flex box

Using Bootstrap 5 button code with centered text and a right aligned icon with multiple buttons in a flex box situation, how do I stop the button text overlapping the icon when it wraps, and how do I set the height of the button while keeping the text center aligned vertically when it wraps?

You can see whole code with the wrapping and overlapping issues in this fiddle by moving the center column with your mouse and making the display area bigger and smaller.

Here’s the html code for a single button:

 <a href="#" target="_blank" class="btn custom-btn" onmouseover="openRegion(event, 't1')">This Section<img src="https://svgshare.com/i/fPK.svg" class="icon-arrow-new" /></a>

Here’s the css (on top of Bootstrap 5):

.custom-btn, .custom-btn:visited {
    position: relative; 
    padding: 1.5rem 0.5rem;
    margin: 0.5rem 0.5rem;  
    font-size: 0.95rem;
    border-radius: 0;
    line-height: 1.2rem;
    background-color: #c1c1c1;
    border-color: #c1c1c1;
    flex: 33%;
    text-transform: uppercase;
    color:#fff;
    box-sizing: border-box;
    letter-spacing: 0.8px;
    height: 70px;
  }
  .custom-btn:active, .custom-btn:hover {
    background-color: #7d7c7c;
    border-color: #787878;
    text-transform: uppercase;
    color:#fff;

  }
  .icon-arrow-new{
    position: absolute;
    right:10px; 
    width: 22px;
  }

Change button image on jwplayer

I have implemented the newest JW Player (8.24) and I would like to customize it, so that it has a fast forward button. Standard only has a -10 sec rewind. it would be nice with a forward +10 sec as well. And someone has already done it! And I have also implemented this script but it only show the icon in – transform = “scaleX(-1)”; – which shows the icon reversed, which is kind a drag. Is there anyone who is good at javascript who can help a noob with this small problem?

How can I get the icon/image not to be shown in reverse, or how can I replace it?

The script which I implemented is this:

const playerContainerSelector = '#jwplayer-container';
const player = jwplayer('#player');
const playerContainer = document.querySelector(playerContainerSelector);

// display icon
const rewindContainer = playerContainer.querySelector('.jw-display-icon-rewind');
const forwardContainer = rewindContainer.cloneNode(true);
const forwardDisplayButton = forwardContainer.querySelector('.jw-icon-rewind');
forwardDisplayButton.style.transform = "scaleX(-1)";
forwardDisplayButton.ariaLabel = "Forward 10 Seconds"
const nextContainer = playerContainer.querySelector('.jw-display-icon-next');
nextContainer.parentNode.insertBefore(forwardContainer, nextContainer);


// control bar icon
playerContainer.querySelector('.jw-display-icon-next').style.display = 'none'; // 
hide next button
const buttonContainer = playerContainer.querySelector('.jw-button-container');
const rewindControlBarButton = buttonContainer.querySelector(".jw-icon-rewind");
const forwardControlBarButton = rewindControlBarButton.cloneNode(true);
forwardControlBarButton.style.transform = "scaleX(-1)";
forwardControlBarButton.ariaLabel = "Forward 10 Seconds";
rewindControlBarButton.parentNode.insertBefore(forwardControlBarButton, 
rewindControlBarButton.nextElementSibling);

// add onclick handlers
[forwardDisplayButton, forwardControlBarButton].forEach(button => {
   button.onclick = () => {
    player.seek((player.getPosition() + 10));
   }
})

The script is from this github thread:
https://github.com/jwplayer/jwplayer/issues/3894

Any help is is much obliged.