Compare commits

...

12 Commits

Author SHA1 Message Date
cab52e1b02 0.0.9 2015-12-02 15:23:59 +01:00
d601a0eeb0 Merge branch 'master' of github.com:pushrocks/smartenv 2015-12-02 15:23:59 +01:00
491f22ffca clean up and fix some errors 2015-12-02 15:23:48 +01:00
1fec5323d9 closes #1 2015-12-01 08:29:58 +01:00
582afc0361 0.0.8 2015-11-30 20:01:08 +01:00
c054ecb0c7 cleaned up 2015-11-30 20:01:02 +01:00
249b626bb5 0.0.7 2015-11-30 19:58:41 +01:00
08d743477f further modularized code 2015-11-30 19:58:35 +01:00
fb64e8004d 0.0.6 2015-11-30 15:04:13 +01:00
f5e48e4fd3 now using classes, remove global funcionality to prevent bad habits 2015-11-30 15:04:04 +01:00
d2de8231cc 0.0.5 2015-11-28 14:50:05 +01:00
0f784e2d74 smartenv.exportEnv and smartenv.importEnv added 2015-11-28 14:49:44 +01:00
13 changed files with 260 additions and 107 deletions

9
.gitignore vendored
View File

@ -1,3 +1,10 @@
node_modules/
.settings/
.idea/
.idea/
#npm devug
npm-debug.log
ts/*.js
ts/*.js.map

132
index.js
View File

@ -1,31 +1,109 @@
/// <reference path="index.ts" />
var Environment = (function () {
function Environment(runtimeEnvArg, userAgentArg) {
if (userAgentArg === void 0) { userAgentArg = "undefined"; }
this.runtimeEnv = runtimeEnvArg;
this.userAgent = userAgentArg;
if (runtimeEnvArg == "node") {
this.isBrowser = false;
this.isNode = true;
this.nodeVersion = process.version;
}
else {
this.isBrowser = true;
this.isNode = true;
this.nodeVersion = "undefined";
}
}
;
return Environment;
})();
/// <reference path="index.ts" />
/**
* Deals with the environment the current JS script is running in.
*/
var SmartenvEnvironment;
(function (SmartenvEnvironment) {
var environment;
var envDetermined = false;
/**
* returns the environment
* @returns {Environment}
*/
var getEnv = function () {
if (!envDetermined) {
(function () {
var localRunTimeEnv = "undefined";
var localUserAgent = "undefined";
if (typeof window !== 'undefined') {
localRunTimeEnv = 'browser';
localUserAgent = navigator.userAgent;
}
else if (typeof process !== 'undefined') {
localRunTimeEnv = 'node';
}
environment = new Environment(localRunTimeEnv, localUserAgent);
})();
}
;
return environment;
};
/**
* prints the environment to console
*/
var printEnv = function () {
if (this.getEnv().isNode) {
var smartenvVersion = require("./package.json").version;
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
}
else {
plugins.beautylog.log("browser is " + this.getEnv().userAgent);
}
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.obs.getComplete()));
};
SmartenvEnvironment.init = function (objectArg) {
objectArg.getEnv = getEnv;
objectArg.printEnv = printEnv;
};
})(SmartenvEnvironment || (SmartenvEnvironment = {}));
/// <reference path="index.ts" />
var SmartenvObjectStorage;
(function (SmartenvObjectStorage) {
function init() {
var obs = {};
var obsItems = {};
obs.addItem = function (objectArg, paramName) {
if (paramName === void 0) { paramName = "undefined"; }
if (paramName == "undefined") {
plugins.beautylog.error("paramName is undefined");
return;
}
obsItems[paramName] = objectArg;
};
obs.getItem = function (keyName) {
return obsItems[keyName];
};
obs.getComplete = function () {
return obsItems;
};
obs.addComplete = function (itemsArg) {
obsItems = plugins._.assign(obsItems, itemsArg);
return obsItems;
};
return obs;
}
SmartenvObjectStorage.init = init;
})(SmartenvObjectStorage || (SmartenvObjectStorage = {}));
/// <reference path="typings/tsd.d.ts" />
var beautylog = require("beautylog")("os");
var addToGlobal = function (objectArg, paramName) {
global[paramName] = objectArg;
/// <reference path="smartenv.classes.ts" />
/// <reference path="smartenv.environment.ts" />
/// <reference path="smartenv.objectstorage.ts" />
var plugins = {
beautylog: require("beautylog")("os"),
_: require("lodash")
};
var smartenv = {}; //create smartenv object
smartenv.items = {}; // create the items object to store items to.
smartenv.makeGlobal = function () {
addToGlobal(smartenv, "smartenv"); //add object smartenv as global["smartenv"]
};
smartenv.info = {};
smartenv.info.node = {};
smartenv.info.node.version = process.version;
smartenv.info.print = function () {
var pck = require("./package.json");
beautylog.log("node version is " + smartenv.info.node.version + " and smartenv version is " + pck.version);
beautylog.log("the smartenv module currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.items).sort());
};
smartenv.register = function (objectArg, paramName) {
if (paramName === void 0) { paramName = "undefined"; }
if (paramName == "undefined") {
beautylog.error("paramName is undefined");
return;
}
smartenv.items[paramName] = objectArg;
};
smartenv.get = function (keyName) {
return smartenv.items[keyName];
};
SmartenvEnvironment.init(smartenv);
smartenv.obs = SmartenvObjectStorage.init();
module.exports = smartenv;

View File

@ -1,6 +1,6 @@
{
"name": "smartenv",
"version": "0.0.4",
"version": "0.0.9",
"description": "store things about your environment and let them travel across modules",
"main": "index.js",
"scripts": {
@ -23,7 +23,8 @@
},
"homepage": "https://github.com/pushrocks/smartenv",
"dependencies": {
"beautylog": "^1.0.4"
"beautylog": "^1.0.4",
"lodash": "^3.10.1"
},
"devDependencies": {
"gulp": "^3.9.0",

14
test.js
View File

@ -2,11 +2,13 @@
var smartenv = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.info.print();
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.register({ key1: "Peter" }, "docit");
smartenv.info.print();
beautylog.log(smartenv.get("docit").key1);
smartenv.makeGlobal();
beautylog.log(global.smartenv.get("docit").key1);
smartenv.obs.addItem({ key1: "Peter" }, "docit");
smartenv.printEnv();
beautylog.log(smartenv.obs.getItem("docit").key1);
beautylog.log(smartenv.obs.getItem("docit").key1);
var key2 = "hello";
smartenv.obs.getItem("docit").key2 = key2;
beautylog.log(smartenv.obs.getItem("docit").key2);
beautylog.success("Success!");

View File

@ -1,32 +1,13 @@
/// <reference path="typings/tsd.d.ts" />
var beautylog = require("beautylog")("os");
var addToGlobal = function (objectArg, paramName) {
global[paramName] = objectArg;
/// <reference path="smartenv.classes.ts" />
/// <reference path="smartenv.environment.ts" />
/// <reference path="smartenv.objectstorage.ts" />
var plugins = {
beautylog: require("beautylog")("os"),
_: require("lodash")
};
var smartenv = {}; //create smartenv object
smartenv.items = {}; // create the items object to store items to.
smartenv.makeGlobal = function () {
addToGlobal(smartenv, "smartenv"); //add object smartenv as global["smartenv"]
};
smartenv.info = {};
smartenv.info.node = {};
smartenv.info.node.version = process.version;
smartenv.info.print = function () {
var pck = require("./package.json");
beautylog.log("node version is " + smartenv.info.node.version + " and smartenv version is " + pck.version);
beautylog.log("the smartenv module currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.items).sort());
};
smartenv.register = function (objectArg, paramName) {
if (paramName === void 0) { paramName = "undefined"; }
if (paramName == "undefined") {
beautylog.error("paramName is undefined");
return;
}
smartenv.items[paramName] = objectArg;
};
smartenv.get = function (keyName) {
return smartenv.items[keyName];
};
SmartenvEnvironment.init(smartenv);
smartenv.obs = SmartenvObjectStorage.init();
module.exports = smartenv;
//# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["index.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,IAAI,WAAW,GAAG,UAAS,SAAS,EAAC,SAAS;IAC1C,MAAM,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAClC,CAAC,CAAC;AACF,IAAI,QAAQ,GAAO,EAAE,CAAC,CAAC,wBAAwB;AAC/C,QAAQ,CAAC,KAAK,GAAG,EAAE,CAAC,CAAC,6CAA6C;AAClE,QAAQ,CAAC,UAAU,GAAG;IAClB,WAAW,CAAC,QAAQ,EAAC,UAAU,CAAC,CAAC,CAAA,2CAA2C;AAChF,CAAC,CAAC;AAGF,QAAQ,CAAC,IAAI,GAAG,EAAE,CAAC;AACnB,QAAQ,CAAC,IAAI,CAAC,IAAI,GAAG,EAAE,CAAC;AACxB,QAAQ,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,CAAC;AAC7C,QAAQ,CAAC,IAAI,CAAC,K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,CAAC,GAAG,GAAG,qBAAqB,CAAC,IAAI,EAAE,CAAC;AAI5C,MAAM,CAAC,OAAO,GAAG,QAAQ,CAAC"}

View File

@ -1,34 +1,16 @@
/// <reference path="typings/tsd.d.ts" />
var beautylog = require("beautylog")("os");
var addToGlobal = function(objectArg,paramName) {
global[paramName] = objectArg;
};
var smartenv:any = {}; //create smartenv object
smartenv.items = {}; // create the items object to store items to.
smartenv.makeGlobal = function() {
addToGlobal(smartenv,"smartenv");//add object smartenv as global["smartenv"]
};
smartenv.info = {};
smartenv.info.node = {};
smartenv.info.node.version = process.version;
smartenv.info.print = function() {
var pck = require("./package.json");
beautylog.log("node version is " + smartenv.info.node.version + " and smartenv version is " + pck.version);
beautylog.log("the smartenv module currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.items).sort());
};
smartenv.register = function(objectArg,paramName = "undefined") {
if (paramName == "undefined"){
beautylog.error("paramName is undefined");
return;
}
smartenv.items[paramName] = objectArg;
};
smartenv.get = function(keyName) {
return smartenv.items[keyName];
/// <reference path="smartenv.classes.ts" />
/// <reference path="smartenv.environment.ts" />
/// <reference path="smartenv.objectstorage.ts" />
var plugins = {
beautylog: require("beautylog")("os"),
_: require("lodash")
}
var smartenv:any = {}; //create smartenv object
SmartenvEnvironment.init(smartenv);
smartenv.obs = SmartenvObjectStorage.init();
module.exports = smartenv;

21
ts/smartenv.classes.ts Normal file
View File

@ -0,0 +1,21 @@
/// <reference path="index.ts" />
class Environment {
public runtimeEnv:string;
public userAgent:string;
public nodeVersion:string;
public isBrowser:boolean;
public isNode:boolean;
constructor(runtimeEnvArg,userAgentArg = "undefined") {
this.runtimeEnv = runtimeEnvArg;
this.userAgent = userAgentArg;
if(runtimeEnvArg == "node"){
this.isBrowser = false;
this.isNode = true;
this.nodeVersion = process.version;
} else {
this.isBrowser = true;
this.isNode = true;
this.nodeVersion = "undefined";
}
};
}

View File

@ -0,0 +1,49 @@
/// <reference path="index.ts" />
/**
* Deals with the environment the current JS script is running in.
*/
module SmartenvEnvironment {
var environment:Environment;
var envDetermined:boolean = false;
/**
* returns the environment
* @returns {Environment}
*/
var getEnv = function(){
if (!envDetermined) {
(function() {
var localRunTimeEnv = "undefined";
var localUserAgent = "undefined";
if (typeof window !== 'undefined') {
localRunTimeEnv = 'browser';
localUserAgent = navigator.userAgent;
} else if (typeof process !== 'undefined') {
localRunTimeEnv = 'node';
}
environment = new Environment(localRunTimeEnv,localUserAgent);
})();
};
return environment;
};
/**
* prints the environment to console
*/
var printEnv = function() {
if (this.getEnv().isNode) {
var smartenvVersion = require("./package.json").version;
plugins.beautylog.log("node version is " + this.getEnv().nodeVersion + " and smartenv version is " + smartenvVersion);
} else {
plugins.beautylog.log("browser is " + this.getEnv().userAgent)
}
plugins.beautylog.log("the smartenv registration store currently holds the following properties:");
console.log(Object.getOwnPropertyNames(smartenv.obs.getComplete()));
}
export var init = function(objectArg) {
objectArg.getEnv = getEnv;
objectArg.printEnv = printEnv;
}
}

View File

@ -0,0 +1,26 @@
/// <reference path="index.ts" />
module SmartenvObjectStorage {
export function init() {
var obs:any = {};
var obsItems:any = {};
obs.addItem = function(objectArg,paramName = "undefined") {
if (paramName == "undefined"){
plugins.beautylog.error("paramName is undefined");
return;
}
obsItems[paramName] = objectArg;
};
obs.getItem = function(keyName) {
return obsItems[keyName];
};
obs.getComplete = function () {
return obsItems;
}
obs.addComplete = function(itemsArg) {
obsItems = plugins._.assign(obsItems,itemsArg);
return obsItems;
};
return obs;
}
}

View File

@ -2,12 +2,14 @@
var smartenv = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.info.print();
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.register({ key1: "Peter" }, "docit");
smartenv.info.print();
beautylog.log(smartenv.get("docit").key1);
smartenv.makeGlobal();
beautylog.log(global.smartenv.get("docit").key1);
smartenv.obs.addItem({ key1: "Peter" }, "docit");
smartenv.printEnv();
beautylog.log(smartenv.obs.getItem("docit").key1);
beautylog.log(smartenv.obs.getItem("docit").key1);
var key2 = "hello";
smartenv.obs.getItem("docit").key2 = key2;
beautylog.log(smartenv.obs.getItem("docit").key2);
beautylog.success("Success!");
//# sourceMappingURL=test.js.map

View File

@ -1 +1 @@
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACrC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;AACtB,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,QAAQ,CAAC,EAAC,IAAI,EAAC,OAAO,EAAC,EAAC,OAAO,CAAC,CAAC;AAC1C,QAAQ,CAAC,IAAI,CAAC,KAAK,EAAE,CAAC;AACtB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AAC1C,QAAQ,CAAC,UAAU,EAAE,CAAC;AACtB,SAAS,CAAC,GAAG,CAAC,MAAM,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AACjD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC"}
{"version":3,"file":"test.js","sourceRoot":"","sources":["test.ts"],"names":[],"mappings":"AAAA,yCAAyC;AACzC,IAAI,QAAQ,GAAG,OAAO,CAAC,YAAY,CAAC,CAAC;AACrC,IAAI,SAAS,GAAG,OAAO,CAAC,WAAW,CAAC,CAAC,IAAI,CAAC,CAAC;AAC3C,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,IAAI,CAAC,iCAAiC,CAAC,CAAC;AAClD,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,EAAC,IAAI,EAAC,OAAO,EAAC,EAAC,OAAO,CAAC,CAAC;AAC7C,QAAQ,CAAC,QAAQ,EAAE,CAAC;AACpB,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AAClD,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AAElD,IAAI,IAAI,GAAG,OAAO,CAAC;AACnB,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,GAAG,IAAI,CAAC;AAC1C,SAAS,CAAC,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,CAAC;AAElD,SAAS,CAAC,OAAO,CAAC,UAAU,CAAC,CAAC"}

View File

@ -2,11 +2,15 @@
var smartenv = require("./index.js");
var beautylog = require("beautylog")("os");
beautylog.info("Now testing the smartenv module");
smartenv.info.print();
smartenv.printEnv();
beautylog.info("Now testing the smartenv module");
smartenv.register({key1:"Peter"},"docit");
smartenv.info.print();
beautylog.log(smartenv.get("docit").key1);
smartenv.makeGlobal();
beautylog.log(global.smartenv.get("docit").key1);
smartenv.obs.addItem({key1:"Peter"},"docit");
smartenv.printEnv();
beautylog.log(smartenv.obs.getItem("docit").key1);
beautylog.log(smartenv.obs.getItem("docit").key1);
var key2 = "hello";
smartenv.obs.getItem("docit").key2 = key2;
beautylog.log(smartenv.obs.getItem("docit").key2);
beautylog.success("Success!");