Just wanted to try out some of the new features after I had read a post ES8 was Released and here are its Main New Features 🔥
Here I will post examples using some ES8 features
| Object.prototype.toTimeString = function() { | |
| var t = parseFloat(this); | |
| var hou = (parseInt(t / 3600) % 24).toString().padStart(2, "0"), | |
| min = (parseInt(t / 60) % 60).toString().padStart(2, "0"), | |
| sec = parseInt(t % 60) | |
| .toString() | |
| .padStart(2, "0"); | |
| return `${hou}:${min}:${sec}`; | |
| }; |
| var source = document.documentElement.innerHTML; | |
| var original = source.length | |
| var saved = (original-(source.replace(/<!--.*?-->/g,'').replace(/\n/g,'').length)); | |
| console.log("This page could be reduced by "+saved+" bytes, which is around "+Math.round(saved/original*100)+"%") |
| const RawHTML = ({children, className = ""}) => | |
| <div className={className} dangerouslySetInnerHTML={{ __html: children.replace(/\n/g, '<br />')}} /> |
| class CopyToClipboard extends React.Component { | |
| copy() { | |
| const textarea = this.textarea; | |
| let { text, onCopy, silent } = this.props; | |
| silent = | |
| typeof silent === "boolean" || | |
| silent.toLowerCase() == "true" || | |
| silent == "1"; | |
| textarea.value = onCopy.call(this, text); | |
| textarea.select(); |
| var sel = "div > div > div > div.clearfix > div._gll > a"; | |
| var count = "div._glm > div"; | |
| var desc = "div._glo > div"; | |
| var groups = Array.from(document.querySelectorAll(sel)); | |
| var foundInfo = {}; | |
| var json = ""; | |
| groups.map(ele => { | |
| var members = ele.parentNode.parentNode.parentNode | |
| .querySelector(count) | |
| .innerText.split(" ")[0]; |
| //Rextester.Program.Main is the entry point for your code. Don't change it. | |
| //Compiler version 4.0.30319.17929 for Microsoft (R) .NET Framework 4.5 | |
| using System; | |
| using System.Net.Http; | |
| namespace Rextester | |
| { | |
| public class Program |
Just wanted to try out some of the new features after I had read a post ES8 was Released and here are its Main New Features 🔥
Here I will post examples using some ES8 features
| var image = Array.from(document.querySelectorAll('img')); | |
| image.map((ele,i) => { | |
| var {width, height} = getComputedStyle(ele); | |
| var newSrc = `http://dummyimage.com/${parseInt(width)}x${parseInt(height)}`; | |
| if ('src' in ele) { | |
| ele.setAttribute('src', newSrc) | |
| } else { | |
| var url = ele.style.backgroundImage; | |
| console.log(url) | |
| if (url) { |
| var path = document.querySelector("path"); | |
| function getPathCommands(pathElement) { | |
| var data = pathElement.getAttribute("d"); | |
| var ofs = 0; | |
| var indexes = data.match(/[hvmlcqtsaz]/gi).map(function(cmd, i) { | |
| ofs += data.substr(ofs).indexOf(cmd) + 1; | |
| return ofs - 1; | |
| }); | |
| var commands = []; | |
| indexes.map(function(curr, i) { |
| var lorem = 'Lorem ipsum dolor sit amet, consectetur adipisicing elit. Quod neque eaque fuga culpa doloribus adipisci vel explicabo! Nihil ipsa commodi quae voluptates laudantium fugit nam. Itaque veniam iure aliquid harum!' | |
| Array.from(document.querySelectorAll("a,h1,h2,h3,h4,h5,h6")).map((ele, i) => { | |
| var img = ele.querySelector('img'); | |
| var span = ele.querySelector('span'); | |
| if (img) { | |
| var info = getComputedStyle(img); | |
| img.src = 'http://dummyimage.com/'+parseInt(info.width)+'x'+parseInt(info.height) | |
| } else { | |
| if (span) { | |
| span.innerText = lorem.substr(0, span.innerText.length) |