I have tried to update node.js using NVM -V.
Still Couldn’t able to update?
Kindly help me out with this.
Blancer.com Tutorials and projects
Freelance Projects, Design and Programming Tutorials
Category Added in a WPeMatico Campaign
I have tried to update node.js using NVM -V.
Still Couldn’t able to update?
Kindly help me out with this.
Within this program, I’m trying to map a function across an Array of objects in order to render rows with information from this Array of users. When doing so, TypeScript is giving me a variety of issues when trying to access this information. I can’t see what it is I’m missing that would allow me to access the properties.
The interfaces for my objects:
type TableData = Array<Row>;
interface Row {
id: string,
twilio_sid: string,
user_sid: string,
name: string,
activity_sid: string,
activity_name: string,
activity_last_updated: string,
role_id?: string,
queues?: string,
channels: [],
role?: string
}
Attempted map thus far:
{(rowsPerPage > 0
? Object.entries(rows).slice(page * rowsPerPage, page * rowsPerPage + rowsPerPage)
: rows
).map((user) => (
<TableRow key={user.id}>
<TableCell component="th" scope="row">
{user.name}
</TableCell>
<TableCell style={{ width: 160 }} align="left">
{user.role}
</TableCell>
<TableCell style={{ width: 160 }} align="left">
{user.activity_name}
</TableCell>
<TableCell style={{ width: 160 }} align="right">
Edit
</TableCell>
</TableRow>
))}
I previously was not using the Object.entries(obj) implementation but this still threw an error stating that slice was not a function on this type Row.
Does an implementation exist where I can still use slice in this regard?
Alright, I need some assistance from the js experts out there. Here’s my problem:
I receive an object from a CMS which contains two strings inside:
{pageContent.title}
Inside the object I get:
"title":{
"_type":"localeString"
"en":"Privacy Policy"
"es":"Política de Privacidad"
}
Each string represents a locale, and the page needs to render the correct one depending on the current locale. For that I’m using a simple router hook:
const router = useRouter()
const locale = router.locale
So now locale returns either en or es
To render the object on the page I’d do:
{pageContent.title.es} for spanish and {pageContent.title.en} for English, and so on.
However, I need the .es and .en part to be dynamic, and pick up that value from locale since now there are only two languages, but more will be added in the future.
I found a very hacky solution that works but I’d prefer something more elegant.
First, I join both, but using the object partial name as a string. Then I remove the ” (unstringing it)
let localeTitle = 'pageContent.title.' + locale
localeTitle = localeTitle.replace(/"/g, '')
Then on the page, I eval() that new string:
{eval(localeTitle)}
Now, I know this isn’t the correct or best way of doing this.
And, before you ask why I’m not getting the corresponding language directly on the query, I tried. I’m using getStaticProps to fetch the data, which doesn’t allow hooks to be used so I can’t access the locale from the router.
Any ideas?
I am trying to output the time of the video duration as it progresses using the ontimeupdate event handler on the video but it doesn’t work.
I added a console.log in the code as well to test but it doesn’t work.
This is the html code
<video id="poster" class="w-100 h-100 image-align" autoplay muted loop src="<?= word("URL_VIDEO") ?>" loading="lazy"></video>
<span id="poster-duration" class="ms-4 text-white">00:00</span>
Here is my script
window.addEventListener('load', function() {
var poster = document.getElementById('poster');
poster.ontimeupdate = function(){
document.getElementById('poster-duration').innerText = addO(Math.floor(poster.duration/60)) + ':' + addO(Math.round(poster.duration%60));
console.log("hello")
};
function addO(n){
if( n.toString().length < 2 ){
return '0'+n;
}
return n;
}
// ...
})();
I’m not sure how to extract content when there are multiple optional children with the same name.
user_defined_text_field below.Hopefully the example below provides the relevant context.
FORM OF DATA
(From an API from a service)
<api>
<response>
<service>api_search</service>
<individuals count="1">
<individual id="1">
<first_name>James</first_name>
<last_name>Jones</last_name>
<email>[email protected]</email>
<gender>M</gender>
<user_defined_text_fields>
<user_defined_text_field>
<name>udf_text_1</name>
<label>Fav Color</label>
<text>Blue</text> // ****** I WANT THIS ******
<admin_only>false</admin_only>
</user_defined_text_field>
<user_defined_text_field>
<name>udf_text_3</name>
<label>Area</label>
<text>Urban</text>
<admin_only>false</admin_only>
</user_defined_text_field>
</user_defined_text_fields>
</individual>
</individuals>
</response>
CURRENT PORTION OF CODE TO EXTRACT RELEVANT DATA
(Inside Google Script. Everything is working perfect — I only need help with the line I have commented below.)
// ...
const entries = fetch.getRootElement().getChild('response').getChild('individuals').getChildren();
const list = new Array();
for (let i in entries) {
const first_name = entries[i].getChildText('first_name');
const last_name = entries[i].getChildText('last_name');
const email = entries[i].getChildText('email');
const gender = entries[i].getChildText('gender');
const fav_color = ??? // ****** NEED HELP HERE ******
list.push([first_name, last_name, email, gender]);
};
// ...
If I want to get a value from the object know but the case is different, it won’t match: "Hello" won’t match "hello". Is there another work around for this?
function ct(e) {
var know = {
"Hi": "Hello",
"How are you?": "Great",
"Bye": "Have A Nice Day !",
"Hello": "Hi , Whats Up",
"What's your name?": "Claire Rachael"
};
let t = document.createElement("span");
t.setAttribute("class", "chatMessage left");
if (e in know) {
setTimeout(() => {
t.textContent = "Typing...";
d.appendChild(t);
g = d.getAttribute("data-bottom")
? d.getAttribute("data-bottom")
: 0;
if (parseInt(g) < 200)
d.scrollTo(0, d.scrollHeight);
}, 2000);
setTimeout(() => {
t.textContent = know[e];
d.appendChild(t);
g = d.getAttribute("data-bottom")
? d.getAttribute("data-bottom")
: 0;
if (parseInt(g) < 200)
d.scrollTo(0, d.scrollHeight);
else
alert("new message");
}, 6000)
}
else {
t.textContent = "I don't understand";
d.appendChild(t);
}
}
I am using Webpack 5 for my React App.
We want to enforce a strict Content Security Policy.
And we need to add the SHA256 hash of the Javascript and the CSS to our HTML page for the Content Security Policy.
So far, I have not been able to figure out a way to generate SHA256 hash using webpack.
I want to highlight the current section and current page in the bootstrap navbar using Javascript can anyone help, also i have 2 Dropdown menus one has sections on the homepage and the other dropdown links to sub-pages so I want to highlight the dropdown menu title also have tried myself but nothing is working for me
my code for navbar is
<nav id="navbarMain" class=" navbar navbar-expand-lg navbar-light bg-light col px-md-3 px-sm-1 ">
<div class="container-fluid px-md-5 px-sm-0 mainlogo ">
<a class="navbar-brand " href=""> <img class="img-fluid " src="" alt="" style="max-width:300px;"> </a>
<button class="navbar-toggler navbar-dark" type="button" data-bs-toggle="collapse" data-bs-target="#navbarSupportedContent" aria-controls="navbarSupportedContent" aria-expanded="false" aria-label="Toggle navigation">
<span class="navbar-toggler-icon "></span>
</button>
<div class="collapse navbar-collapse" id="navbarSupportedContent">
<ul class="navbar-nav justify-content-end ">
<li class="nav-item">
<a class="nav-link active" aria-current="page" href="#dashboard">Dashboard</a>
</li>
<li class="nav-item my-auto px-xl-3 px-ld-1 ">
<a class="nav-link active hometag" aria-current="page" href="/#hero">Home</a>
</li>
<li id="warumdrop" class="nav-item px-xl-3 px-lg-1 my-auto dropdown">
<a class="nav-link dropdown-toggle " href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Homepages section
</a>
<ul class="dropdown-menu " aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="/#warum">warum</a></li>
<li><a class="dropdown-item" href="/#whyus">why us</a></li>
<li><a class="dropdown-item" href="/#feedback">feedback</a></li>
</ul>
</li>
<li class="nav-item px-xl-3 px-lg-1 my-auto dropdown ">
<a class="nav-link dropdown-toggle " href="#" id="navbarDropdown" role="button" data-bs-toggle="dropdown" aria-expanded="false">
Subpages links
</a>
<ul class="dropdown-menu " aria-labelledby="navbarDropdown">
<li><a class="dropdown-item" href="<?php echo base_url(); ?>requirements/glassAndBuildingCleaningPage">glassAndBuildingCleaningPage</a></li>
<li><a class="dropdown-item" href="<?php echo base_url(); ?>requirements/janitorialPage">janitorialPage</a></li>
<li><a class="dropdown-item" href="<?php echo base_url(); ?>requirements/chemicalCleaningPage">Cleaning</a></li>
<li><a class="dropdown-item" href="<?php echo base_url(); ?>requirements/theCurtainPage">curtain</a></li>
</ul>
</li>
</li>
<li class="nav-item px-xl-3 px-lg-1 my-auto ">
<a href="<?php echo base_url(); ?>requirements/contactPage" class="nav-link ">contact</a>
</li>
<li class="nav-item px-xl-3 px-lg-1 my-auto ">
<a style="color:#D70143;" href="<?php echo base_url(); ?>requirements/vacanciesPage" class="nav-link joblink">Jobpage</a>
</li>
<li class="nav-item">
<a style="color:#D70143;" href="'. base_url() .'requirements/logout" class="nav-link ">Logout</a>
</li>
<li class="nav-item ">
<a href="#" data-bs-toggle="modal" data-bs-target="#loginmodal" style="color:#032A66; font-size:25px; width:auto;" class=" loginatag nav-link "><i class="bi bi-box-arrow-in-right"></i></a>
</li>
</ul>
</div>
</div>
</nav>
I use mac os and when i click on the button to download pdf , It doesn’t do anything ? What do you think is the issue?
i have a chrome extension code that will give info about cpu usage of all chrome process (Fired each time the Task Manager updates its process statistics, providing the dictionary of updated Process objects, indexed by process ID.) when im on an active tab
the code
chrome.tabs.onActivated.addListener((tabs) => {
let tabId = tabs.tabId;
chrome.tabs.get(tabId, (tab) => {
console.log(tab.url);
});
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
if(changeInfo.status == "complete"){
console.log(tab.url);
}
});
chrome.processes.onUpdated.addListener((x) => {
console.log(x)
});
});
the problem is i want to get only specific process where its cpu usage is above 500 and get the osProcessId for further action. i tried to do validation by using for loop but it return nothing. in other word, maybe my question is how to do validation on function that always do update everytime
specific process that have cpu load above 500

validation i tried to add to chrome.processes.onUpdated.addListener
chrome.processes.onUpdated.addListener((x) => {
for(var i=0;i<x;i++){
if(x[i].cpu >= 500){
console.log(x[i].osProcessId)
}
}
});
I have problem with Material Menus. When I open menu and from there click on my Dialog the menu stay on the background without closing it. When I set onClick={handleClose} on my MenuItem it closing the menu, but also close the Dialog
const RowMenu = ({ dataParams, refetch }) => {
const [anchorEl, setAnchorEl] = useState(null);
const open = Boolean(anchorEl);
const handleClick = (event) => {
setAnchorEl(event.currentTarget);
};
const handleClose = () => {
setAnchorEl(null);
};
return (
<>
<IconButton
aria-label="more"
id="long-button"
aria-controls={open ? 'long-menu' : undefined}
aria-expanded={open ? 'true' : undefined}
aria-haspopup="true"
onClick={handleClick}
>
<MoreVertIcon />
</IconButton>
<Menu
id="long-menu"
MenuListProps={{
'aria-labelledby': 'long-button'
}}
open={open}
anchorEl={anchorEl}
onClose={handleClose}
PaperProps={{
style: {
maxHeight: 48 * 4.5,
width: '20ch'
}
}}
>
<MenuItem sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<EditParams dataParams={dataParams} refetch={refetch} />
</MenuItem>
<MenuItem sx={{ display: 'flex', alignItems: 'center', justifyContent: 'center' }}>
<Typography>Изтриване</Typography>
</MenuItem>
</Menu>
</>
);
}
I have a function which goes off to retrieve an image from Firebase Storage:
import {
getStorage,
ref,
getDownloadURL
} from 'firebase/storage';
const storage = getStorage();
export async function getImage(location) {
const ImageURL = await getDownloadURL(ref(storage, location));
return await ImageURL;
}
This is then called within a React component:
import { getImage } from 'API/Storage/getImage';
const EventPage = (props) => {
return (
<div>
<img src={getImage('image.jpg')}
</div>
);
}
export default EventPage;
However the image doesn’t display and instead shows: <img src="[object Promise]" alt="Show Image">
What’s the best way of resolving the promise? Console logging ImageURL within the getImage function returns the URL as expected.
My response object containing startTime, I want to compare all the startTimes and get the latest time to display on timeline.
How can I find the latest Date and time using moment.js
Response I am getting –
[{
name:"abc",
type:"CALL",
startTime:"2021-10-13T07:16:55Z",
},{
name:"def",
type:"CALL",
startTime:"2021-10-13T07:18:57Z",
},{
name:"ghi",
type:"CALL",
startTime:"2021-10-15T07:17:05Z",
},{
name:"jkl",
type:"CALL",
startTime:"2021-11-03T12:07:52Z",
}]
My code –
response.forEach((d)=>{
if(d.type == 'CALL'){
console.log("latest start time ",d);
$scope.view(d); //need to pass the obj of latest startTime only
$scope.$apply();
}else{
//Something else
}
})
How can I do this using JavaScript or moment?
Let arr = [ “Ahmed”, 4, ” mia”, “jhon”, 6 ,7,” Chris” ]
For ( i = 0; I ${arr{i}}`) } // output
0 => ahmed 2 => mia 3 => jhon 6 => chris
// how i want it to look
0 => ahmed 1 => mia 2 => jhon 3 => Chris
I have following code.
const documents = [
{
id: 309,
name: "sample.pdf",
hash: "ce01b860a0b92750d922e900a5a8800c",
ext: ".pdf",
mime: "application/pdf",
url:
"https://realestream.nyc3.digitaloceanspaces.com/ce01b860a0b92750d922e900a5a8800c.pdf",
},
{
id: 165,
name: "mortgage_financing.png",
hash: "fe4b75488e35c6f84baf428f7043522e",
ext: ".png",
mime: "image/png",
url:
"https://realestream.nyc3.digitaloceanspaces.com/fe4b75488e35c6f84baf428f7043522e.png",
},
{
id: 310,
name: "wordFile.docx",
hash: "5c8034f2ed8f8bebbb3cfdceadab8123",
ext: ".docx",
mime:
"application/vnd.openxmlformats-officedocument.wordprocessingml.document",
url:
"https://realestream.nyc3.digitaloceanspaces.com/5c8034f2ed8f8bebbb3cfdceadab8123.docx",
}
];
return (
<div className="App">
{documents.map((o) => (
<div>
<a href={o.url} target="_blank" rel="noreferrer">
{o.name}
</a>
<img src={`./assets/${o.ext.substring(1)}.png`} alt="file" />
</div>
))}
</div>
);
I am trying to show for each format relevant image, but it’s not working, please help me to fix this broken image error. I try even like this src=require(./assets/${o.ext.substring(1)}.png).default} , but it’s not helped.
Thanks.