Toggling inline css statements in javascript [duplicate]

Forgive for a moment that there are vastly better ways to handle a simple toggle like this and pretend that we have to do it by declaring inline styles.

What’s wrong with my logic such that I can’t call toggleSidebar(); every time a button a clicked and always produce the opposite result of what is currently true? (This only works the first time you click the button right now).

function toggleSidebar() {
    var sidebar = document.getElementById('sidebar');
    var show = Boolean;
    
    if (show == null) {
        show = true;
    }

    if (show) { 
        sidebar.style.right = '0px';
        show = !show;
    } else {    
        sidebar.style.right = '-400px';
        show = !show;
    }
}

fire async function and wait later for result [duplicate]

I have the following scenario:

async function asyncfunc1()
{
      var request = new XMLHttpRequest();
      request.open('GET', requestURL, false);
      request.responseType = 'json';
      request.send();
      return request.response;
}

var res_1 = asyncfunc1(); /* i dont to wait here, just let it work in the background */
res_2 = do some stuff....
res_3 = do more stuff
total_res= res_1 + res_2 + res_3; /* how to wait for res_1 here */

Automate string input to a input

I know this question has been asked a hundred times.
But once again, the solutions no longer work.

I need to simulate key presses to automate a form.

If I do it like this

document.getElementById("input_id").value = "testinput"

the events from the input do not trigger.
And my value is just deleted again.

is there again a possibility to simulate keystrokes so that also all events are triggered?

How do I color separate words that are in quotation marks

I am making a shop, and I made a “Colors available” part, but I want to be able to color separate words with different colors, in Javascript, css, or HTML, or however it is possible

<button onclick="getColors()">Colors Available</button>
<script>

    function getColors(){
        if(!document.getElementById('colors_ava')){
            let colors_ava = document.createElement('div');
            colors_ava.id = 'colors_ava';
            document.body.appendChild(colors_ava);
            colors_ava.innerText = "Rich Navy  -  True Red  -  Dark Geen  -  Olive Drab Green  -  Patriot Blue";
        }
    }
</script>

Vue js Module not found: Error: Can’t resolve ‘fs’ and Can’t resolve ‘child_process’

This problem has bothered me a lot and I haven’t found a solution yet
I installed vue-webartc for video calls and want to use it in the vue app but this problem appeared
I tried with the solutions on the internet but to no avail
How do I put fs and child process to flase into a vue js project?
i get these problem in the image of the screenshot enter image description here
i added this to my package.json file but still have the same problem

"browser": {
     "fs": false,
     "child_process": false
   }

and i also tried this in my webpack.config.js

export const node = {
   child_process: "empty",
   fs: "empty"
};
export const resolve = {
 extensions: [".ts", ".js"],
 fallback: {
    "fs": false,
    "child_process": false,
},

};

should i modify this vue.config.js also?

const { defineConfig } = require('@vue/cli-service')
const NodePolyfillPlugin = require("node-polyfill-webpack-plugin")

module.exports = defineConfig({
  transpileDependencies: true,
  configureWebpack: {
    plugins: [
      new NodePolyfillPlugin(),
    ],
  },
})

i will really appreciate your help

React Native Uri is not Displaying

I have a TouchableOpacity set up as shown below:

<View style={{flexDirection: 'row'}}>
   <TouchableOpacity onPress={() => selectImage()} style={{backgroundColor: COLORS.lightGray3, width: SIZES.width, height: 200, borderTopRightRadius: 15, borderTopLeftRadius: 15,}}>

       <TouchableOpacity onPress={() => setModal(!modal)} style={{backgroundColor: 'white', width: 20, height: 20, borderRadius: 15, alignSelf:'flex-end', right: 10, top: 10}}>
           <Icon name='x' size={20} style={{color: 'red'}}/>
       </TouchableOpacity>

       {array.picture == null ? 
       <View style={{alignItems: 'center', flexDirection: 'column', top: 50}}>
          <Text>No Image Selected. </Text>
       </View>
       :
       <Image resizeMode='cover' source={{uri: array.picture}} /> 
       }

   </TouchableOpacity>
</View>

In this TouchableOpacity is a conditional to load an image uri from an array once the image has been selected via selectImage(); even if array.picture IS NOT equal to null, it will either display the same “No Image Selected” text, or a gray background.

ARRAY:

[{"name": "test", "picture": "file:///Users/user/Library/Developer/CoreSimulator/Devices/C10A4A25-D633-44E8-AE53-AD8DD9601A82/data/Containers/Data/Application/C68582F5-CA35-4DD6-9D15-36A254411CD9/tmp/3E9EBBE3-AC1A-4C61-927E-DD168BD037A5.jpg", "price": 12}]

PICTURE OF DISPLAY:enter image description here

ALSO, this is all displayed within a modal.

Anyone sure as to why this is occurring? Thanks!

Upload webp an sending to server express and nodejs

I am developing a web application in node js with express, among its many functions I need to implement a small form to add products, with fields such as name, price, stock. just as I require an input in a form that allows me to upload a photo per product and when I receive it, I transform it into a webp type and after that I send it to the server where it can be stored with a unique code, I already have the entire form but I’m not sure how to send the change the photo in a format (so they can upload any compatible format and on the server it will still be saved as webp type), I tried implementing multer, but I didn’t find any concise way to do it, is there any middleware ? or any concise and not too complicated way to do it? I also attach the dependencies that I have at the moment

const express = require('express');
const morgan = require('morgan');
const path = require('path');
const { engine } = require('express-handlebars');
const favicon = require('serve-favicon');
const session = require('express-session');
const MySQLStorage = require('express-mysql-session');
const flash = require('connect-flash');
const passport = require('passport');

Express Session working in dev but not in production in incognito

Express Session working in dev but not in production in incognito

const session = expressSession({
  name: "session",
    secret: process.env.sessions_key,
    resave: false,
    store: store,
  proxy: true,
    saveUninitialized: process.env.ENV==='dev'?false:true,
    cookie: {
        maxAge : 1000 * 60 * 60 * 48,
        sameSite: 'strict',
    httpOnly: true, 
        secure: process.env.ENV==='dev'?false:true
    }
});
app.enable('trust proxy');

Suggestions of about books, video tutorials, and so on [closed]

I am a newbie programmer and new here in the StackOverflow forum. I have been working as a programmer in a company for two years. I am not graduated from any TI course. I am curious and enthusiastic about technology and programming. I still have to learn much about programming logic. Many times I got stuck thinking and trying to write a code, and sometimes I get messed up with my own code while I am typing. I confuse myself with many thoughts about how I can solve one specific problem in the most simple way possible.

So, I would like suggestions from you about books, video tutorials, and so on to help me to thrive on my programmer skills.

Thanks in advance,

Jordan

OpenLayers 6, Iterate through all features of a layer?

In OpenLayers 6…

I’m not familiar with the thing, but…
How can I iterate through all features on my layer with the title “firmenGeoJSON” and hide or show some of them with specific property “name”?

Thank you…

let myLayers = map.getAllLayers();

myLayers.forEach(function(layer) {
    if (layer.getProperties()['title'] == 'firmenGeoJSON') {
        console.log('found and hide');
        //??????????
    };
});

Using _.throttle on a function that needs to take different input values

I am coding in Node.js and would like to use lodash’s throttle method on an array of axios requests.
I have a process, being run in an AWS lambda function, that receives as input an array of parameters. Each of these parameters is used to configure an axios request to an external API and do something with the data in the response. Thus, for example, if we get 1000 parameters in this array, 1000 calls will need to be made to this external API.

In my example, makeCallToApi is an imported class defined elsewhere, containing a static async function execute(param) which constructs a request config for axios using the input param (used in constructing the url) and then tries to return the response of await axios(config).

await Promise.all(
  arrayOfParams.map(async (param) => {
    const data = await makeCallToApi.execute(param);
    await myMongooseModel.create(formatData(data));
  })
);

The external API is rate-limited, so I want to throttle these requests to avoid hitting their limit. How would I use _.throttle to do this?
I have the following example below, which I know is wrong and would like to understand how to rewrite correctly:

// in the file where makeCallToApi is defined:
const throttledCallToApi = _.throttle(axios); 

export class makeCallToApi {
   static async execute(param) {
      const config = ... // construct the request config; url = `${baseUrl}/example-api/${param}`
      try {
       const response = await throttledAxios(config);
       return response?.data;
       } catch (err) {
          // error-handling stuff
      }
  }
}

// then, in my main code...

await Promise.all(
  arrayOfParams.map(async (param) => {
    const data = throttledCallToApi(param);
    await myMongooseModel.create(formatData(data));
  })
);

The problem with this is that although I am looping over the entries in arrayOfParams, throttledCallToApi() keeps being called with the value of the first param in the arrayOfParams.
What am I doing incorrectly in the usage of _.throttle()?

Svelte: Web worker in without SvelteKit

I am struggling to find information how to incorporate a web worker in a Svelte app that is not using SvelteKit (I have found numerous examples how do it with SvelteKit though). Basically I would believe I have two choices here:

  1. Add them directly to the source code (app.svelte), hence the compiler will pick it up and bundle it (at least I would assume he does so). I haven’t found any code sample for that one.
  2. Link the web worker javascript file in my index.html and place it manually in the public folder.

I would assume 1. is more elegant and the way to go, but I haven’t found any clear best practices/guidelines how to implement it.

So what is the best choice and is there anywhere an example that I might be able to reuse?