Skip to content

Instantly share code, notes, and snippets.

Avatar
:bowtie:

Alexander Elias vokeio

:bowtie:
View GitHub Profile
@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 / 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 / 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];
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) {
View observe-object.js
'use strict';
var object = {
hello: 'blue',
app: {
env: {
port: 7777,
la: 1
}
},
@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;
}
/*
@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) {
You can’t perform that action at this time.