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
var object = {}, i = 0; | |
while (i++ < 100000) { | |
object['user' + i] = i; | |
} | |
// fastest | |
console.time('keys for'); | |
var result; | |
var keys = Object.keys(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
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; |
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 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]; |
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 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') { |
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
/* | |
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]; |
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 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) { |
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
'use strict'; | |
var object = { | |
hello: 'blue', | |
app: { | |
env: { | |
port: 7777, | |
la: 1 | |
} | |
}, |
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
/* | |
type: constructor name ('String', 'Array', 'Object', 'Function') | |
value: variable | |
*/ | |
function is (type, value) { | |
return !value ? false : value.constructor.name === type; | |
} | |
/* |
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 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) { |
NewerOlder