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
| /** | |
| * getLastWord - Splits the given string in | |
| * its last word and pass the result into the callback | |
| * | |
| * @param {String} str | |
| * @param {Function} callback - Takes as arguments the first part of the text (without the last word) and the last word. | |
| */ | |
| export function getLastWord(str, callback) { | |
| if (typeof str !== 'string') str = ''; |
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
| function capitalize (str) { | |
| return str.replace(/(\w)\w+/g, (match, g1) => `${g1.toUpperCase()}${match.substring(1)}`) | |
| } |
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
| function isEqual(obj1, obj2, customizer = {}) { | |
| const keys1 = Object.keys(obj1); | |
| const keys2 = Object.keys(obj2); | |
| if (keys1.length !== keys2.length) return false; | |
| return keys1.every(key => { | |
| const item1 = obj1[key]; | |
| const item2 = obj2[key]; |
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
| /** | |
| * renderTemplate - Renders the context on the template | |
| * | |
| * @param {String} template - A string based template | |
| * @param {Object} context - Given context to replace in template | |
| * | |
| * @return {String} Template rendered | |
| */ | |
| function renderTemplate (template, context) { | |
| return template.replace(/\{(\w+)\}/g, function (match, group) { |
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
| function serializeObject(obj) { | |
| return Object.keys(obj) | |
| .map(key => `${encodeURIComponent(key)}=${encodeURIComponent(obj[key])}`) | |
| .join('&'); | |
| } |
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
| regex = { | |
| 'email': /[a-zA-Z0-9]\S+[a-zA-Z0-9]@[a-zA-Z]+\.[a-zA-Z]+(.[a-zA-Z]+)?/, | |
| 'tel': /(:?\+\d{1,2}[\-\s])?((\(\d{3}\))|(\d{3}))[\.\s\-]?\d{3}[\.\s\-]?\d{4}(:?\sx\d{1,4})?(:?x\d{1,4})?/ | |
| }; |
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
| var lockScroll = (function () { | |
| var lastScrollPosition, | |
| LOCK_SCROLL = 'lock-scroll'; | |
| return function (element, state) { | |
| if (state) { | |
| if (!lastScrollPosition) { | |
| lastScrollPosition = window.pageYOffset || document.documentElement.scrollTop; | |
| document.body.classList.add(LOCK_SCROLL); | |
| document.body.style.transform = 'translateY(-' + lastScrollPosition + 'px)'; |
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
| function getDataPromise () { | |
| var random = Math.random() * 5000 | 0; | |
| return new Promise(function (resolve, reject) { | |
| setTimeout(function () { | |
| resolve(random); | |
| }, random); | |
| }); | |
| } | |
| function runner (generator) { |
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
| /** | |
| * createTakeLastOneContext - Returns a function that uses its context | |
| * to know the last time it was called | |
| * @returns {Function} takeLastOne function. | |
| */ | |
| function createTakeLastOneContext () { | |
| var _lastOne = 0, | |
| _timeStamp = 0; | |
| return function takeLastOne (callback) { |
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
| function getQueryParams (url) { | |
| if (!url) { | |
| url = window.location.href | |
| } | |
| const match = url.match(/\?(((.+)(?=\#))|(.+))/); | |
| if (!match) { | |
| return null; | |
| } |