Skip to content

Instantly share code, notes, and snippets.

View gauravmuk's full-sized avatar
🦁
Learning

Gaurav Nanda gauravmuk

🦁
Learning
View GitHub Profile
@gauravmuk
gauravmuk / deps-promise.js
Created July 7, 2019 18:04
Get Dependencies Recursive
const fetch = require('node-fetch');
function getDependencies(packageName) {
const url = `https://registry.npmjs.org/${packageName}/latest`;
return fetch(url).then((response) => {
return response.json();
}).catch(() => {
return [];
}).then((body) => {
return Array.from(Object.keys(body.dependencies));
@gauravmuk
gauravmuk / deps-await-part1.js
Created July 7, 2019 18:07
Get dependencies using await
const fetch = require('node-fetch');
async function getDependencies(packageName) {
const url = `https://registry.npmjs.org/${packageName}/latest`;
try {
const response = await fetch(url);
const body = await response.json();
return Array.from(Object.keys(body.dependencies));
} catch (err) {
return [];
@gauravmuk
gauravmuk / deps-await-part2.js
Created July 7, 2019 18:14
Async await nested deps
const fetch = require('node-fetch');
async function getDependencies(packageName) {
const url = `https://registry.npmjs.org/${packageName}/latest`;
try {
const response = await fetch(url);
const body = await response.json();
return Array.from(Object.keys(body.dependencies));
} catch (err) {
return [];
@gauravmuk
gauravmuk / deps-async-await.js
Created July 7, 2019 18:29
Question Fun Level - 10
const fetch = require('node-fetch');
async function getDependencies(packageName) {
const url = `https://registry.npmjs.org/${packageName}/latest`;
try {
const response = await fetch(url);
const body = await response.json();
return Object.keys(body.dependencies);
} catch (err) {
return [];
@gauravmuk
gauravmuk / engage-opt-in-trigger.html
Created June 14, 2020 13:49
This snippet is an example showing how to bind click event listener to trigger VWO Engage Optin.
<button onclick="_pcq.push(['triggerOptIn']);">
GET NOTIFICATIONS
</button>
@gauravmuk
gauravmuk / pushcrew-sw.uninstall.js
Created September 17, 2020 03:03
Remove Service Worker
navigator.serviceWorker
.getRegistrations()
.then(function (registrations) {
for (let registration of registrations) {
registration.unregister();
}
})
.catch(function (err) {
console.log("Service Worker registration failed: ", err);
});