webpack dev server doesn’t recognize JSX code

I’m trying to get a React project running with webpack-dev-server. The project runs, but when I start the dev server with yarn run webpack-dev-server, I get the following message:

ERROR in ./app/javascript/components/index.jsx 9:14
Module parse failed: Unexpected token (9:14)
You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js.org/concepts#loaders
|     document.body.appendChild(document.createElement("div"))
|   );
>   root.render(<App />);
| });

What am I missing from my toolchain? The full repo is available here:
https://github.com/fredwillmore/billboard

How can one convert an irregular time series plot into a regular time series in Excel, involving earthquake data as an example

I’m working with earthquake data, and it’s irregular. I’m attempting to convert it into a regular format, considering factors such as the annual frequency. However, I’m uncertain about the steps to visualize and implement this transformation in Excel.

I attempted to solve it on my own using various methods, but I haven’t been successful so far.

Lodash group item into mini-array based on another key’s value

I’m parsing some json made from a midi file (I’ll be doing this a lot for a game I’m making) and I an easy way to do it using Lodash.

I’ve tried .groupBy and .filter and a couple other methods, they aren’t working

This is what I want to go from:

{
  "name": "F4",
  "midi": 65,
  "time": 0,
  "velocity": 1,
  "duration": 0.8
},
{
  "name": "C5",
  "midi": 72,
  "time": 0,
  "velocity": 1,
  "duration": 0.8
},
{
  "name": "C#4",
  "midi": 61,
  "time": 0.8,
  "velocity": 1,
  "duration": 0.8
},
{
  "name": "F4",
  "midi": 65,
  "time": 0.8,
  "velocity": 1,
  "duration": 0.8
},
{
  "name": "C5",
  "midi": 72,
  "time": 0.8,
  "velocity": 1,
  "duration": 0.8
}

And this is what I’m trying to get as an output:

{
  "notes": ["F4","C5"],
  "time": 0,
  "volume": 1,
  "duration": 0.8
},
{
  "notes": ["C#4","F4","C5"],
  "time": 0.8,
  "volume": 1,
  "duration": 0.8
},

The "notes" are condensed into an array based on the "time" value.

Trying to concatenate a variable in Javascript

I am trying to concatenate a variable in Javascript. Here is my code:

for (let i = 1; i < 11; i++) {
    for (let j = 1; j < 10; j++) {
      let data = data+arr[i,j];
  }
}

The array arr has 10 rows and 9 columns and is filled with data. I want to create a new data string called data with all the values in the array arr. Do you know why this doesn’t work?

I tried using this code:

for (let i = 1; i < 11; i++) {
    for (let j = 1; j < 10; j++) {
        let data = data+arr[i,j];
  }
}

What are the differences between elastic email features and do I have to pay a fee?

I made myself a project from javascript with elastic email, I will do things like a password reset link here, but I have a question like this in elastic, elastic email marketing is limited to 1000 people, I think it is 0$, on the other hand, I think the email api is 0$ and unlimited people, I guess, if I switch to email api, will it be a problem, will there be an extra fee, can you give detailed information, I don’t have full information, I am newer about this subject.

Translated with Deepltranslate (from Turkish)

At the moment it sends e-mails, but what are the differences between limited people and of course I don’t have a group of 1000 friends, but the unlimited tariff is appetizing?

How to use FinalizationRegistry to clear interval inside a class constructor when object is destroyed?

I have this code created with help from ChatGPT:

class Thing {
    #intervalId;
    #finalizationRegistry;
    constructor() {
        console.log('constructor()');
        let count = 0;
        this.#intervalId = setInterval(() => {
            console.log(`Test ${count++}`);
        }, 1000);

        this.#finalizationRegistry = new FinalizationRegistry(() => {
            this.#destructor();
        });
        this.#finalizationRegistry.register(this);
    }
    #destructor() {
        console.log('destructor()');
        clearInterval(this.#intervalId);
    }
}

(() => {
    const x = new Thing();
})();

This is my attempt to create a destructor for a class in JavaScript. I’m not sure if it works because the console.log('destructor()'); was not called when I tested. My first code used a dummy object inside the constructor as a help value and that was working, it was triggering when I assigned x = null but the code was wrong.

The above code is just the smallest possible example of clearing setInterval with FinalizationRegistry but I’m not sure if it works.

Is there a way to test that this actually works and call destructor?

My real question is that I want to implement Cache class and I need to trigger this function inside interval:

this.#intervalId = setInterval(() => {
   this.#prune();
}, 1000);

And I want to clear the timer when this is not accessible anymore. Like with the above code:

(() => {
    const x = new Thing();
})();

Can you create an interval inside the class constructor that references this and clear the interval when the object is garbage collected? Can the object even be garbage collected when intervals keep a reference to this? If not then is there a workaround?

Unexpected Token on Type Import from a TS File to a Svelte File

(I’m new to coding so I apologize if I explain this poorly)
Whenever I try to import a type from my “types.ts” file into my “+page.svelte” file, I am encountered with a “Unexpected Token” error at runtime. The error message points to the first “{” in the import statement, calling that the unexpected token.

//Svelte File

<script lang="ts">
    import type { task } from "../lib/types"

    let toDo : task
//Typescript File

export type task = {
    name : string,
    done : boolean,
    desc : string
}

I’ve tried uninstalling and reinstalling a lot of different extensions including: Bun, Vite,and JS/TS. I’ve tried to rewrite the code from scratch in a few different files but I encounter the error in each one. What’s weird is that the error doesn’t show up right away, and sometimes it shows up as an error in my code (pre-runtime), and other times it doesn’t.

Is it guaranteed that the onload event of a new Image returned by a function will be executed after the return?

Consider this minimal reproducible example:

let src = 'https://fetch-progress.anthum.com/120kbps/images/sunrise-baseline.jpg';

let example = null;

function test(inSrc) {
  let image = new Image();

  image.onload = function () {
    if (example.src === src) {
      example = null;
    }
  }

  image.src = inSrc;

  return image;
}

example = test(src);

Is it guaranteed that the onload event will be executed after the new image object is assigned to ‘example’ and, therefore, after loading the image, example will be null again, regardless of the size of the source? Or could onload be executed just before the return?

Apparently it always runs after the return in all my tests, but I would like to determine if it is 100% guaranteed. I would appreciate a reference that explains how it works. Thank you!

easeOutQuart implementation with equal operator in mathematical function in JavaScript

I don’t understand this implementation of the easeOutQuart function from this repository: https://gist.github.com/CGamesPlay/8628541:

easeOutQuart: function (t) {
    return -1 * ((t=t/1-1)*t*t*t - 1);
},

I can’t figure out how works the (t=t/1-1) term. The equal operator is the assignement operator, why is it in the middle of this mathematical function?

Can anyone enlighten me?

Use optionnal/undefined array in generic with Typescript

With Typescript and a much more complex project than the one presented, I want to create many collections based on the same model:

type BaseItem = {
  id: string;
};

type Item1Type = BaseItem & {
  name: string;
};

type Item2Type = BaseItem & {
  amount: number;
};

type CollectionType<I> = {
  'hydra:member': I[];
};

type StateType<I> = CollectionType<I>;

const test = <I extends StateType<I['hydra:member'][0]>>(data: I) => {
  return data;
};

const data1: StateType<Item1Type> = {'hydra:member': [{id: 'a', name: 'a'}]};
const data2: StateType<Item2Type> = {'hydra:member': [{id: 'a', amount: 1}]};

const result1 = test(data1);
const result2 = test(data2);

Here, everything works fine and result1/result2 returns correctly typed data :

enter image description here

But with exactly the same code, if I try to make StateType can be undefined i have this error :

type StateType<I> = undefined | CollectionType<I>;

// TS error : The type '"hydra:member"' cannot be used to index type 'I'.ts(2536)
const test = <I extends StateType<I['hydra:member'][0]>>(data: I) => {
  return data;
};

I understand that since StateType is potentially undefined, it’s no longer possible to rebuild it with the hydra:member key, but I’d like to make this optional (StateType = array correctly typed with Item1Type/Item2Type or undefined).

enter image description here

How to reference item iterated on inside a v-for?

In the code below I display an image multiple times n=0,1,2 using a v-for, and I wish for an alert with the n number corresponding with the image to appear whenever such image is hovered over.

Of course, with the code below I get an n is not defined error whenever I hover over an image. What is the correct way to implement the code?

App.vue:

<template>
  <div>
    <img v-for="n in [0,1,2]" v-bind:key="n" 
    src="something.png" onmouseover="alert(n)">
  </div>
</template>

Stream down file with strapi

after few days of testing and trying I am stuck…

My goal is, to stream an audio file down to client. With range headers and so on.
Important, I need a stream, coz’ I am planing to implement some analytics.

What I have done:

I have a custom api

'use strict';
const fs = require('fs');
const path = require('path');

module.exports = {
  streamFile: async (ctx, next, i) => {
    const mediaId = ctx.params.id;
    const entry = await strapi.entityService.findOne('plugin::upload.file', mediaId, {});
    const file = path.join(__dirname, '/../../../../public/' + entry.url);

    let stats = fs.statSync(file);
    let start, end;
    let total = stats.size;
    let range = ctx.req.headers.range;

    if (range) {
      let positions = range.replace(/bytes=/, "").split("-");
      start = parseInt(positions[0], 10);
      end = positions[1] ? parseInt(positions[1], 10) : total - 1;
    } else {
      start = 0;
      end = total - 1;
    }

    let chunksize = (end - start) + 1;
    let stream = fs.createReadStream(file, { start: start, end: end })

    ctx.res.writeHead(206, {
      "Content-Range": "bytes " + start + "-" + end + "/" + total,
      "Accept-Ranges": "bytes",
      "Content-Length": chunksize,
      "Content-Type": entry.mime
    });

    ctx.status = 206;

    await next();

    ctx.body = stream;
  }
};

If I call the url directly (no audio client) I receive an error in browser like unsupported type.

When I use tag, I see this in network

enter image description here
enter image description here

Any idea what to try?

PS: file is loaded correclty, the stats are there and overall only stream is not working