Skip to content

Instantly share code, notes, and snippets.

@nataliefl
Created April 25, 2016 11:58
Show Gist options
  • Save nataliefl/338996c992fe011f65f8b0f700a68a50 to your computer and use it in GitHub Desktop.
Save nataliefl/338996c992fe011f65f8b0f700a68a50 to your computer and use it in GitHub Desktop.
Draft of logging lib for comscore maelstrom
'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