Adds month to date javascript with format

so i have a response from frontend as below:

const response = { Lakban: “Merah”, Plant: “K103”, Kategori: “M2”, Jumlah: 103 }

and i have lookup Value from MongoDB with example result as below:

const monthReturnDB = “November”

const shelfLifeDB = 6

and i have function below to get month number:

const getMonth=(monthStr)=>{

return new Date(monthStr+'-1-01').getMonth()+1

}

so what i try to explain is i try to get the format of date based on the monthReturnDB and the “Kategori” type with function below:

let value;

if(response.Kategori ===”M1″){

value = “1” + “/” getMonth(monthReturnDB)+Dates.getFullYear()

}else{

value = “1” + “/” getMonth(monthReturnDB)+(Dates.getFullYear()-1)

}

i expected it to sum the value from the months and year with the shelfLifeDB number, with function below:

let end = new Date(valueDB);

end.setMonth(end.getMonth() + 11);

let curr = new Date()

console.log(curr)

console.log(end.toLocaleString(‘en-US’),valueDB)

but its not returning the expected result as i want:

the expected result i want is as pic below:
enter image description here

Any explanation where i did wrong here?

cannot read properties of undefined (reading indexof)

We have a script for the game “FiveM” (GTA V ROLEPLAY). In one script we get a error: cannot read properties of undefined (reading indexof)

function rightCloth() {
  let type = $(".btnChangeCloth").attr("data-currentAction");
  let val = clotheValues[charSex][type].indexOf(selectedValues[type]);
  selectedValues[type] = clotheValues[charSex][type][val + 1];
  if (typeof selectedValues[type] == "undefined") {
    selectedValues[type] = clotheValues[charSex][type][0];
  }

let val = clotheValues[charSex][type].indexOf(selectedValues[type]);

thats the line of the error code. Whats wrong?

not experienced for that

Ethers.js is not returning the full object struct from mapping

I have this struct

struct User { Counters.Counter total; mapping(uint => address) payment_splitters; }

And this mapping

mapping(uint => address) payment_splitters;

As far as I understand, this is the correct way to get a user from payment_splitters mapping.

const user = await myContract.payment_splitters_registry(userAddress);

The problem is that I am just getting one element from the struct, which is total.

What do you think I’m missing from ethersjs? Why I only get one element from my struct?

Why do I keep getting false for some() javascript array method for an array inside an object? [duplicate]

  const menu = [{
       name: "tofu fritters",
       ingredients: ["tofu", "egg yolk", "breadbrumbs", "paprika"],
     },
     {
       name: "black bean curry",
       ingredients: ["black beans", "garam masala", "rice"],
     },
     {
       name: "chocolate tiffin",
       ingredients: [
         "dark chocolate",
         "egg",
         "flour",
         "brown sugar",
         "vanilla essence",
       ],
     },
     {
       name: "hummus",
       ingredients: ["chickpeas", "tahini", "lemon", "garlic", "salt"],
     },
   ];

searchResult = menu.some(menuItem => menuItem.ingredients === 'flour');
console.log(searchResult);

I was expecting this to return true since flour is present in the array for the third menu item but it returns false. Some() only seems to return true if I remove the array entirely from the object.

Unable to resolve path to module (import/no-unresolved) in eslint

I’m having mix codebase of Typescript and Javascript with monorepo configuration with Lerna in create-react-app. I’m importing TS files in my JS files with tsconfig.json setup, but getting an error with eslint.

Currently, my .eslintrc.json looks like this, I’ve newly added the settings here, but it didn’t seem to work

{
  "env": {
    "browser": true,
    "es2021": true,
    "jest": true
  },
  "extends": [
    "plugin:react/recommended",
    "airbnb",
    "prettier",
    "plugin:prettier/recommended",
    "plugin:import/typescript"
  ],
  "parserOptions": {
    "ecmaFeatures": {
      "jsx": true
    },
    "ecmaVersion": 12,
    "sourceType": "module"
  },
  "plugins": ["react", "prettier"],
  "rules": {
    "react/react-in-jsx-scope": "off",
    "react/jsx-filename-extension": [
      1,
      { "extensions": [".js", ".jsx", ".ts", ".tsx"] }
    ],
    "prettier/prettier": "error",
    "jsx-a11y/click-events-have-key-events": "off",
    "import/no-extraneous-dependencies": ["error", { "devDependencies": true }],
    "react/function-component-definition": [
      2,
      {
        "unnamedComponents": "arrow-function"
      }
    ],
    "import/no-relative-packages": "off"
  },
  "ignorePatterns": ["config-overrides.js", "*.json", "*.md", "*.css"],
  "settings": {
    "import/resolver": {
      "typescript": true,
      "node": true
    },
    "import/parsers": {
      "@typescript-eslint/parser": [".ts", ".tsx"]
    }
  }
}

Simple If statement not returning bool (onload function)

when the uploaded image satisfies the if statement it gives the alert but it doesnot return the false .

var _URL = window.URL || window.webkitURL;
var img = new Image();
img.onload = function() {
var width = this.width, height = this.height;

if (width > 200 && height > 100)
{
   alert("Incorrect Dimension");
   return false;
}
};
img.src = _URL.createObjectURL(file);

Remove item from shopping cart react js

I working on adding/removing items to a shopping cart in my react js project, after I add items to the cart I add “-” and “+” buttons that on click should decrease/increase item quantity. I’ve managed to make the add to cart, increase work but I can’t figure out how to delete the item from the cart when quantity becomes 0. This is my code so far:

const [items, setItems] = useState([]);

const handleDecrease = (id) => {
    setItems((prevState) =>
      prevState.map(
        (item) =>
          item.id === id
            ? item.qty !== 1
              ? { ...item, qty: item.qty - 1 }
              : item.id !== id
            : item // !id
      )
    );
  };

{items?.map((item) => {
            return (
              <div
                key={item.id}
              >
                <div onClick={() => handleDecrease(item.id)}>-</div>
                <div>{item.title}</div>
                <div> ${item.price * item.qty}</div>
                <div>{item.qty}</div>
              
              </div>
            );
          })}

in my handleDecrease function I check if the item quantity is !==1 then I decrease the quantity by 1, if the quantity is 1 and “-” is clicked again, I want to remove the item completely from the items array, but my code only adds false to the items array. How can I remove the item?

React Native Retrieve Actual Image Sizes for React Native 0.7 / 0.71

I would like to be able to know the actual size of a network-loaded image that has been passed into I have tried using onLayout to work out the size (as taken from here https://github.com/facebook/react-native/issues/858) but that seems to return the sanitised size after it’s already been pushed through the layout engine.

I tried looking into onLoadStart, onLoad, onLoadEnd, onProgress to see if there was any other information available but cannot seem to get any of these to fire. I have declared them as follows:

Why is typescript map set function not working [duplicate]

I have written a simple code push key value pair in a map. but console log shows empty map everytime. Can someone help whats wrong

let mp: Map<string, number[]> = new Map<string, number[]>();
console.log('first = ' + JSON.stringify(mp));
mp.set('1', []);
console.log('second = ' + JSON.stringify(mp));
const g:number[] = mp.get('1') || [];
g.push(3);
mp.set('1', g);
console.log('third = ' + JSON.stringify(mp));

Output

"first = {}" 
"second = {}" 
"third = {}" 

I am not able to figure out why there is no entry in the map.

Adding props condition in Styled component error Expression produces a union type that is too complex to represent

I’m trying to make a condition using the component’s disabled prop. However, I’m getting this error Adding props condition in Styled component error Expression produces a union type that is too complex to represent. The code below works on other component, except for this on. Can you please help me understand what the error means or what’s the fix of it? TIA!

ListGroupItem is a react-bootstrap component.

My typescript version is 4.4.4

export const StyledListGroupItem = styled(ListGroupItem)`
  ${({ disabled }) => (disabled && `
    color: red;
  `)};
` as any;

error while making the git link to the local

$ npm i
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path E:hr74Hr-Portal-Team-74/package.json
npm ERR! errno -4058
npm ERR! enoent ENOENT: no such file or directory, open ‘E:hr74Hr-Portal-Team-74package.json’
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR! C:UsersRamyaAppDataLocalnpm-cache_logs2023-01-24T04_43_05_564Z-debug-0.log

Ramya@DESKTOP-1O1S1H1 MINGW64 /e/hr74/Hr-Portal-Team-74 (master)

i tried to run the code but iam getting this erorr

failed to upload image in nestjs

        hi i am newbie in backend especially nodejs , i am using nestjs as framework. i want to make the name of my uploaded file "https://mydomain/files/example-image.png" , but i get an error like this
    
        Error: ENOENT: no such file or directory, open 'C:*********nestjs-learningfileshttp:localhost:3001files9795f8f8147410d8fa07a4de5a92e0678.png'
        
        and here is my code to name the file
        
        FileInterceptor('image', {
          storage: diskStorage({
            destination: './files',
            filename: (req, file, cb) => {
              const randomName = Array(32)
                .fill(null)
                .map(() => Math.round(Math.random() * 16).toString(16))
                .join('');
              return cb(null, `http://localhost:3001/files/${randomName}${extname(file.originalname)}`);
            },
          }),
        }),
       
    

is this way wrong? , is there a specific way to name the file?
someone please help me solve this

How does the value of a property change depending on whether I am viewing the whole object in the console vs that property on its own?

I am trying to do this:

albumList.map(
    (album) => {
        return (
            {album.averagescore}
        )
    }
)

But I am not seeing anything for album.averagescore.

I can console.log(album) like this:

albumList.map(
    (album) => {
        console.log(album)
        return (
            {album.averagescore}
        )
    }
)

and I can see the property averagescore with its values in all the objects in the array.
However, when I console.log(album.averagescore):

albumList.map(
    (album) => {
        console.log(album.averagescore)
        return (
            {album.averagescore}
        )
    }
)

it logs “undefined” for all items.

I am struggling to understand how the value of this property changes depending on whether I am viewing the whole object vs that property on its own. I can access all the other values from the object just fine (ex. album.artist, album.title, etc.), and I can see the value clearly within the object. I would appreciate any suggestions!

Here is how I am getting this data:

  const personid = 3;
  
  const [albumList, setalbumList] = useState("");
  
  const getAlbums = () => {
    Axios.get(apiBasePath + '/getalbums/' + personid)
      .then(
        res1 => {
          for (let i = 0; i < res1.data.length; i++) {
            Axios.get(apiBasePath + '/getaveragescore/' + res1.data[i].albumid)
              .then(
                res2 => {
                  res1.data[i].averagescore = res2.data[0].avg
                }
              )
          }
          setalbumList(res1.data)
        }
      );
  }

  useEffect(
    () => getAlbums(),
    []
  )

xa0 /   is being read out by screen reader

I have a unique problem.. I’m wondering if there is a work around

I have a situation where I need to insert a non width space / breaking space / space into my document

currently I am using const SPACE = xa0;

Now for my use case this is working, however using safari & VoiceOver the special character is being read outloud as space

Is there a way to hide this from the screen reader?

Unfortunately I’m not in a position where I am able to add an element around the space character like

<span aria-hidden="true">&nbsp;</span>

Is there any other way to prevent the screen reader from reading “space” outloud?