Skip to content

Commit

Permalink
Updated functions for ES6 consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
workeffortwaste committed Nov 10, 2020
1 parent e978d56 commit ca927ff
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 7 deletions.
15 changes: 15 additions & 0 deletions .eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
module.exports = {
"env": {
"browser": true,
"commonjs": true,
"es2021": true
},
"extends": [
"standard"
],
"parserOptions": {
"ecmaVersion": 12
},
"rules": {
}
};
8 changes: 4 additions & 4 deletions layout-shift-gif.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ const Good3G = {
const phone = devices['Nexus 5X']

/* Detect layout shift */
function clsDetection () {
const clsDetection = () => {
window.cumulativeLayoutShiftScore = 0
window.previousRect = []
window.currentRect = []
Expand All @@ -64,7 +64,7 @@ function clsDetection () {
}

// Return the colours we're using for the CLS
function getColor (cls) {
const getColor = (cls) => {
let c = { stroke: 'rgba(0,128,0,.7)', fill: 'rgba(0,128,0,.1)', solid: 'rgb(0,128,0,1)' }
if (cls >= 0.1) {
c = { stroke: 'rgba(255,125,0,.5)', fill: 'rgba(255,125,0,.05)', solid: 'rgba(255,125,0,1)' }
Expand All @@ -75,7 +75,7 @@ function getColor (cls) {
return c
}

async function createGif (url, device) {
const createGif = async (url, device) => {
// Launch puppeteer
const browser = await puppeteer.launch({ args: ['--no-sandbox'], timeout: 10000 })

Expand Down Expand Up @@ -152,7 +152,7 @@ async function createGif (url, device) {
const ctx = canvas.getContext('2d')

// Canvas setup function
const canvasSetup = function () {
const canvasSetup = () => {
// Add the screenshot to each frame
ctx.drawImage(image, 0, 0, image.width, image.height)
// Add the CLS score in the top left corner
Expand Down
13 changes: 10 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"name": "layout-shift-gif",
"version": "1.1.1",
"version": "1.1.2",
"description": "Generates a .gif showing the layout shift events for a website.",
"main": "./layout-shift-gif.js",
"keywords":[
"keywords": [
"layout shift",
"cls",
"gif",
Expand All @@ -28,5 +28,12 @@
"bugs": {
"url": "https://github.com/workeffortwaste/layout-shift-gif/issues"
},
"homepage": "https://defaced.dev/tools/layout-shift-gif-generator/"
"homepage": "https://defaced.dev/tools/layout-shift-gif-generator/",
"devDependencies": {
"eslint": "^7.13.0",
"eslint-config-standard": "^16.0.1",
"eslint-plugin-import": "^2.22.1",
"eslint-plugin-node": "^11.1.0",
"eslint-plugin-promise": "^4.2.1"
}
}

0 comments on commit ca927ff

Please sign in to comment.