How to get value from async function in javascript [duplicate]

I am trying to get response status from an async function after fetching from a url, but I can’t. The responseStatus always 0 in the console log

    let responseStatus = 0;
    const makeRequest = async () => {
      const response = await fetch(url);
      responseStatus = response.status;
      // console.log(response);
    }

    makeRequest();
    console.log("responseStatus: " + responseStatus)

Expected result:
responseStatus: 200

Actual result:
responseStatus: 0

how to give yeoman all argument at one go?

i wanted to give all argument of yeoman at one go in CI, i am using this yoeman

https://github.com/microsoft/generator-azuresfguest

something like this :

yeoman cmd : yo azuresfguest --serviceName "x".......

https://github.com/yeoman/yo/issues/480?

idea is, i will run the yeoman in CI/CD tool where user wont write anything or input anything in cmd – it’s just hardcoded values as argument.

argument details as per this document :

https://github.com/microsoft/generator-azuresfguest/blob/master/generators/guestbinary/index.js

How to use URL redirect in Google Chrome Extension in Manfest V3

I am new to developing Google Chrome Extensions. After extensive research, I cannot find really any useful Tips. Basically, what I want is after successfully logging in; the user is presented with a popup box (at this moment, options.html); where a user can check a checkbox (which if checked), does this change on this file. I do not have the function for the checkbox yet but I am needing to do the redirect first I think to make sure my extension would work for what I need it for but..

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" href="./CSS/selection.css">
<style>
        body, html {
          padding: 0;
          margin: 0;
        }
        .container {
            box-shadow: inset 0px 0px 8px 8px #181818;
            width: 400px;
            height: 300px;
            background: url("./Images/ShadowGhosts.png");
            background-repeat: no-repeat;
            background-size: auto;
            background-size: 400px 300px;
            display: flex;
            align-items: left;
            justify-content: left;
            flex-direction: column;
            font-family: 'Source Sans Pro';
            user-select: none;
            color: goldenrod;
        }

        .black-input {
            color: red
        }
</style>
</head>
<body>
    <div class="container">
<fieldset>
    <legend>Select Which one you Want:</legend>

    <div>
      <input type="checkbox" class="black-input" id="scales" name="scales">
             <!-- checked> -->
      <label for="scales">Ears</label>
    </div>

    <div>
      <input type="checkbox" id="horns" name="horns">
      <label for="horns">Horns</label>
    </div>
</fieldset>
</div>
</body>

and this is my manifest file:

{
    "name": "Shadow Ghosts",
    "description": "Some Cool Description",
    "version": "1.1",
    "manifest_version": 3,
    "background": {
        "service_worker": "./JS/background.js"
    },
    "action": {
        "default_popup": "popup.html",
        "default_icon": {
            "16": "./Images/SG.png",
            "32": "./Images/SG.png",
            "48": "./Images/SG.png",
            "128": "./Images/SG.png"
        }
    },
    "icons": {
            "16": "./Images/SG.png",
            "32": "./Images/SG.png",
            "48": "./Images/SG.png",
            "128": "./Images/SG.png"

    },

    "content_scripts": [{
            "all_frames": true,
            "matches": ["<all_urls>"],
            "js": ["JS/content-script.js"]
        },
        {
            "run_at": "document_start",
            "matches": ["*://localhost/tulc/public/exemple/wc*"],
            "js": ["JS/cookie-fix.js"]
        }
    ],

    "permissions": ["storage", "activeTab", "scripting", "webRequest", "declarativeNetRequest"]
}

And lastly, this is my background script:

let color = "#3AA757";

chrome.runtime.onInstalled.addListener(() => {
    chrome.storage.sync.set({ color });
    console.log('Default background color set to ,color');
});


// chrome.webRequest.onSendHeaders.addListener(function (e){
//  chrome.tabs.query({
//      active:true,
//      currentWindow:true
//  },
//  function (tabs){

//  });},
//  {
//  urls:["<all_urls>"],
//  types: ["xmlhttprequest"]
// },["requestHeaders"]);

In my background script, I used an older example to try to create my own code but it did not work as I had to comment it out. Can someone please point me in the right direction on:

1.) How to do a URL Redirect (From: Yahoo.com To: Google.com)
2.) How to add data to each checkbox if checked
and Lastly:
3.) How to use the data from the checkbox to modify data on the redirected page?

Displaying warning message if user is not on chrome

I am currently building a website, and I do not have the skills to make the website work on all on all browsers. So I have written a quick bit of JavaScript to detect the browser. I do not know JavaScript very well so the code does not work.

Here is the code


if(userAgent.not(/chrome/i)){
    alert("Warning.n " +
        "You are not on a recomended browser, n ciertain features might not work " +
        "try using chrome");
}

can you please just make the warning only appear if you are not using chrome.

thank you very much

Identify money sending transaction and contract creation transaction

I’m using web3 version ^1.0.0-beta.46.

below is an example transaction of Ethereum block

accessList: []
blockHash: "0x0b82cf9ba5232f3e6432f99bed4e850f984d9b05ee64c8b4d42a826a1e68588e"
blockNumber: 14839057
chainId: "0x1"
from: "0xeB2629a2734e272Bcc07BDA959863f316F4bD4Cf"
gas: 21000
gasPrice: "21325281910"
hash: "0xc6d172d47a2dc6bc407b35d871b63dbf34a5a10c1a23f393543da20936519c9f"
input: "0x"
maxFeePerGas: "47000000000"
maxPriorityFeePerGas: "2000000000"
nonce: 5775540
r: "0xb7dd45d91b2585b8c4fe31ef722f97e477446d6dd412963782209f76608c89a"
s: "0x6bd92fd926f7e2d2626bdda85c99aa4bdb8ece805fc31b6008a734c05319d78e"
to: "0x55E19b1Eb57bfd3118cA4A986992526aA8d70887"
transactionIndex: 104
type: 2
v: "0x0"
value: "40535780000000000"

Can we identify eth transaction here?

Note: to value is always present in each transaction of this block

css count-increment on every page-break

i have created a header and footer that will only show when the user exports the page, I am trying to add a custom pagination when printing but it does not seem to increment and is stuck with “Page 1”, is there a way for the CSS to detect page break? i have a page-break-after: always in one of the components since it usually has more than 1 page when exported. or is it because my footer is in a separate div from the components?

here is my partial code
my css:

body {
  counter-reset: page 1;
}

@media print {
  .pagebreak-after {
    padding-top: 1rem;
    page-break-after: always;
  }
  .print_footer {
    visibility: visible;
    position: fixed;
    display: flex;
    bottom: 2%;
    padding: 1rem;
    width: 100%;
    border-top: 1px solid black;
  }
  .counter::after {
    counter-increment: page;
    content: " | Page " counter(page);
  }
  .adjust_on_print {
    margin-top: 3rem !important;
  }
  .no-print {
    display: none;
    visibility: hidden;
  }
  .print_header {
    visibility: visible;
    position: fixed;
    top: 2%;
    width: 100%;
    border-bottom: 1px solid gray;
  }
}

my code:

<div class="content">
  <div class="row d-flex no-print">
    <div v-if="false" class="col d-flex align-items-center">
      <a class="nav-link" :href="json_data" :download="file_name">
        <button
          class="btn btn-sm btn-outline-secondary d-flex align-items-center"
        >
          <i class="mdi mdi-printer mr-1" /><small>Export</small>
        </button>
      </a>
    </div>
    <div class="col d-flex align-items-center">
      <button
        class="btn btn-sm btn-outline-secondary ml-auto d-flex align-items-center"
        @click.prevent="print_full"
      >
        <i class="mdi mdi-printer mr-1" /><small>{{btn_labels.print}}</small>
      </button>
    </div>
  </div>
  <ErmittlungDerHochstgrenzen ref="ermit" />
  <WeitereBerechnungsgrundlagen class="my-3 pagebreak-after" ref="weitere" />
  <ErmittlungAnerkannterHilfebedarf
    class="adjust_on_print"
    ref="ermit_annerkanter"
  />
</div>
<div :class="{'no-print':this.print}">
  <div class="print_header">
    <p>{{claim_info.Insurance_number}}</p>
    <p>{{claim_info.First_name}} {{claim_info.Last_name}}</p>
  </div>
  <div class="print_footer">
    <span class="mr-auto">Footer here</span>
    <span class="mx-auto"
      >{{claim_info.First_name}} {{claim_info.Last_name}}</span
    >
    <span class="ml-auto counter">{{claim_info.Date | moment('L')}}</span>
  </div>
</div>

Trying to pass value/variable/params to url and new window

I’m trying to pass some values to a new window URL:

   function sendInfo() {
        
    
        var params = new URLSearchParams();
         params.append("ozip", publicOzip);
         params.append("dzip", publicDzip);
         params.append("ocity",ocitystatetext);
         params.append("dcity", dcitystatetext);
        
        var url = "/critracker.html?" + params.toString();
        location.href = "/critracker.html?";
        
    }

however i am getting a “Uncaught SyntaxError: Unexpected token ‘var’ ” on the second window which contains the code:

    function get () 
    { 
      var params = new URLSearchParams(window.location.search), 
      var   ozip = params.get("ozip"); 
      var   dzip = params.get("dzip");
      var   ocity = params.get("ocity");
      var   dcity = params.get("dcity"); 
}

The new window does not open with the variables as parameters , does anyone have any tips for sending variables and their values to a new window?

Nesting multiple [Op.not] queries in a single where clause

I’ve got a filter that allows users to indicate themes and genres they would like removed from the search results. This is an OR, not AND situation, so if either a theme or a genre is matched, it should be removed from the pool.

If I run the query below with a single [Op.not] clause, the themes and genres filter correctly. When I attempt to combine them as show in the example, only the genres [Op.not] executes. I assume I’ve chained them incorrectly in the where clause?

Code Example

    //Variables to store filters from JSON body
    let sortBy = [req.body.galleryFilters.sortBy, 'ASC']
    let hiddenThemes = [];
    let hiddenGenres = [];

    //Parse the body for activeFilters create and array of Active Filters 
    req.body.galleryFilters.themes.forEach(theme => {
      if(theme.hidden === true) {
        hiddenThemes.push(theme.name)
      }
    })

    req.body.galleryFilters.genres.forEach(genre => {
      if(genre.hidden === true) {
        hiddenGenres.push(genre.name)
      }
    })

    //use variables above to create new playlist obje
    const playlists = await db.playlists.findAll({
      where: {
        [Op.not]: {
          themes: {
            [Op.overlap]: hiddenThemes
          },
        },
        [Op.not]: {
          genres: {
            [Op.overlap]: hiddenGenres
          },
        },
      },
      order: [[req.body.galleryFilters.sortBy, 'ASC']]
    });
  
    return res.send(playlists);
  
  }
});

JavaScript – Applying CSS file to a page only if certain conditions are met

So… I am in the process of making a Chrome Browser extension as a practice assignment.

Right now, I have made a manifest.json file that contains a part like the following:

"content_scripts": [
    {
        "matches": ["<all_urls>"],
        "js": ["content.js"]
    }

]

The intention here is that for all sites opened via the Chrome browser, the content.js will be at work.

Before getting into what I intend to have the content.js as, I have made an index.html (image of it by clicking the 1 here)1

Also, I have made main.css and looks like the following:

html body {
filter: grayscale(70);}

Basically, index.html will be what the “New Tab” will look like. So, on that page, for example, if a user checkmarks “YouTube”, I want the content.js to have something like:
“If the YouTube checkmark is checked AND the website domain matches www.youtube.com, then apply main.css to that website’s page”

Jest error in mockImplementation: Type ‘string[]’ is not assignable to type ‘Cat[]’

I’m trying to write a unit test for my API using Jest and I’m using some boilerplate code but it’s leading me to an error that I don’t understand. Here is the test:

describe('findAll', () => {
it('should return an array of cats', async () => {
  const result = ['test'];
  jest.spyOn(catsService, 'findAll').mockImplementation(() => result);

  expect(await catsController.findAll()).toBe(result);
  });
});

The error is in the part () => result:

Type ‘string[]’ is not assignable to type ‘Cat[]’

My findAll method within catsController is very straightforward, it just return an array of Cat objects:

findAll(): Cat[] {
return this.catsService.findAll();
}

What is incorrect about my mockImplementation?

Detecting String in Specific Format

I was wondering if there was anyway to create a function that ‘detects’/finds a string in a specific format.

For example, when the function is run, anything following the format of “#text,” where ‘text’ could be anything, is found and identified. This means thing like “#hash” and “#tag”.

I have done research but failed to find anything useful.