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
| ClassList.prototype.reduce = function (reducer, initialValue) { | |
| return ClassList.of(this._classes.reduce(reducer, initialValue)); | |
| } | |
| // Notice how we can define "filter" by reducing the previous array | |
| // into a new array with only the values that satisfies the predicate | |
| ClassList.prototype.filter = function (predicate) { | |
| return ClassList.of(this.getClasses()).reduce((newList, currentClass) => { | |
| if (predicate(currentClass)) newList.push(currentClass); |
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 mapFn = fn => lst => lst.map(fn); | |
| const solarize = cls => cls.concat('--solarized'); | |
| const mapSolarize = mapFn(solarize); | |
| ClassList.of([ | |
| 'btn', | |
| 'btn-primary', | |
| 'btn-primary--active' | |
| ]).map(mapSolarize).getClasses(); |
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 flattenArray(array) { | |
| let temp = []; | |
| function flatten(arr) { | |
| if (Array.isArray(arr)) { | |
| const [head, tail] = [arr[0], arr.slice(1)] | |
| flatten(head); | |
| if (tail.length > 0) flatten(tail); |
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 countWatchers(scope) { | |
| if (!scope) { | |
| return 0; | |
| } | |
| if (scope.vm) { | |
| let log = [scope.vm.__proto__.constructor.name, scope.$$watchers && scope.$$watchers.length] | |
| console.log(log.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
| export const pad = (char) => ( | |
| (number, padLeft = false) => ( | |
| (str) => ( | |
| number | |
| ? (padLeft | |
| ? pad(char)(--number)('' + char).concat(str + '') | |
| : pad(char)(--number)('' + str).concat(char + '')) | |
| : 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 mapValues(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| result[key] = fn(obj[key], key); | |
| return result; | |
| }, {}); | |
| } | |
| function pick(obj, fn) { | |
| return Object.keys(obj).reduce((result, key) => { | |
| if (fn(obj[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
| function eachKey(obj, f) { | |
| for(var key in obj) { | |
| if( obj.hasOwnProperty(key) ) | |
| f(key, obj[key]); | |
| } | |
| } | |
| function adtcase (base, proto, key) { | |
| return (...args) => { | |
| var inst = new base(); |
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
| /** | |
| * The first commented line is your dabblet’s title | |
| */ | |
| background: linear-gradient(135deg, #0e0d26 0%, #16152c 24%, #0c1a26 47%, #05161b 73%, #020d13 93%, #020D14 100%); | |
| min-height: 100%; |
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 isArray(elm) { | |
| return ('object' === typeof elm && elm.length >= 0); | |
| } | |
| function cons(elm1, elm2) { | |
| if (!isArray(elm1)) elm1 = [elm1]; | |
| return elm1.concat(elm2); | |
| } | |
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 sprintf = function (str) { | |
| var args = Array.prototype.slice.call(arguments, 1), | |
| hash = { | |
| '%s': String, | |
| '%d': parseInt, | |
| '%f': parseFloat | |
| }; | |
| return str.replace(/%0(\d+)d/g, function (m, num) { | |
| var r = String(args.shift()), | |
| c = ''; |