This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Let us assume that this is the file you are working with and you need some arithmetic functions | |
//below is the import statement | |
const math = require("math.js") | |
let num1 = 10 | |
let num2 = 20 | |
console.log(math.add(num1,num2)) //math.add is how we will be accessing the add functions from the math.js file | |
make sure that you pass two arguments, since add function requires two arguments. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const displayPrintDialogue = (generatedBlob) => { // generate blob | |
var blob = new Blob([generatedBlob], { type: "application/pdf" }); | |
var blobURL = URL.createObjectURL(blob); | |
let iframe = document.createElement("iframe"); //load content in an iframe to print later | |
document.body.appendChild(iframe); | |
iframe.style.display = "none"; | |
iframe.src = blobURL; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const fetchData = async () =>{ | |
const ids = [1,2,3,4,5] | |
let promises = await ids.map(id =>{ | |
await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`) | |
.then(res => res.data) | |
.catch(err => console.log(err) | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const axios = require('axios') | |
const fetch = async (id) =>{ | |
let data = await axios.get(`https://jsonplaceholder.typicode.com/posts/${id}`).then(res => res.data).catch(err => err.message) | |
return data | |
} | |
const main = async () =>{ | |
for(var i=1;i<10;i++){ | |
let data = await fetch(i) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const timer = ms => new Promise(res => setTimeout(res, ms)) | |
async function load () | |
{ | |
for (var i = 0; i < 100; i++) { | |
// write the logic here, make api calls or anything | |
await timer(550); // will go into the next one after 550ms | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function printDiv() { | |
var a = window.open('', '', 'height=1000, width=800'); | |
a.document.write('<html>'); | |
response.htmlContent.map(html =>{ | |
// add the html to new window | |
a.document.write(html); | |
// always start next content from new page | |
a.document.write(`<div style = "display:block; clear:both; page-break-after:always;"></div>`); | |
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
https://learn.jquery.com/events/event-delegation/ | |
(parentStaticSelector).on(event, dynamicChildSelector, function(){}) |
Some introduction text, formatted in heading 2 style
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function parseUnixTimeStamp(unix_timestamp){ | |
var date = new Date(unix_timestamp); | |
// var hours = date.getHours(); | |
// var minutes = "0" + date.getMinutes(); | |
let parsedDate = date.toLocaleString([], {year: 'numeric', month: 'numeric', day: 'numeric',hour: '2-digit', minute:'2-digit'}) | |
// or | |
parsedDate = date.toLocaleString([], {year: 'numeric', month: 'short', day: 'short',hour: '2-digit', minute:'2-digit'}) | |
// or | |
parsedDate = date.toLocaleString([], {year: 'numeric', month: 'long', day: 'long',hour: '2-digit', minute:'2-digit'}) |
OlderNewer