Skip to content

Instantly share code, notes, and snippets.

🎯
Focusing

Alexander Elias vokeio

🎯
Focusing
Block or report user

Report or block vokeio

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@vokeio
vokeio / flatten-object.js
Last active Oct 9, 2016
Flattens a multi level object to a single level object with paths
View flatten-object.js
function flattenObject (object) {
var flatObject = {};
for (var key in object) {
if (!object.hasOwnProperty(key)) continue;
if (object[key] && object[key].constructor.name === 'Object') {
var childObject = flattenObject(object[key]);
for (var childKey in childObject) {
@vokeio
vokeio / is.js
Last active Sep 14, 2016
Primitive Type Check
View is.js
/*
type: constructor name ('String', 'Array', 'Object', 'Function')
value: variable
*/
function is (type, value) {
return !value ? false : value.constructor.name === type;
}
/*
View observe-object.js
'use strict';
var object = {
hello: 'blue',
app: {
env: {
port: 7777,
la: 1
}
},
View string-manipulation.js
function toCamelCase (string) {
var nextIndex = string.search('-') + 1;
var nextLetter = string.charAt(nextIndex).toString();
var r = '-' + nextLetter;
var n = nextLetter.toUpperCase();
return string.replace(r, n);
}
function fromCamelCase (string) {
@vokeio
vokeio / edit-style-sheet.js
Created Sep 2, 2016
Edit Style Sheet Javascript
View edit-style-sheet.js
/*
var name = 'nav-bar';
var selector = '.nav-bar > ul.active';
var key = 'transform';
getRule(name, selector, key, function (sTransform) {
var values = getTranslateValues(sTransform);
var x = values[0] - 100;
var y = values[1];
var z = values[2];
@vokeio
vokeio / each.js
Last active Feb 7, 2017
Loop through each an iterable and enables, break, continue, and manipulation.
View each.js
function each (iterable, callback, scope) {
var statment = null, i = null, l = null, k = null;
if (iterable.constructor.name === 'Number') {
for (i = 0; i < iterable; i++) {
statment = callback.call(scope, i, iterable);
if (statment === 'break') break;
else if (statment === 'continue') continue;
}
} else if (iterable.constructor.name === 'Map') {
@vokeio
vokeio / manipulate-object.js
Created Feb 8, 2017
Object Manipulation Object
View manipulate-object.js
function getByPath(object, path) {
var keys = path.replace('[', '.').replace(']', '').split('.');
var last = keys.length - 1;
var obj = object;
for (var i = 0; i < last; i++) {
var prop = keys[i];
if (!obj[prop]) return undefined;
obj = obj[prop];
@vokeio
vokeio / umd.js
Created Feb 16, 2017
A better way then umd
View umd.js
var NAME = '';
var MODULE = {} || function () {};
(function (t, n, m) {
if (typeof m === 'function') m = m(t);
if (typeof t.define !== 'undefined') t.define([n], m);
else if (typeof t.module !== 'undefined') t.module.exports = m;
else if (typeof t.window !== 'undefined') t.window[n] = m;
else return m;
View test-object-loop.js
var object = {}, i = 0;
while (i++ < 100000) {
object['user' + i] = i;
}
// fastest
console.time('keys for');
var result;
var keys = Object.keys(object);
View promise-async-each.js
function each (condition, method, context, index) {
index = index === undefined ? 0 : index;
if (condition.call(context, index)) {
return Promise.resolve().then(function () {
return method.call(context, index);
}).then(each.bind(null, condition, method, context, index+1));
} else {
return Promise.resolve();
}
You can’t perform that action at this time.