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 createSubscriber() { | |
'use strict'; | |
var subscriber = {}; | |
var f = {}; | |
if (typeof f !== 'object') { | |
throw 'The argument for \'createSubscriber\' must be type object'; | |
} |
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
/* | |
createNode(tagNameOrNode, attributes, callback(createNode)) | |
eg > | |
createNode('div', { | |
class : 'my-class-name' | |
}, function (newNode) { | |
}); | |
returns a list of chained methods | |
- .append(Node) | |
*/ |
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
// Here is a JSFiddle with a concrete example: https://jsfiddle.net/SeanJM/rg3ftcgk/1/ | |
// this is one my most leveraged functions that I use to keep my code nice and modular | |
// - | |
// Changes made from https://gist.github.com/lewisje/041f4d25d12c8a135a8b | |
// Based on a post in reddit https://www.reddit.com/r/javascript/comments/46xaln/what_goto_libraries_frameworks_tools_or_otherwise/d08wr56 | |
// from https://www.reddit.com/user/lewisje | |
function fnChain(target, source, args) { | |
'use strict'; | |
var name; |
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 jsCase(string) { | |
return string.match(/[a-zA-Z0-9_]+/g).map(function (a, i) { | |
if (i === 0) { | |
return a.toLowerCase(); | |
} | |
return a[0].toUpperCase() + a.substr(1, a.length).toLowerCase(); | |
}).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
function kebabCase(string) { | |
return string.split(/ |_|-/).join('-').split('').map(function (a) { | |
if (a.toUpperCase() === a && a !== '-') { | |
return '-' + a.toLowerCase(); | |
} | |
return a; | |
}).join('').toLowerCase(); | |
} |
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 arrayUniq(array) { | |
var u = []; | |
array.forEach(function (a) { | |
if (u.indexOf(a) === -1) { | |
u.push(a); | |
} | |
}); | |
return u; | |
} |
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 arrayRemove(array, removeList) { | |
var clone = array.slice(); | |
removeList.forEach(function (a) { | |
while (clone.indexOf(a) > -1) { | |
clone.splice(clone.indexOf(a), 1); | |
} | |
}); | |
return clone; | |
} |
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 control (node) { | |
var hookMatch = /^-js-[a-zA-Z-\_]+|\s-js-[a-zA-Z-\_]+/g; | |
function jsCase(string) { | |
return string.match(/[a-zA-Z0-9_]+/g).map(function (a, i) { | |
if (i === 0) { | |
return a.toLowerCase(); | |
} | |
return a[0].toUpperCase() + a.substr(1, a.length).toLowerCase(); | |
}).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
// A framework to build a number manipulation library | |
// Usage: lumber(5).padLeft(2).value; | |
// -> 05 | |
// Usage: lumber(5).padRight(2).value; | |
// -> 50 | |
// Usage: lumber(5.1).currency().value; | |
// Default arguments for '.currency()' is a template of value: '($0.00)' | |
// -> $5.10 | |
// Usage: lumber(-5.1).currency().value; | |
// -> ($5.10) |
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
// Usage : stringSplice('my string', 2, 0, ' awesome'); | |
// -> 'my awesome string' | |
// | |
// How to extend the native string prototype (if you want): | |
// String.prototype.splice = function () { | |
// var args = [].slice.call(arguments); | |
// return stringSplice.apply(null, [this.valueOf()].concat(args)); | |
// }; | |
function stringSplice(baseString, start, length, newString) { |