This file contains 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
class Avenger { | |
constructor(name) { | |
this.name = name; | |
} | |
} | |
const hero = new Avenger("Steve Rogers"); | |
hero.name; /*?*/ |
This file contains 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
// Destructuring | |
const args = [1, 2, 3, 4]; | |
const [a, b, c, d] = args; | |
console.log(a, b, c, d); | |
const coords = { x: 1, y: 10 }; | |
const { x: horizontal, y } = coords; | |
horizontal; /*?*/ | |
y; /*?*/ |
This file contains 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
// Uppercase first letter of a string | |
function ucFirst(string) { | |
return string.charAt(0).toUppercase() + string.slice(1); | |
} |
This file contains 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
// Get URL params | |
const getParameters = () => | |
window.location.search | |
.slice(1) | |
.url.split('&') | |
.reduce(function _reduce(/*Object*/ obj, /*String*/ str) { | |
str = str.split('='); | |
obj[str[0]] = decodeURIComponent(str[1]); | |
return obj; | |
}, {}); |
This file contains 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
// CSV to JSON | |
const CSVToJSON = (data, delimiter = ',') => { | |
const titles = data.slice(0, data.indexOf('\n')).split(delimiter); | |
return data | |
.slice(data.indexOf('\n') + 1) | |
.split('\n') | |
.map(v => { | |
const values = v.split(delimiter); | |
return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {}); | |
}); |
This file contains 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
// Redirect to... | |
const redirect = (url, replace = false) => { | |
if (asLink) { | |
window.location.href = url; | |
} else { | |
window.location.replace(url); | |
} | |
}; | |
redirect('https://overment.com'); |
This file contains 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
// Named parameters | |
// Instead this: | |
articles(ids, published, orderBy, order) | |
articles([1, 4, 6], true, 'created_at', 'DESC') | |
// Do this: | |
articles({ ids, published, orderBy, order }) | |
articles({ ids: [1, 4,6 ], published: true, orderBy: 'created_at', order: 'ASC'}) |
This file contains 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
// Rename object keys | |
const renameKeys = (keysMap, obj) => | |
Object.keys(obj).reduce( | |
(acc, key) => ({ | |
...acc, | |
...{ [keysMap[key] || key]: obj[key] }, | |
}), | |
{} | |
); |
This file contains 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
// Rename object keys | |
const renameKeys = (keysMap, obj) => | |
Object.keys(obj).reduce( | |
(acc, key) => ({ | |
...acc, | |
...{ [keysMap[key] || key]: obj[key] }, | |
}), | |
{} | |
); |
This file contains 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
// Array to CSV data | |
const csvContent = result.map(e => e.join(",")).join("\n"); | |
copy(csvContent) |
OlderNewer