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
| //this is the functional version of the same code allowing you work with several inputs | |
| var onlyNumbers = function(){ | |
| 'use strict'; | |
| var coma = true, | |
| that = this; | |
| this.addEventListener('keyup', function(e){ | |
| var key = e.keyCode, | |
| value = that.value; | |
| if(key == 8 && value.search(/,/) === -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
| for (var i = 0; i < 1024 * 1024; i++) { | |
| process.nextTick(function () { Math.sqrt(i) } ) | |
| } |
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 browserify = require('browserify'); | |
| const gulp = require('gulp'); | |
| const rename = require('gulp-rename'); | |
| const runSequence = require('run-sequence'); | |
| const source = require('vinyl-source-stream'); | |
| const buffer = require('vinyl-buffer'); | |
| const uglify = require('gulp-uglify'); | |
| const sourcemaps = require('gulp-sourcemaps'); | |
| const gutil = require('gulp-util'); | |
| const del = require('del'); |
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; | |
| } |
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 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
| 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
| 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
| 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
| /** | |
| * 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) { |
OlderNewer