Created
April 25, 2016 11:58
-
-
Save nataliefl/338996c992fe011f65f8b0f700a68a50 to your computer and use it in GitHub Desktop.
Draft of logging lib for comscore maelstrom
This file contains 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 store = {}; | |
module.exports.get = function get() { | |
var items = {}; | |
Array.prototype.slice.call(arguments) | |
.filter(function (arg){ | |
return store[arg]; | |
}) | |
.map(function(arg){ | |
//Returning literal set the key name to "arg", hence this | |
items[arg] = store[arg]; | |
}); | |
return items; | |
}; | |
module.exports.increment = function(key) { | |
if(typeof store[key] === 'undefined'){ | |
return store[key] = 1; | |
} | |
var val = Number(store[key]); | |
if(val === store[key] && val%1 === 0){ | |
return store[key] = ++val; | |
} | |
log.warn("Failed to increment %s. It is not an integer.", store[key]) | |
return 0; | |
}; | |
module.exports.append = function(key, value) { | |
if(typeof store[key] === 'undefined'){ | |
return store[key] = [value]; | |
} | |
if(Object.prototype.toString.call(store[key]) === '[object Array]'){ | |
return store[key] = store[key].concat([value]); | |
} | |
log.warn("Failed to append %s. It is not an array.", store[key]); | |
return null; | |
}; | |
module.exports.set = function(key, value){ | |
return store[key] = value; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment