This file contains hidden or 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 weekDays = { | |
| monday: "Monday", | |
| tuesday: "Tuesday", | |
| wednesday: "Wednesday", | |
| thursday: "Thursday", | |
| friday: "Friday" | |
| }; | |
| const mappedWeekDays = Object.keys(weekDays).reduce((mapper, day) => { | |
| mapper[day] = { |
This file contains hidden or 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 p1 = new Promise(resolve => resolve({ data: 1, status: 'OK' })); | |
| const p2 = new Promise((resolve, reject) => reject({ data: 2, status: 'OK' })); | |
| const p3 = new Promise(resolve => resolve({ data: 3, status: 'OK' })); | |
| const promisesCatcher = promises => promises.map(promise => promise.catch(err => ({ data: err, status: 'ERROR' }))); | |
| Promise.all( | |
| promisesCatcher([p1, p2, p3]) | |
| ).then(values => { | |
| for (let result of values) { |
This file contains hidden or 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 fs = require('fs'); | |
| const rawBase64 = ''; // typically 'data:image/png;base64,.......' | |
| const [, ext, data] = rawBase64.match(/^data:image\/([a-z]+);base64,(.*)$/); | |
| fs.writeFileSync(`image.${ext}`, data, 'base64'); |
This file contains hidden or 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 REGEX = /https:\/\/.*\.googleusercontent\.com\/.*#(https?:\/\/.*)/i; | |
| // Rewrite img source on <img> tags | |
| Array.from( | |
| document.querySelectorAll('img') | |
| ).forEach(img => { | |
| const match = img.src.match(REGEX); | |
| if (!match) { | |
| return; |
This file contains hidden or 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
| // Originally tweeted at https://twitter.com/ClementParis016/status/1065000952749539329 | |
| // Fetch raw binary PDF data | |
| const response = await fetch('https://some.pdf'); | |
| // Extract response body as Blob | |
| const blob = await response.blob(); | |
| // Create an URL pointing to the object | |
| const url = URL.createObjectURL(blob); | |
| // Render a PDF viewer! |
This file contains hidden or 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
| // It may have a lot of possible use case but the one I did it for initially was | |
| // to find which keys were missing between two JSON translations files | |
| function getKeys(obj) { | |
| const keys = []; | |
| const walk = (o, parent = null) => { | |
| for (const k in o) { | |
| const current = parent ? parent + '.' + k : k; | |
| keys.push(current); |
This file contains hidden or 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
| import { map, iteratee } from 'lodash'; | |
| /** | |
| * Replaces elements from collection that matches predicate with replacement. | |
| * | |
| * @param {Array} collection The collection to replace in | |
| * @param {*} predicate The condition to determine which elements of collection | |
| * should be replaced | |
| * @param {*} replacement The value to use as a replacement of elements of | |
| * collection that matches the predicate |
This file contains hidden or 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 { Octokit } = require("@octokit/rest"); | |
| const fastCsv = require("fast-csv"); | |
| const fs = require("fs"); | |
| const consola = require("consola"); | |
| process.on("unhandledRejection", (error, promise) => { | |
| consola.fatal(`Unhandled rejection! ${error.name}: ${error.message}`, { | |
| error, | |
| promise, | |
| }); |
OlderNewer