Having problem with retrieving first 5 words from input

I have the following script which functionality should be to retrieve the first 5 words from one input and type them in a second input but it isn’t working as expected.

$('#review_content').on('keyup change paste click input', function () {
    
    var contentVal = $('#review_content').val();
    var contentValSplit = $('#review_content').val().split(' ');
    
    var headerValSplit = $('#review_header').val().split(' ');
    
    if(headerValSplit.length < 6) {
        if(contentValSplit.length > 6) {
            var $five = contentValSplit[0] + ' ' + contentValSplit[1] + ' ' + contentValSplit[2] + ' ' + contentValSplit[3] + ' ' + contentValSplit[4];
            $('#review_header').val($five + "...");
        } else {
            $('#review_header').val(contentVal + "...");
        }
    } 

});

When I paste longer text (longer than 5 words) the script is just pasting the same text in the second input but that’s not how it should work. It should get only the first 5 words from the whole text and paste only them in the second input. Or if the text is smaller than 5 words it should synchronously type the letters from the first input in the second one and stop after finishing the fifth word. Any ideas how to do that?

Adding thickness to lines in threejs

This is my demo, i want to add linewidth to give more thickness to my circle

I have looked to this question and i have tried to understand how i can use LineGeometry, LineMaterial and Line2

This is the relevant code

const curve = new THREE.EllipseCurve(
  0,
  0, // ax, aY
  10,
  10, // xRadius, yRadius
  0,
  2 * Math.PI, // aStartAngle, aEndAngle
  false, // aClockwise
  0 // aRotation
);

const points = curve.getPoints(50);
const geometryCircle = new THREE.BufferGeometry().setFromPoints(points);

const materialCircle = new THREE.LineBasicMaterial({
  color: 0xdddddd
});

const ellipse = new THREE.Line(geometryCircle, materialCircle);

How can i use these classes in the demo to give more thickness?

Any edit in the codesandbox it would be great to show me

TypeError: db.collection is not a function Firestore

TypeError: db.collection is not a function Firestore

I was presented this error in an attempt to import Firestore from the Firebase Admin SDK. Can’t find anything that helped, or if I imported it incorrectly

Code; index.js (main file)

var admin = require("firebase-admin");
var serviceAccount = require("./firebase/key.json");

admin.initializeApp({
  credential: admin.credential.cert(serviceAccount)
});

var db = admin.firestore()

Code; validate.js (import)

var db = require('../../../index')```

what is error create-react-app Unexpected error. Please report it as a bug:

what is showing error showing on reactjs Aborting installation. Unexpected error. Please report it as a bug:?

Aborting installation.
    Unexpected error. Please report it as a bug:
    Error: spawn UNKNOWN
        at ChildProcess.spawn (node:internal/child_process:412:11)
        at Object.spawn (node:child_process:698:9)
        at spawn (D:ankitnode_modulescross-spawnindex.js:12:24)
        at D:ankitnode_modulescreate-react-appcreateReactApp.js:390:19
        at new Promise (<anonymous>)
        at install (D:ankitnode_modulescreate-react-appcreateReactApp.js:341:10)
        at D:ankitnode_modulescreate-react-appcreateReactApp.js:468:16
        at processTicksAndRejections (node:internal/process/task_queues:96:5) {
      errno: -4094,
      code: 'UNKNOWN',
      syscall: 'spawn'
    }
    
    Deleting generated file... package.json
    Deleting react-app/ from D:ankit
    Done.

Website hangs in mobile but runs well in desktop

The home page of https://inscignis.in/ runs well in desktop but in mobile devices, when we scroll down to the bottom and try to scroll up, it kind of gets stuck in the motion and the experience isn’t smooth. Couldn’t figure out any possible bugs. it will be really helpful if anyone can give any general solutions to it.

Sorry couldn’t post the website code here as it is owned by my university.
Thanks in advance.

I have a JavaScript file that is full of hexadecimal numbers, want to convert it to normal js

Js file full of hexadecimal and I want to convert it to normal file. Some of the code:

a=JSON[_0x4d9f54(0xff)](localStorage[_0x4d9f54(0xee)](schol)),sid=a['sid'];for(var _0x4baca5=0x0;_0x4baca5';}_0x954758+=_0x4d9f54(0x13a),alert(_0x954758);var _0x2de5d2=document[_0x4d9f54(0x1da)]('btnx20btn-success')[0x0][_0x4d9f54(0xf1)];document[_0x4d9f54(0x1da)](_0x4d9f54(0x108))[0x0][_0x4d9f54(0xf1)]=_0x2de5d2+_0x4d9f54(0x200)+_0x2de5d2+_0x4d9f54(0x193)+_0x2de5d2+' '+_0x2de5d2;var _0x2de5d2=document[_0x4d9f54(0x1da)](_0x4d9f54(0x108));_0x2de5d2[0x0]['outerHTML']=_0x4d9f54(0x18d),_0x2de5d2[0x1][_0x4d9f54(0xf1)]=_0x4d9f54(0x16f),_0x2de5d2[0x2][_0x4d9f54(0xf1)]=_0x4d9f54(0x212),_0x2de5d2[0x3][_0x4d9f54(0x1e7)]='خروج';!localStorage[_0x4d9f54(0xee)](schol+'-total6')&&opnsms(0x1);;}function deel(){var _0x4c3c0a=_0x3dab;localStorage[_0x4c3c0a(0x1db)](schol),setTimeout(function(){pr(0x1);},0x3e8);}var txt2='',win;function pri(){var _0x2f3174=_0x3dab,_0x39cb71=_0x2f3174(0x10b),_0x244e83=document[_0x2f3174(0x1da)](_0x2f3174(0x1f4)),_0x10d002=0x0;for(var _0x1e2ffe=0x0;_0x1e2ffe<_0x244e83['length'];_0x1e2ffe++){_0x244e83[_0x1e2ffe]['checked']&&(_0x10d002=_0x10d002+0x1);}var _0x3803bc=_0x2f3174(0x17b)+_0x10d002+_0x2f3174(0x10f);win=window['open']('','js'),win[_0x2f3174(0x126)][_0x2f3174(0x13b)][_0x2f3174(0xf1)]=_0x2f3174(0x238)+Intl[_0x2f3174(0x1c1)](_0x2f3174(0xd5),{'day':'numeric','month':_0x2f3174(0x206),'weekday':'long','year':'numeric'})[_0x2f3174(0x1bb)](Date[_0x2f3174(0x204)]())+_0x2f3174(0x1a3)+_0x2f3174(0x214)+_0x3803bc+_0x39cb71+'x22x20style=x22border-radius:5px;width:250px;height:40px;background:#00423c;border:solid;border-width:1px;border-color:white;color:white;font-family:Tahoma;font-size:18pxx22x20value=x22اخترx20هناx20لمشاهدةx20التقريرx22>

x20

Javascript image onload fails on Firefox and Chrome

I am trying to load my images with a fade in effect that will be triggered once the image is loaded. I noticed that onload works properly in Chrome, but in Firefox or Safari it is called some hundred miliseconds before the image is rendered, so any animation below that duration will be skipped.

I’ have been reading other questions, as:

Didn’t find an answer in any of them.

Here I created a snippet demonstrating the problem using Picsum heavy images —3000 x 3000—. Notice that, when opening this question on Chrome and running this snippet, on load the image is faded; but when opening this same question on Firefox or Safari the image is rendered without fade in.

const imgElement = new Image();
const rootElement = document.getElementById("root");

rootElement.append(imgElement);
imgElement.className = "image";
imgElement.src = "https://picsum.photos/3000/3000";

imgElement.onload = function () {
  imgElement.classList.add("loaded");
};
.image {
  border: 2px solid gray;
  max-width: 100%;
  opacity: 0;
  transition: opacity 0.3s ease;
}

.image.loaded {
  opacity: 1;
}
<div id="root"></div>

I don’t think also that it is related to the browsers cache, as is pointed out [here][5], because we are rendering a new image every time.

Any idea will be welcome!

How can you register global components in Svelte?

Vue (at least Vue 2) allows developers to register components globally:

import MyComponent from '@/components/MyComponent'
Vue.component('my-component-name', MyComponent)

Which then results into:

  • You can write or use component libraries (like Vuetify, Quasar, Ant etc.) without needing to import their components explicitly.
  • You can easily override other global components by just calling Vue.component(…) when you want to extend or change their respective codebase without having direct access to the source code.

I read in another SO post that Svelte does not support global component registration. However, I would still like to achieve the same results as given above.

How would I approach this in Svelte?

CDN import not getting mounted on window

I’m working a SPFX module for SharePoint, and I’m having weird behaviors while trying to dynamically import a script form a CDN.

The code create an new script element and add it to the body of the page when needed. The onload method is properly called and the method onerror is not. However nothing is attached to window.

For example, I’m trying to dynamically add bootstrap to the page with the following CDN URL : https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js. The script element is properly added, onload is called, but window.bootstrap is undefined.

If I try to import a very basic script like the following :

console.log("I'm loaded");

The script element will be added and “I’m loaded” will appear in the console which mean that the loaded script is properly run.

What could cause such a behavior; where a CDN script is imported, loaded and run yet not mounted on window ?

Error on “apidoc” lib while run on Docker

I am getting error on apidoc (apidoc-0.50.3 version) while run in Docker and I am using Node v12.22.7

Command :

RUN npm install apidoc -g
RUN apidoc -e node_modules

Error :

node_modules/apidoc/lib/writer.js:136
const title = projectInfo.title ?? projectInfo.name ?? 'Loading...';
SyntaxError: Unexpected token '?'

Help me to find out a solution.

How to return the error in response from the async function?

Got stuck in a bug where the error is not returning in the response body, although that the console.log() shows the error in the terminal.

the function

    const Attributes = async () => {
      try {
        const response = await CISP.adminGetUser(IdentityParams).promise();
            UserAttributesInfoData = response
          
      } catch (err) {
        console.error(err)
      }
      return UserAttributesInfoData;
    };

await Attributes().then((data) => UserAttributesInfoData = data);

response code

      response = {
        statusCode: 200,
        body: JSON.stringify({
          message: 'IVS - CreateChannel',
          // location: ret.data.trim()
        }),
      };
  } catch (err) {
    console.log(err);
    return err;
  }
  
  return response;

The code works very well, but what I’m trying to do is to catch the errors in the response body.
So far, when I modify a parameter in purpose to see if the response catches the error, it returns empty.
How can I do it to return the error in the response?

Dexie js Changable tables

I am using Dexie.js as a wrapper for my IndexedDB local database.
I have a list of tables that i am getting from my server, each table is also contains its own schema and then i am creating the IndexedDB tables according to this info.

I am trying to achieve the following behaivior:

  1. hold DB version in configurable file
  2. first time the browser opens, get all the tables info and create them with Dexie
  3. save all the data
  4. next time the application opens – check if the version changed, if it did – fetch the tables info again and upgdrade the db, if not – just open the DB.

so 1-3 works perfectly, my problem is:
if the version DID NOT change, i dont want to fecth the data again, but Dexie wont let me access any of the stores if im not passing them before open.

is there any way to solve it without saving the entire tables schemas in localStorage ?

Getting a red squiglly line under the first cards[0], I dont know what is causing it

this is minimal js, everything else is commented. I cannot understand why “cards[i]”(first one in the for loop) has a red squiggly line under it, I cannot run any console commands. Please help!

    let cards=document.querySelectorAll(".blocks");
    let pic,card,rand;
    let finals = [];
    const count = 10; 
    const max = 9;
    
    for(let k = 0; k < 1000; k++){
      rand = Math.round(Math.random() * max);
    //   !finals.includes(rand) && finals.push(rand)
      if(!finals.includes(rand))
      finals.push(rand);
    }
    finals = finals.slice(0, count)
    setupCards(finals);
    
    function setupCards(arr){
        
        for(let i=0;i<=arr.length;i++){
    ====>cards[i].style.backgroundImage=`url(images/${arr[i]}.jpg)`;
        // cards[i].style.transform="rotateY(180deg)";
        // cards[i].style.backgroundImage="url(images/back6.jpg)";             
     }
}

How to integrate Php array to Javascript Using Ajax

I am working on ajax and php,I want to use Php array in javascript,But right not unable to integrate Php array to javascript,
Here is my Controller code where i am getting Php array as json(Using Json encode)

function GetFollowingCoinUsers()
        {
            $CoinId=$_POST['coin_id'];
            $result = $this->M_main->GetAllCoinFollower($CoinId);
            $UserId=array();
            foreach($result as $res)
            {
                $UserId[]=$res['UserId'];
            }
            echo json_encode($UserId);
        }

Above code give me result in following way

["463","500","505"]

And i am trying to use this array in Javascript/Ajax Response

$.ajax({
            type: "post",
            url:'<?php echo base_url();?>Main/GetFollowingCoinUsers',
            data: {coin_id:coin_id},
            success: function (datan) {
                    var cars = datan;
                    let text = "";
                    for (let i = 0; i < cars.length; i++) {
                      text += cars[i] + "<br>";
                    }
                    alert(text);
                    
            }
        });