Skip to content

Instantly share code, notes, and snippets.

View SeanJM's full-sized avatar

Sean MacIsaac SeanJM

  • Sean J MacIsaac
  • Montreal, QC
View GitHub Profile
function createSubscriber() {
'use strict';
var subscriber = {};
var f = {};
if (typeof f !== 'object') {
throw 'The argument for \'createSubscriber\' must be type object';
}
/*
createNode(tagNameOrNode, attributes, callback(createNode))
eg >
createNode('div', {
class : 'my-class-name'
}, function (newNode) {
});
returns a list of chained methods
- .append(Node)
*/
@SeanJM
SeanJM / fnChain.js
Last active March 15, 2016 18:45
A function which allows the augmentation of an Object with functional methods.
// 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;
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('');
}
@SeanJM
SeanJM / kebabCase.js
Created December 23, 2015 14:27
A function which 'kebab' cases a string
function kebabCase(string) {
return string.split(/ |_|-/).join('-').split('').map(function (a) {
if (a.toUpperCase() === a && a !== '-') {
return '-' + a.toLowerCase();
}
return a;
}).join('').toLowerCase();
}
@SeanJM
SeanJM / arrayUniq.js
Created December 23, 2015 14:24
A function which returns the uniq members of an array
function arrayUniq(array) {
var u = [];
array.forEach(function (a) {
if (u.indexOf(a) === -1) {
u.push(a);
}
});
return u;
}
@SeanJM
SeanJM / arrayRemove.js
Last active December 23, 2015 14:22
A function which removes members from an Array
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;
}
@SeanJM
SeanJM / control.js
Last active December 9, 2015 15:32
an event binder
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('');
}
@SeanJM
SeanJM / lumber.js
Last active December 30, 2015 17:44
A framework to build a number manipulation library with built in functions for currency, padding and grouping
// 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)
@SeanJM
SeanJM / stringSplice.js
Created December 3, 2015 13:01
A function to splice strings.
// 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) {