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 stripHTMLTags = str => str.replace(/<[^>]*>/g, ''); | |
stripHTMLTags('<a href="#">Me & you</a>'); |
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 unescapeHTML = str => | |
str.replace( | |
/&|<|>|'|"/g, | |
tag => | |
({ | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
''': "'", | |
'"': '"' |
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 escapeHTML = str => | |
str.replace( | |
/[&<>'"]/g, | |
tag => | |
({ | |
'&': '&', | |
'<': '<', | |
'>': '>', | |
"'": ''', | |
'"': '"' |
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 digitize = n => [...`${n}`].map(i => parseInt(i)); | |
digitize(691710147); // [6,9,1,7,1,0,1,4,7] |
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 capitalize = ([first, ...rest], lowerRest = false) => | |
first.toUpperCase() + (lowerRest ? rest.join('').toLowerCase() : rest.join('')); | |
capitalize('JavaScript'); // 'JavaScript ' | |
capitalize('JavaScript', true); // 'Javascript's |
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 detectDeviceType = () => | |
/Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent) | |
? 'mobile' | |
: 'desktop'; | |
detectDeviceType(); // "mobile" or "desktop" |
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 UUIDGenerator = () => | |
([1e7] + -1e3 + -4e3 + -8e3 + -1e11).replace(/[018]/g, c => | |
(c ^ (crypto.getRandomValues(new Uint8Array(1))[0] & (15 >> (c / 4)))).toString(16) | |
); | |
UUIDGenerator(); // 82f13078-8479-4060-87ea-1e919e71edfe |
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 formToObject = form => | |
Array.from(new FormData(form)).reduce( | |
(acc, [key, value]) => ({ | |
...acc, | |
[key]: value | |
}), | |
{} | |
); | |
formToObject(document.querySelector('form'); |
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 serializeForm = form => | |
Array.from(new FormData(form), field => field.map(encodeURIComponent).join('=')).join('&'); | |
serializeForm(document.querySelector('form') | |
// full-name=Adrian%20Legaspi&email=adrian.luball%40gmail.com&nickname=ImLuyou |
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
let method = (/* True or false */ ? 'start' : 'stop'); | |
array[method](); |