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 getNodePath (node) { | |
| var path = []; | |
| while (node) { | |
| path.unshift(toSelector(node)); | |
| if (node === document.body || node.id.length > 0) { | |
| return path.join(' '); | |
| } | |
| node = node.parentNode; | |
| } | |
| return path.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 function which which allows you to apply a list of functions (supplied as arguments) to a value. | |
| // | |
| // Usage: pipe(functions...)(value) | |
| // | |
| // Example: var getFirstWordLetter = pipe(getFirstWord, getFirstLetter); | |
| // getFirstWordLetter('Sean MacIsaac') | |
| // -> 'S' | |
| function pipe () { | |
| var functionList = [].slice.call(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
| // A function to return an array of indexes for a matching string. | |
| // Usage : indexesOf('this, this this', 'this'); | |
| // Usage : indexesOf('this, this this', /t[a-z]{3}/); | |
| // -> [{"index":0,"length":4,"match":"this"}, | |
| // {"index":6,"length":4,"match":"this"}, | |
| // {"index":11,"length":4,"match":"this"}] | |
| // | |
| // The 'and' method: | |
| // Usage : indexesOf('this, this this', /t[a-z]{3}/).and(/i/); | |
| // -> [{"index":0,"length":4,"match":"this"}, |
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) { |
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
| 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
| 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 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 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 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(''); | |
| } |
OlderNewer