Skip to content

Instantly share code, notes, and snippets.

View rake7h's full-sized avatar
😀

Rakesh rake7h

😀
View GitHub Profile
cacheGroups: {
reactVendor: {
test: /[\\/]node_modules[\\/](react|react-dom|react-router|react-loadable)[\\/]/,
name: 'reactvendor',
},
reactRedux: {
test: /[\\/]node_modules[\\/](redux|react-redux|axios)[\\/]/,
name: 'reactRedux',
},
utilityVendor: {
@rake7h
rake7h / clear-cache.js
Created April 8, 2021 18:42 — forked from deanhume/clear-cache.js
Clear Service Worker Cache
if ('serviceWorker' in navigator) {
caches.keys().then(function(cacheNames) {
cacheNames.forEach(function(cacheName) {
caches.delete(cacheName);
});
});
}
@rake7h
rake7h / ServingES6.md
Created May 23, 2021 14:51 — forked from newyankeecodeshop/ServingES6.md
Serving ES6 to modern browsers

Background

Recently I noticed that Safari 10 for Mac/iOS had achieved 100% support for ES6. With that in mind, I began to look at the browser landscape and see how thorough the support in the other browsers. Also, how does that compare to Babel and its core-js runtime. According to an ES6 compatability table, Chrome, Firefox, and IE Edge have all surpassed what the Babel transpiler can generate in conjunction with runtime polyfills. The Babel/core-js combination achieves 71% support for ES6, which is quite a bit lower than the latest browsers provide.

It made me ask the question, "Do we need to run the babel es2015 preset anymore?", at least if our target audience is using Chrome, Firefox, or Safari.

It's clear that, for now, we can't create a site or application that only serves ES6. That will exclude users of Internet Explorer and various older browsers running on older iOS and Android devices. For example, Safari on iOS 9 has pretty mediocre ES6 support.

@rake7h
rake7h / safari-nomodule.js
Created September 17, 2021 16:50 — forked from samthor/safari-nomodule.js
Safari 10.1 `nomodule` support
/*
* Copyright 2017 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
@rake7h
rake7h / vanilla-js-cheatsheet.md
Created October 21, 2021 12:14 — forked from thegitfather/vanilla-js-cheatsheet.md
Vanilla JavaScript Quick Reference / Cheatsheet
@rake7h
rake7h / Native.js
Created October 21, 2021 12:17 — forked from alexreardon/Native.js
Some vanilla JS methods and patterns
// Native selectors.
(function(window, document) {
'use strict';
var noop = function() {
};
// DOCUMENT LOAD EVENTS
// not needed at the bottom of the page
document.addEventListener('DOMContentLoaded', noop);
const stream = require('stream')
const cache = new Map() // you might wanna use an lru here
function createCacheStream (url) {
const buf = []
return stream.Transform({
transform: function (data, enc, cb) {
buffer.push(data)
cb(null, data)
},
@rake7h
rake7h / date-utils.js
Last active February 4, 2023 17:49
date-utils.js
// date to epoc
const epoc = new Date("2016/3/17").valueOf()
// epoc to data
const formatter = new Intl.DateTimeFormat("en-GB");
console.log(formatter.format(epoc));
@rake7h
rake7h / async-await-forEach-alternatives.md
Created February 28, 2023 05:17 — forked from joeytwiddle/async-await-forEach-alternatives.md
Do not use forEach with async-await

Do not use forEach with async-await

TLDR: Use for...of instead of forEach in asynchronous code.

The problem

Array.prototype.forEach is not designed for asynchronous code. (It was not suitable for promises, and it is not suitable for async-await.)

For example, the following forEach loop might not do what it appears to do:

#!/usr/bin/env node
require('esbuild-register/dist/node').register();
require('./cli.ts');