How to style elements in an EJS file with a style.css

I was just experimenting here and there with ejs because I am new to it. Then I thought why not style elements with a conditional flow? Basically a particular element will look purple when the condition is true and it will look red when it is not. When I style the elements in the tag itself, it works but it doesn’t work when I link a style.css file with it.

<body>
<%if(4>3){%>
<h1 style="color: blue;">4 is more than 3</h1>
<% }else{%>
<h1 style="color: red;">Something is very wrong</h1>
<% }%>
</body>

This worked properly

but when I tried to style it in style.css, it didn’t work. Could you please tell me the reason?

EJS file:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./style.css">
    <title>To Do List</title>
</head>
<body>
    <%if(4>3){%>
    <h1 id="one">4 is more than 3</h1>
   <% }else{%>
        <h1 id="two">Something is very wrong</h1> 
 <% }%>
</body>
</html>

CSS file:

#one{
color: purple;
}
#two{
color: red;
}

The output:

get scss from design tokens json file using style dictionary

I want to get the scss rules for design tokens from a json file provided by the design team.
I used style dictionary and managed to get the base design tokens, but there are few tokens that use entire objects as value.

This is an example of design token (received from the design team) that I want to transform to scss:

{
"fontFamilies": {
    "inter": {
      "value": "Inter",
      "type": "fontFamilies"
    }
  },
 "fontWeights": {
    "inter-0": {
      "value": "Regular",
      "type": "fontWeights"
    },
  },
"fontSize": {
    "10": {
      "value": "72",
      "type": "fontSizes"
    }
  },
"Display-2xl": {
    "Regular": {
      "value": {
        "fontFamily": "{fontFamilies.inter.value}",
        "fontWeight": "{fontWeights.inter-0.value}",
        "fontSize": "$fontSize.10",
      },
      "type": "typography"
    },
}

Note: the simple tokens are successfully transformed.
Style dictionary output looks like this:

$font-families-inter: Inter;
$font-weights-inter-0: Regular;
$font-size-10: 72;
$display-2xl-regular: [object Object];

Is it possible to use style dictionary and output these rules for tokens like display-2xl-regular?

What is @JsonProperty equivalent in Node.js (or JavaScript)?

I want to rename json objects’ keys in Node.js(or JavaScript). Like how we use @JsonProperty to rename in java is there something equivalent in JavaScript to do the same?

I wrote the following code in java to change the keys’ name(from caps to camel case) of a json object.

public class Rename {
    @JsonProperty("STUDENT_ID")
    private String studentId;
    @JsonProperty("STUDENT_NAME")
    private String studentName;
}

I want to do the same in Node.js. Is there any annotation or any methods available to do it?

Javascript Object destructure given undefined

I have an object which looks like –

const test = {
  
"data": {

  "status": {
   "coed": "200",
    "desc": "aaa"
},

"data": {
  "id": "aaa",
  "date": "todays date"
}
}

}

here , I have one function

const getData = ({data: { status: { code } }}) => {
return code;
}

calling this function:

getData(test)

So test is a response data , so takes time to get that but till that time the function gets called and gives

can not read property code of undefined

How do I fix this and destructure the data ?

thanks

Close Submenu when opening another with ReactJS

Creating Submenus I find that when opening one of them all the others open and when closing it in the same way they all close.

This is my code:

const DashBoard = () => {

    const [showDropdown, setShowDropdown] = useState(false)

  return (

    <>
        <div>
            <div>
                <div>
                    <img 
                        src={ Logo }
                        alt= "LOGO"
                    />
                    </div>
                    <div>
                        <ul>
                            <li>
                                <div
                                onClick={ () => setShowDropdown(!showDropdown) }
                                >
                                    <FiHome  />
                                    Submenu 1
                                </div>

                                { showDropdown && 
                                
                                    (

                                    <div>
                                    
                                        <ul>
                                            <li>Test</li>
                                            <li >Test</li>
                                        </ul>

                                    </div>
                                    )                        
                                }
                            </li>
                        </ul>
                    </div>

                    <div>
                        <ul>
                            <li className='group'>
                                <div
                                onClick={ () => setShowDropdown(!showDropdown) }
                                >
                                    <FiHome  />
                                    Submenu 2
                                </div>

                                { showDropdown &&                                
                                    (

                                        <div>
                                        
                                            <ul>
                                                <li>Test</li>
                                                <li >Test</li>
                                            </ul>

                                        </div>
                                    )    
                                }
                            </li>
                        </ul>
                    </div>
            </div>
            <div>
                <main>Main Content</main>
            </div>
        </div>
    </>


  )
}

How could I achieve that when opening a submenu the others are closed? I have reviewed that indicating an ID per submenu is possible but I don’t know if it is the best way. Thanks.

Html video streaming size exceeds the file size , how to cache and optimise html video element with javascript

i am trying to stream video from node js server and it is working fine , but the problem is video size is 61MB , as i change my range in html video element it again fetches which goes in loop and fetch size exceeds 100 mb if continued . how not to load video anymore if the video is fully loaded and keep stream size maximum to video size

networks

How to return a promise that resolves customized data from API Javascript

So I’m using the API of National Weather Service to create a weather app. But the fetched data is very complicated, and I need to fetch two different APIs. So I want to write a customized async function that returns a promise, which resolves to an object that contains only the necessary data I need.

I came up with something like this:

async function fetchWeatherAPI(){
    //data that I need
    let data = {};
    
    try {
       const res1 = await fetch(url1);
       const result1 = await res1.json();
       data = {...data , result1.usefulData};
    } catch(error){}

    try {
       const res2 = await fetch(url2);
       const result2 = await res2.json();
       data = {...data, result2.usefulData};
    } catch(error){}

    return new Promise((resolve,reject)=>{
         resolve(data);
    })

}

This code is working for me. But the problem is, what if the APIs reject? How can I handle the error so that I can display the error message in the returned promise? I may want something like this:

return new Promise((resolve,reject)=>{
    if(...) reject(errrorMessage); 
    resolve(data);
})

Confusion regarding Spread Operator in JS

So basically I have list of objects. I am iterating and have to change one property of the object. I have two scenarios, in one I have to change the property of a particular object.

 setList(list.map((list_item)=>
      list_item.id===id?{...list_item,doubleClick:true}:list_item
    )

And there is another scenario where I have to change the property of every object in the list.

setList(list.map((list_item)=>{...list_item,doubleClick:false}))

The first case is working fine but the second case is throwing error >Parsing error: Unexpected token (34:35)

To me they don’t look that different except first one has ternary operator? Is that what’s making a difference?
How to fix the second case?

Edit: So I think spread operator works with an expression or declaration.

setList(list.map((list_item)=>list_item={...list_item,doubleClick:false}))

This works.
Is there any better or correct way to do it?

Header Component Stopped Showing When I Used useNavigate Hook

I’ve been following along this video series on creating a special type of dropdown hamburger menu. When I got to this part of the video I had to make some changes as I was using react router dom v6 and had learned the the withRouter had been deprecated.

Currently the menu is suppose to disappear once I click on the link to the new page. However after adding in the useNavigate hook my header has completely disappeared. I’m not 100% familiar yet with some of the hooks in react and have found myself stuck on getting my header to appear again and have the menu work. I have put the code I’m working with below, and really could use some guidance on how to get this to work without switching to v5 and going with the video tutorial.

App.js

import "./App.scss";
import Header from "./components/Header";
import MenuWrapper from "./components/MenuWrapper";
import { BrowserRouter as Router, Routes, Route } from "react-router-dom";

function App() {
  return (
    <Router>
      <div className="App">
        <MenuWrapper>
          <Header />
        </MenuWrapper>
        <div className="container">
          <div className="wrapper">
            <div className="home">
              <Routes>
                <Route exact path="/" element={<Home />} />
                <Route
                  exact
                  path="/opportunities"
                  element={<Opportunities />}
                />
                <Route exact path="/solutions" element={<Solutions />} />
                <Route exact path="/contact-us" element={<Contact />} />
              </Routes>
            </div>
          </div>
        </div>
      </div>
    </Router>
  );
}

function Opportunities() {
  return <p>Discover our numerous opportunities</p>;
}

function Solutions() {
  return <p>Solutions that help you.</p>;
}

function Contact() {
  return <p>Feel free to reach us.</p>;
}

function Home() {
  return (
    <div className="container">
      <div className="wrapper">
        <h5>
          The <b>HAMBRG</b>, is a creative, engineer driven, global agency
          working on advancing the software, advertising and design communities
          to new heights.
        </h5>
      </div>
    </div>
  );
}
export default App;

MenuWrapper.jsx


const withRouter = (Component) => {
  const MenuWrapper = (props) => {
    const history = useNavigate();

    return <Component history={history} {...props} />;
  };

  return MenuWrapper;
};
export default withRouter;

Header.jsx

import { Link } from "react-router-dom";
import Hamburger from "./Hamburger";

const Header = () => {
  //State for menu button
  const [state, setState] = useState({
    initial: false,
    clicked: null,
    menuName: "Menu",
  });

  //State for disabled button
  const [disabled, setDisabled] = useState(false);

  //Use effect for page changes
  useEffect((history) => {
    history.listen(() => {
      setState({ clicked: false, menuName: "Menu" });
    });
  });

  const handleMenu = () => {
    disableMenu();
    if (state.initial === false) {
      setState({
        initial: null,
        clicked: true,
        menuName: "Close",
      });
    } else if (state.clicked === true) {
      setState({
        clicked: !state.clicked,
        menuName: "Menu",
      });
    } else if (state.clicked === false) {
      setState({
        clicked: !state.clicked,
        menuName: "Close",
      });
    }
  };

  //Determine if our menu should be disabled
  const disableMenu = () => {
    setDisabled(!disabled);
    setTimeout(() => {
      setDisabled(false);
    }, 1200);
  };

  return (
    <header>
      <div className="container">
        <div className="wrapper">
          <div className="inner-header">
            <div className="logo">
              <Link to="/">HAMRG.</Link>
            </div>
            <div className="menu">
              <button disabled={disabled} onClick={handleMenu}>
                Menu
              </button>
            </div>
          </div>
        </div>
      </div>
      <Hamburger state={state} />
    </header>
  );
};

export default Header;

Hamburger.jsx

import { Link } from "react-router-dom";

const Hamburger = ({ state }) => {
  let menu = useRef(null);

  useEffect(() => {
    if (state.clicked === false) {
      // close the menu
      menu.style.display = "none";
    } else if (
      state.clicked === true ||
      (state.clicked === true && state.initial === null)
    ) {
      // open the  menu
      menu.style.display = "block";
    }
  });

  return (
    <div ref={(el) => (menu = el)} className="hamburger-menu">
      <div className="menu-secondary-background-color"></div>
      <div className="menu-layer">
        <div className="menu-city-background"></div>
        <div className="container">
          <div className="wrapper">
            <div className="menu-links">
              <nav>
                <ul>
                  <li>
                    <Link to="/opportunities">Opportunities</Link>
                  </li>
                  <li>
                    <Link to="/solutions">Solutions</Link>
                  </li>
                  <li>
                    <Link to="/contact-us">Contact Us</Link>
                  </li>
                </ul>
              </nav>
              <div className="info">
                <h3>Our Promise</h3>
                <p>
                  Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed
                  do eiusmod tempor incididunt ut labore et dolore magna aliqua.
                  Ut enim ad minim veniam, quis nostrud exercitation ullamco
                  laboris nisi ut aliquip ex ea commodo consequat. Duis aute
                  irure dolor in reprehenderit in voluptate velit esse cillum
                  dolore eu fugiat nulla pariatur. Excepteur sint occaecat
                  cupidatat non proident, sunt in culpa qui officia deserunt
                  mollit anim id est laborum.
                </p>
              </div>
              <div className="locations">
                Location:
                <span>Dallas</span>
                <span>Austin</span>
                <span>New York</span>
                <span>San Francisco</span>
                <span>Beijing</span>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  );
};

export default Hamburger;

Static Value currect but dynamic value is not currect [closed]

*hotel calculation problem.

  1. enter image description here
  2. enter image description here

Please show my image and solve my ans. 1st image is a static value this calculation is no problem but 2nd image is a dynamic value so right now button click ‘Total Value’ is wrong number.

My main problem is a js append child all value of wrong number.

Hotel result is current ans.

nodemon app crashed waiting for file changes before starting

`TypeError: JwtStrategy requires a secret or key
at new JwtStrategy (/home/ab/Desktop/express-login-register-api-master/node_modules/passport-jwt/lib/strategy.js:45:15)

at Object.<anonymous> (/home/ab/Desktop/express-login-register-api-master/src/auth/passport.js:8:3)

at Module._compile (node:internal/modules/cjs/loader:1099:14)

at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)

at Module.load (node:internal/modules/cjs/loader:975:32)

at Function.Module._load (node:internal/modules/cjs/loader:822:12)

at Module.require (node:internal/modules/cjs/loader:999:19)

at require (node:internal/modules/cjs/helpers:102:18)

at Object.<anonymous> (/home/ab/Desktop/express-login-register-api-master/src/app.js:7:1)

at Module._compile (node:internal/modules/cjs/loader:1099:14)

Node.js v17.7.2
[nodemon] app crashed – waiting for file changes before starting…

I was trying to load an external API from github and trying to run it in my code.`

Nested objects in response not logging to console

My server gets a response from another server with a document from a mongodb database with a body similar to

{
    messageDetails: {
        body: "hello"
    },
    customerDetails: {
        cstmrFirstName: 'Random',
        cstmrLastName: 'Name',
    },
}

But the response with the body is being logged to the console as:

{
  messageDetails: [Object],
  customerDetails: [Object],
}

How can I log the full object to the console with each object’s properties?

How to assign jQuery globally in a Vue Application

I have to include Jquery globally in my Vue 2 project. I know I shouldn’t, but I must because a package (MathQuill) we use needs it.

I tried the following:
I created jqueryjs.js under src -> plugins.

import Vue from 'vue';
import jQuery from 'jquery';

Vue.use(jQuery)

export default new jQuery({
});

Then I included it in main.ts

import Vue from 'vue'
import App from './App.vue'
import vuetify from './plugins/vuetify'
import jQuery from './plugins/jqueryjs'


Vue.config.productionTip = false

new Vue({
  vuetify,
  jQuery,
  render: h => h(App)
}).$mount('#app')

Here is the error message I still get in the console log:
enter image description here

What am I doing wrong? Thank you