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 throttle ( fn, threshhold, scope ) { | |
| threshhold || (threshhold = 250); | |
| var last, | |
| deferTimer; | |
| return function () { | |
| var context = scope || this; | |
| var now = +new Date, | |
| args = arguments; |
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
| if( !Object.assign ) { | |
| Object.assign = function( obj, items ) { | |
| var src = Object( items), target = Object( obj ) | |
| Object.getOwnPropertyNames( src ).forEach( function( k ) { | |
| target[ k ] = src[ k ] | |
| }) | |
| return target; | |
| } | |
| } |
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
| /* | |
| * memoize.js | |
| * by @philogb and @addyosmani | |
| * with further optimizations by @mathias | |
| * and @DmitryBaranovsk | |
| * perf tests: http://bit.ly/q3zpG3 | |
| * Released under an MIT license. | |
| */ | |
| function memoize( fn ) { | |
| return function () { |
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 isScrolledIntoView (el) { | |
| var elemTop = el.getBoundingClientRect().top; | |
| var elemBottom = el.getBoundingClientRect().bottom; | |
| var isVisible = (elemTop >= 0) && (elemBottom <= window.innerHeight); | |
| return isVisible; | |
| } |
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 contains = (key, list) => { | |
| return list.indexOf(key) > -1; | |
| } | |
| const diff = (first, second) => { | |
| let firstKeys = Object.keys(first); | |
| let secondKeys = Object.keys(second); | |
| let addition = secondKeys.filter(key => !contains(key, firstKeys)) | |
| let deletion = firstKeys.filter(key => !contains(key, secondKeys)) | |
| return {addition, deletion} |
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 assignPrototypeMethods = ( constructorMethod, context ) => { | |
| // Loop over the BaseController's prototype methods and assign them to the current context | |
| for ( var methodName in constructorMethod.prototype ) { | |
| if (constructorMethod.prototype.hasOwnProperty( methodName ) && !context[ methodName ]) { | |
| // Copy the method into the current controller context. | |
| context[ methodName ] = constructorMethod.prototype[ methodName ]; | |
| } | |
| } | |
| } |
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
| range (num) { | |
| return [...Array(num).keys()] | |
| } |
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
| clamp (n, min, max) { | |
| return Math.max(Math.min(n, max), min) | |
| } |
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
| export const repeat = (str, times) => (new Array(times + 1)).join(str); | |
| export const padStart = (num, maxLength, char = ' ') => repeat(char, maxLength - num.toString().length) + num; | |
| export const formatTime = (time) => { | |
| const h = padStart(time.getHours(), 2, '0'); | |
| const m = padStart(time.getMinutes(), 2, '0'); | |
| const s = padStart(time.getSeconds(), 2, '0'); | |
| const ms = padStart(time.getMilliseconds(), 3, '0'); | |
| return `${h}:${m}:${s}.${ms}`; |
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 roman = (n) => { | |
| n = String(Math.floor(Math.abs(n))) | |
| let element, i, result = '' | |
| const table = [ | |
| ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'IX'], | |
| ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'], | |
| ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'] | |
| ] | |
| for (i = 0; i < table.length; i += 1) { |