Compare commits
57 Commits
Author | SHA1 | Date | |
---|---|---|---|
2f11d1ba0f | |||
33692ff417 | |||
f408337186 | |||
bd6d574226 | |||
d5c2d167ec | |||
2af6d5a974 | |||
fdba21d60d | |||
c17ebca309 | |||
a014dcf1ab | |||
44bee7bf6f | |||
7841917058 | |||
f5a674f98d | |||
80ece7c093 | |||
39250b3d47 | |||
ed78c0becf | |||
63c103fde5 | |||
88003bde0f | |||
276a0641e8 | |||
b166269cb4 | |||
3ca1b425bf | |||
ffc07da665 | |||
be2adaf259 | |||
7aa9637826 | |||
a3c4f87741 | |||
f005f57764 | |||
6e418cdbf8 | |||
87155900e1 | |||
d24b11f737 | |||
17ebd58951 | |||
32bd229f91 | |||
4e5ddf8411 | |||
701c7c1b8b | |||
9a272def16 | |||
0213950aae | |||
b7342dbf05 | |||
677c8d33b9 | |||
ffc781011d | |||
aeec1b36a3 | |||
4c2e7f9446 | |||
dddad457f3 | |||
4f110c6e64 | |||
12d971c470 | |||
886c245e8d | |||
50d610e5df | |||
5edb62c134 | |||
38f22a6d95 | |||
91cdb71388 | |||
ab33e97c8d | |||
47f840841c | |||
fe2210dc9f | |||
489ebab6ee | |||
46baf07551 | |||
cf0aabfbfc | |||
a5005aeb96 | |||
a7e9f1303d | |||
92a6508c6a | |||
32f6b5cbf8 |
26
.gitignore
vendored
26
.gitignore
vendored
@ -1,14 +1,20 @@
|
||||
node_modules/
|
||||
.settings/
|
||||
.idea/
|
||||
.nogit/
|
||||
|
||||
# artifacts
|
||||
coverage/
|
||||
docs/
|
||||
public/
|
||||
pages/
|
||||
|
||||
#npm devug
|
||||
npm-debug.log
|
||||
# installs
|
||||
node_modules/
|
||||
|
||||
ts/*.js
|
||||
ts/*.js.map
|
||||
ts/typings/
|
||||
# caches
|
||||
.yarn/
|
||||
.cache/
|
||||
.rpt2_cache
|
||||
|
||||
test/browser/browserified/
|
||||
# builds
|
||||
dist/
|
||||
dist_*/
|
||||
|
||||
# custom
|
108
.gitlab-ci.yml
108
.gitlab-ci.yml
@ -1,59 +1,137 @@
|
||||
image: hosttoday/ht-docker-node:npmts
|
||||
# gitzone ci_default
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
|
||||
cache:
|
||||
paths:
|
||||
- .npmci_cache/
|
||||
key: '$CI_BUILD_STAGE'
|
||||
|
||||
stages:
|
||||
- security
|
||||
- test
|
||||
- release
|
||||
- trigger
|
||||
- pages
|
||||
- metadata
|
||||
|
||||
testLEGACY:
|
||||
stage: test
|
||||
# ====================
|
||||
# security stage
|
||||
# ====================
|
||||
mirror:
|
||||
stage: security
|
||||
script:
|
||||
- npmci test legacy
|
||||
- npmci git mirror
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
auditProductionDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --production --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=prod --production
|
||||
tags:
|
||||
- docker
|
||||
|
||||
auditDevDependencies:
|
||||
image: registry.gitlab.com/hosttoday/ht-docker-node:npmci
|
||||
stage: security
|
||||
script:
|
||||
- npmci npm prepare
|
||||
- npmci command npm install --ignore-scripts
|
||||
- npmci command npm config set registry https://registry.npmjs.org
|
||||
- npmci command npm audit --audit-level=high --only=dev
|
||||
tags:
|
||||
- docker
|
||||
allow_failure: true
|
||||
|
||||
testLTS:
|
||||
# ====================
|
||||
# test stage
|
||||
# ====================
|
||||
|
||||
testStable:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test lts
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci npm test
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
testSTABLE:
|
||||
testBuild:
|
||||
stage: test
|
||||
script:
|
||||
- npmci test stable
|
||||
- npmci npm prepare
|
||||
- npmci node install stable
|
||||
- npmci npm install
|
||||
- npmci command npm run build
|
||||
coverage: /\d+.?\d+?\%\s*coverage/
|
||||
tags:
|
||||
- docker
|
||||
|
||||
release:
|
||||
stage: release
|
||||
script:
|
||||
- npmci publish
|
||||
- npmci node install stable
|
||||
- npmci npm publish
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
# ====================
|
||||
# metadata stage
|
||||
# ====================
|
||||
codequality:
|
||||
stage: metadata
|
||||
allow_failure: true
|
||||
only:
|
||||
- tags
|
||||
script:
|
||||
- npmci command npm install -g tslint typescript
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command "tslint -c tslint.json ./ts/**/*.ts"
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- priv
|
||||
|
||||
trigger:
|
||||
stage: trigger
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci trigger
|
||||
only:
|
||||
- tags
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
|
||||
pages:
|
||||
image: hosttoday/ht-docker-node:npmpage
|
||||
stage: pages
|
||||
stage: metadata
|
||||
script:
|
||||
- npmci command npmpage --host gitlab
|
||||
- npmci node install lts
|
||||
- npmci command npm install -g @gitzone/tsdoc
|
||||
- npmci npm prepare
|
||||
- npmci npm install
|
||||
- npmci command tsdoc
|
||||
tags:
|
||||
- lossless
|
||||
- docker
|
||||
- notpriv
|
||||
only:
|
||||
- tags
|
||||
artifacts:
|
||||
expire_in: 1 week
|
||||
paths:
|
||||
- public
|
||||
allow_failure: true
|
||||
|
29
.vscode/launch.json
vendored
Normal file
29
.vscode/launch.json
vendored
Normal file
@ -0,0 +1,29 @@
|
||||
{
|
||||
"version": "0.2.0",
|
||||
"configurations": [
|
||||
{
|
||||
"name": "current file",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"${relativeFile}"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
},
|
||||
{
|
||||
"name": "test.ts",
|
||||
"type": "node",
|
||||
"request": "launch",
|
||||
"args": [
|
||||
"test/test.ts"
|
||||
],
|
||||
"runtimeArgs": ["-r", "@gitzone/tsrun"],
|
||||
"cwd": "${workspaceRoot}",
|
||||
"protocol": "inspector",
|
||||
"internalConsoleOptions": "openOnSessionStart"
|
||||
}
|
||||
]
|
||||
}
|
26
.vscode/settings.json
vendored
Normal file
26
.vscode/settings.json
vendored
Normal file
@ -0,0 +1,26 @@
|
||||
{
|
||||
"json.schemas": [
|
||||
{
|
||||
"fileMatch": ["/npmextra.json"],
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"npmci": {
|
||||
"type": "object",
|
||||
"description": "settings for npmci"
|
||||
},
|
||||
"gitzone": {
|
||||
"type": "object",
|
||||
"description": "settings for gitzone",
|
||||
"properties": {
|
||||
"projectType": {
|
||||
"type": "string",
|
||||
"enum": ["website", "element", "service", "npm", "wcc"]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
2
LICENSE
2
LICENSE
@ -1,6 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Push.Rocks
|
||||
Copyright (c) 2015 Lossless GmbH
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
39
README.md
39
README.md
@ -1,39 +0,0 @@
|
||||
# smartenv
|
||||
store things about your environment and let them travel across modules
|
||||
|
||||
## Availabililty
|
||||
[](https://www.npmjs.com/package/smartenv)
|
||||
[](https://gitlab.com/pushrocks/smartenv)
|
||||
[](https://github.com/pushrocks/smartenv)
|
||||
[](https://pushrocks.gitlab.io/smartenv/)
|
||||
|
||||
## Status for master
|
||||
[](https://gitlab.com/pushrocks/smartenv/commits/master)
|
||||
[](https://gitlab.com/pushrocks/smartenv/commits/master)
|
||||
[](https://david-dm.org/pushrocks/smartenv)
|
||||
[](https://www.bithound.io/github/pushrocks/smartenv/master/dependencies/npm)
|
||||
[](https://www.bithound.io/github/pushrocks/smartenv)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](https://nodejs.org/dist/latest-v6.x/docs/api/)
|
||||
[](http://standardjs.com/)
|
||||
|
||||
## Install
|
||||
Install the package through npm
|
||||
|
||||
```
|
||||
npm install smartenv --save
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
||||
```javascript
|
||||
var smartenv = require("smartenv");
|
||||
|
||||
smartenv.info(); //prints an output about your current environment and registered objects
|
||||
smartenv.register({akey:"a text"},"somevalue"); // register a new object
|
||||
smartenv.makeGlobal() // make smartenv available from gobal.smartenv
|
||||
smartenv.get("somevalue").akey; // returns "a text"
|
||||
smartenv.items.somevalue.akey; // also returns "a text"
|
||||
```
|
||||
|
||||
[](https://push.rocks)
|
3
dist/index.d.ts
vendored
3
dist/index.d.ts
vendored
@ -1,3 +0,0 @@
|
||||
import { getEnv, printEnv } from './smartenv.environment';
|
||||
import { obs } from './smartenv.objectstorage';
|
||||
export { getEnv, printEnv, obs };
|
8
dist/index.js
vendored
8
dist/index.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const smartenv_environment_1 = require("./smartenv.environment");
|
||||
exports.getEnv = smartenv_environment_1.getEnv;
|
||||
exports.printEnv = smartenv_environment_1.printEnv;
|
||||
const smartenv_objectstorage_1 = require("./smartenv.objectstorage");
|
||||
exports.obs = smartenv_objectstorage_1.obs;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi90cy9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOztBQUNBLGlFQUF1RDtBQUtyRCxpQkFMTSw2QkFBTSxDQUtOO0FBQ04sbUJBTmMsK0JBQVEsQ0FNZDtBQUxWLHFFQUE4QztBQU01QyxjQU5PLDRCQUFHLENBTVAifQ==
|
11
dist/smartenv.classes.d.ts
vendored
11
dist/smartenv.classes.d.ts
vendored
@ -1,11 +0,0 @@
|
||||
export declare class Environment {
|
||||
runtimeEnv: string;
|
||||
isBrowser: boolean;
|
||||
userAgent: string;
|
||||
isNode: boolean;
|
||||
nodeVersion: string;
|
||||
isCI: boolean;
|
||||
isTravis: boolean;
|
||||
isC9: boolean;
|
||||
constructor();
|
||||
}
|
8
dist/smartenv.classes.helpers.d.ts
vendored
8
dist/smartenv.classes.helpers.d.ts
vendored
@ -1,8 +0,0 @@
|
||||
export declare let getEnvString: () => string;
|
||||
export declare let getUserAgentString: () => string;
|
||||
export declare let isNode: () => boolean;
|
||||
export declare let getNodeVersion: () => string;
|
||||
export declare let isBrowser: () => boolean;
|
||||
export declare let isCI: () => boolean;
|
||||
export declare let isC9: () => boolean;
|
||||
export declare let isTravis: () => boolean;
|
54
dist/smartenv.classes.helpers.js
vendored
54
dist/smartenv.classes.helpers.js
vendored
@ -1,54 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.getEnvString = function () {
|
||||
if (typeof window !== 'undefined') {
|
||||
return 'browser';
|
||||
}
|
||||
else if (typeof process !== 'undefined') {
|
||||
return 'node';
|
||||
}
|
||||
};
|
||||
exports.getUserAgentString = function () {
|
||||
if (exports.isBrowser()) {
|
||||
return navigator.userAgent;
|
||||
}
|
||||
else {
|
||||
return undefined;
|
||||
}
|
||||
};
|
||||
exports.isNode = function () {
|
||||
return exports.getEnvString() === 'node';
|
||||
};
|
||||
exports.getNodeVersion = function () {
|
||||
return process.version;
|
||||
};
|
||||
exports.isBrowser = function () {
|
||||
return !exports.isNode();
|
||||
};
|
||||
exports.isCI = function () {
|
||||
if (process.env.CI) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
;
|
||||
};
|
||||
exports.isC9 = function () {
|
||||
if (process.env.C9_HOSTNAME) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
};
|
||||
exports.isTravis = function () {
|
||||
if (process.env.TRAVIS) {
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
;
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuY2xhc3Nlcy5oZWxwZXJzLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vdHMvc21hcnRlbnYuY2xhc3Nlcy5oZWxwZXJzLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ1csUUFBQSxZQUFZLEdBQUc7SUFDeEIsRUFBRSxDQUFDLENBQUMsT0FBTyxNQUFNLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztRQUNsQyxNQUFNLENBQUMsU0FBUyxDQUFBO0lBQ2xCLENBQUM7SUFBQyxJQUFJLENBQUMsRUFBRSxDQUFDLENBQUMsT0FBTyxPQUFPLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztRQUMxQyxNQUFNLENBQUMsTUFBTSxDQUFBO0lBQ2YsQ0FBQztBQUNILENBQUMsQ0FBQTtBQUVVLFFBQUEsa0JBQWtCLEdBQUc7SUFDOUIsRUFBRSxDQUFDLENBQUMsaUJBQVMsRUFBRSxDQUFDLENBQUMsQ0FBQztRQUNoQixNQUFNLENBQUMsU0FBUyxDQUFDLFNBQVMsQ0FBQTtJQUM1QixDQUFDO0lBQUMsSUFBSSxDQUFDLENBQUM7UUFDTixNQUFNLENBQUMsU0FBUyxDQUFBO0lBQ2xCLENBQUM7QUFDSCxDQUFDLEN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FBQztBQUNKLENBQUMsQ0FBQSJ9
|
18
dist/smartenv.classes.js
vendored
18
dist/smartenv.classes.js
vendored
@ -1,18 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const helpers = require("./smartenv.classes.helpers");
|
||||
class Environment {
|
||||
constructor() {
|
||||
this.runtimeEnv = helpers.getEnvString();
|
||||
this.isBrowser = helpers.isBrowser();
|
||||
this.userAgent = helpers.getUserAgentString();
|
||||
this.isNode = helpers.isNode();
|
||||
this.nodeVersion = helpers.getNodeVersion();
|
||||
this.isCI = helpers.isCI();
|
||||
this.isTravis = helpers.isTravis();
|
||||
this.isC9 = helpers.isC9();
|
||||
}
|
||||
;
|
||||
}
|
||||
exports.Environment = Environment;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYuY2xhc3Nlcy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52LmNsYXNzZXMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSxzREFBc0Q7QUFFdEQ7SUFTSTtRQUNJLElBQUksQ0FBQyxVQUFVLEdBQUcsT0FBTyxDQUFDLFlBQVksRUFBRSxDQUFBO1FBQ3hDLElBQUksQ0FBQyxTQUFTLEdBQUcsT0FBTyxDQUFDLFNBQVMsRUFBRSxDQUFBO1FBQ3BDLElBQUksQ0FBQyxTQUFTLEdBQUcsT0FBTyxDQUFDLGtCQUFrQixFQUFFLENBQUE7UUFDN0MsSUFBSSxDQUFDLE1BQU0sR0FBRyxPQUFPLENBQUMsTUFBTSxFQUFFLENBQUE7UUFDOUIsSUFBSSxDQUFDLFdBQVcsR0FBRyxPQUFPLENBQUMsY0FBYyxFQUFFLENBQUE7UUFDM0MsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxFQUFFLENBQUE7UUFDMUIsSUFBSSxDQUFDLFFBQVEsR0FBRyxPQUFPLENBQUMsUUFBUSxFQUFFLENBQUE7UUFDbEMsSUFBSSxDQUFDLElBQUksR0FBRyxPQUFPLENBQUMsSUFBSSxFQUFFLENBQUE7SUFDOUIsQ0FBQztJQUFBLENBQUM7Q0FDTDtBQW5CRCxrQ0FtQkMifQ==
|
10
dist/smartenv.environment.d.ts
vendored
10
dist/smartenv.environment.d.ts
vendored
@ -1,10 +0,0 @@
|
||||
import * as classes from './smartenv.classes';
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
export declare var getEnv: () => classes.Environment;
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
export declare var printEnv: () => void;
|
35
dist/smartenv.environment.js
vendored
35
dist/smartenv.environment.js
vendored
@ -1,35 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const classes = require("./smartenv.classes");
|
||||
const objectStorage = require("./smartenv.objectstorage");
|
||||
let environment;
|
||||
let envDetermined = false;
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
exports.getEnv = function () {
|
||||
if (!envDetermined) {
|
||||
environment = new classes.Environment();
|
||||
envDetermined = true; // ensure code above only runs once
|
||||
}
|
||||
;
|
||||
return environment;
|
||||
};
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
exports.printEnv = function () {
|
||||
if (this.getEnv().isNode) {
|
||||
console.log('running on NODE');
|
||||
let smartenvVersion = require('../package.json').version;
|
||||
console.log('node version is ' + this.getEnv().nodeVersion + ' and smartenv version is ' + smartenvVersion);
|
||||
}
|
||||
else {
|
||||
console.log('running on BROWSER');
|
||||
console.log('browser is ' + this.getEnv().userAgent);
|
||||
}
|
||||
console.log('the smartenv registration store currently holds the following properties:');
|
||||
console.log(Object.getOwnPropertyNames(objectStorage.obs.getAll()));
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uI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BQyxDQUFBO1FBQ2pDLE9BQU8sQ0FBQyxHQUFHLENBQUMsYUFBYSxHQUFHLElBQUksQ0FBQyxNQUFNLEVBQUUsQ0FBQyxTQUFTLENBQUMsQ0FBQTtJQUN4RCxDQUFDO0lBQ0QsT0FBTyxDQUFDLEdBQUcsQ0FBQywyRUFBMkUsQ0FBQyxDQUFBO0lBQ3hGLE9BQU8sQ0FBQyxHQUFHLENBQUMsTUFBTSxDQUFDLG1CQUFtQixDQUFDLGFBQWEsQ0FBQyxHQUFHLENBQUMsTUFBTSxFQUFFLENBQUMsQ0FBQyxDQUFBO0FBQ3ZFLENBQUMsQ0FBQSJ9
|
5
dist/smartenv.objectstorage.d.ts
vendored
5
dist/smartenv.objectstorage.d.ts
vendored
@ -1,5 +0,0 @@
|
||||
export declare let obsItems: any;
|
||||
/**
|
||||
* Objectstorage allows easy sharing of objects within node
|
||||
*/
|
||||
export declare let obs: any;
|
47
dist/smartenv.objectstorage.js
vendored
47
dist/smartenv.objectstorage.js
vendored
@ -1,47 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const plugins = require("./smartenv.plugins");
|
||||
exports.obsItems = {};
|
||||
/**
|
||||
* Objectstorage allows easy sharing of objects within node
|
||||
*/
|
||||
exports.obs = {
|
||||
add: function (paramNameArg = 'undefined', objectArg = 'undefined') {
|
||||
if (paramNameArg === 'undefined') {
|
||||
console.log('paramName is undefined');
|
||||
return;
|
||||
}
|
||||
if (objectArg === 'undefined') {
|
||||
console.log('objectArg is undefined');
|
||||
}
|
||||
if (typeof exports.obsItems[paramNameArg] === 'undefined') {
|
||||
exports.obsItems[paramNameArg] = objectArg;
|
||||
}
|
||||
else {
|
||||
console.log('object is already present, so add operation has failed.');
|
||||
}
|
||||
return exports.obsItems[paramNameArg];
|
||||
},
|
||||
replace: function (paramNameArg, objectArg) {
|
||||
exports.obsItems[paramNameArg] = objectArg;
|
||||
},
|
||||
merge: function (paramNameArg, objectArg) {
|
||||
if (!(typeof exports.obsItems[paramNameArg] === 'undefined')) {
|
||||
exports.obsItems[paramNameArg] = plugins.lodash.assign(exports.obsItems[paramNameArg], objectArg);
|
||||
}
|
||||
else {
|
||||
console.log('object is not present, so there is nothing to merge');
|
||||
}
|
||||
},
|
||||
get: function (keyName) {
|
||||
return exports.obsItems[keyName];
|
||||
},
|
||||
getAll: function () {
|
||||
return exports.obsItems;
|
||||
},
|
||||
addComplete: function (itemsArg) {
|
||||
exports.obsItems = plugins.lodash.assign(exports.obsItems, itemsArg);
|
||||
return exports.obsItems;
|
||||
}
|
||||
};
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYub2JqZWN0c3RvcmFnZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52Lm9iamVjdHN0b3JhZ2UudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSw4Q0FBOEM7QUFFbkMsUUFBQSxRQUFRLEdBQVEsRUFBRSxDQUFBO0FBRTdCOztHQUVHO0FBQ1EsUUFBQSxHQUFHLEdBQVE7SUFDcEIsR0FBRyxFQUFFLFVBQVUsWUFBWSxHQUFHLFdBQVcsRUFBRSxTQUFTLEdBQUcsV0FBVztRQUNoRSxFQUFFLENBQUMsQ0FBQyxZQUFZLEtBQUssV0FBVyxDQUFDLENBQUMsQ0FBQztZQUNqQyxPQUFPLENBQUMsR0FBRyxDQUFDLHdCQUF3QixDQUFDLENBQUE7WUFDckMsTUFBTSxDQUFBO1FBQ1IsQ0FBQztRQUNELEVBQUUsQ0FBQyxDQUFDLFNBQVMsS0FBSyxXQUFXLENBQUMsQ0FBQyxDQUFDO1lBQzlCLE9BQU8sQ0FBQyxHQUFHLENBQUMsd0JBQXdCLENBQUMsQ0FBQTtRQUN2QyxDQUFDO1FBQ0QsRUFBRSxDQUFDLENBQUMsT0FBTyxnQkFBUSxDQUF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UUFBUTtRQUM3QixnQkFBUSxHQUFHLE9BQU8sQ0FBQyxNQUFNLENBQUMsTUFBTSxDQUFDLGdCQUFRLEVBQUUsUUFBUSxDQUFDLENBQUE7UUFDcEQsTUFBTSxDQUFDLGdCQUFRLENBQUE7SUFDakIsQ0FBQztDQUNGLENBQUEifQ==
|
4
dist/smartenv.plugins.d.ts
vendored
4
dist/smartenv.plugins.d.ts
vendored
@ -1,4 +0,0 @@
|
||||
import 'typings-global';
|
||||
import * as smartq from 'smartq';
|
||||
import * as lodash from 'lodash';
|
||||
export { smartq, lodash };
|
8
dist/smartenv.plugins.js
vendored
8
dist/smartenv.plugins.js
vendored
@ -1,8 +0,0 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
require("typings-global");
|
||||
const smartq = require("smartq");
|
||||
exports.smartq = smartq;
|
||||
const lodash = require("lodash");
|
||||
exports.lodash = lodash;
|
||||
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoic21hcnRlbnYucGx1Z2lucy5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uL3RzL3NtYXJ0ZW52LnBsdWdpbnMudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6Ijs7QUFBQSwwQkFBdUI7QUFDdkIsaUNBQWdDO0FBSTVCLHdCQUFNO0FBSFYsaUNBQWdDO0FBSTVCLHdCQUFNIn0=
|
17
npmextra.json
Normal file
17
npmextra.json
Normal file
@ -0,0 +1,17 @@
|
||||
{
|
||||
"npmci": {
|
||||
"npmGlobalTools": [],
|
||||
"npmAccessLevel": "public"
|
||||
},
|
||||
"gitzone": {
|
||||
"projectType": "npm",
|
||||
"module": {
|
||||
"githost": "gitlab.com",
|
||||
"gitscope": "pushrocks",
|
||||
"gitrepo": "smartenv",
|
||||
"description": "store things about your environment and let them travel across modules",
|
||||
"npmPackagename": "@pushrocks/smartenv",
|
||||
"license": "MIT"
|
||||
}
|
||||
}
|
||||
}
|
@ -1,4 +0,0 @@
|
||||
{
|
||||
"mode":"default",
|
||||
"coverageTreshold":75
|
||||
}
|
18587
package-lock.json
generated
Normal file
18587
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load Diff
45
package.json
45
package.json
@ -1,11 +1,13 @@
|
||||
{
|
||||
"name": "smartenv",
|
||||
"version": "2.0.1",
|
||||
"name": "@pushrocks/smartenv",
|
||||
"version": "5.0.2",
|
||||
"description": "store things about your environment and let them travel across modules",
|
||||
"main": "dist/index.js",
|
||||
"typings": "dist/index.d.ts",
|
||||
"main": "dist_ts/index.js",
|
||||
"typings": "dist_ts/index.d.ts",
|
||||
"type": "module",
|
||||
"scripts": {
|
||||
"test": "(npmts)",
|
||||
"test": "(tstest test/ --web)",
|
||||
"build": "(tsbuild --web --allowimplicitany && tsbundle npm)",
|
||||
"testbrowser": "(npm test) && (node testbrowser.js)"
|
||||
},
|
||||
"repository": {
|
||||
@ -15,19 +17,38 @@
|
||||
"keywords": [
|
||||
"environment"
|
||||
],
|
||||
"author": "Smart Coordination GmbH <office@push.rocks> (https://push.rocks)",
|
||||
"author": "Lossless GmbH <hello@lossless.support> (https://lossless.com)",
|
||||
"license": "MIT",
|
||||
"bugs": {
|
||||
"url": "https://gitlab.com/pushrocks/smartenv/issues"
|
||||
},
|
||||
"homepage": "https://gitlab.com/pushrocks/smartenv",
|
||||
"dependencies": {
|
||||
"lodash": "^4.17.4",
|
||||
"smartq": "^1.1.1",
|
||||
"typings-global": "^1.0.14"
|
||||
"@pushrocks/smartpromise": "^3.1.7"
|
||||
},
|
||||
"devDependencies": {
|
||||
"beautylog": "^6.1.5",
|
||||
"tapbundle": "^1.0.5"
|
||||
}
|
||||
"@gitzone/tsbuild": "^2.1.56",
|
||||
"@gitzone/tsbundle": "^1.0.98",
|
||||
"@gitzone/tsrun": "^1.2.31",
|
||||
"@gitzone/tstest": "^1.0.68",
|
||||
"@pushrocks/tapbundle": "^5.0.2",
|
||||
"@types/npm": "^7.19.0",
|
||||
"@types/node": "^17.0.21"
|
||||
},
|
||||
"private": false,
|
||||
"files": [
|
||||
"ts/**/*",
|
||||
"ts_web/**/*",
|
||||
"dist/**/*",
|
||||
"dist_*/**/*",
|
||||
"dist_ts/**/*",
|
||||
"dist_ts_web/**/*",
|
||||
"assets/**/*",
|
||||
"cli.js",
|
||||
"npmextra.json",
|
||||
"readme.md"
|
||||
],
|
||||
"browserslist": [
|
||||
"last 1 chrome versions"
|
||||
]
|
||||
}
|
||||
|
39
readme.md
Normal file
39
readme.md
Normal file
@ -0,0 +1,39 @@
|
||||
# @pushrocks/smartenv
|
||||
store things about your environment and let them travel across modules
|
||||
|
||||
## Availabililty and Links
|
||||
* [npmjs.org (npm package)](https://www.npmjs.com/package/@pushrocks/smartenv)
|
||||
* [gitlab.com (source)](https://gitlab.com/pushrocks/smartenv)
|
||||
* [github.com (source mirror)](https://github.com/pushrocks/smartenv)
|
||||
* [docs (typedoc)](https://pushrocks.gitlab.io/smartenv/)
|
||||
|
||||
## Status for master
|
||||
|
||||
Status Category | Status Badge
|
||||
-- | --
|
||||
GitLab Pipelines | [](https://lossless.cloud)
|
||||
GitLab Pipline Test Coverage | [](https://lossless.cloud)
|
||||
npm | [](https://lossless.cloud)
|
||||
Snyk | [](https://lossless.cloud)
|
||||
TypeScript Support | [](https://lossless.cloud)
|
||||
node Support | [](https://nodejs.org/dist/latest-v10.x/docs/api/)
|
||||
Code Style | [](https://lossless.cloud)
|
||||
PackagePhobia (total standalone install weight) | [](https://lossless.cloud)
|
||||
PackagePhobia (package size on registry) | [](https://lossless.cloud)
|
||||
BundlePhobia (total size when bundled) | [](https://lossless.cloud)
|
||||
Platform support | [](https://lossless.cloud) [](https://lossless.cloud)
|
||||
|
||||
## Usage
|
||||
|
||||
Use TypeScript for best in class instellisense.
|
||||
|
||||
## Contribution
|
||||
|
||||
We are always happy for code contributions. If you are not the code contributing type that is ok. Still, maintaining Open Source repositories takes considerable time and thought. If you like the quality of what we do and our modules are useful to you we would appreciate a little monthly contribution: You can [contribute one time](https://lossless.link/contribute-onetime) or [contribute monthly](https://lossless.link/contribute). :)
|
||||
|
||||
For further information read the linked docs at the top of this readme.
|
||||
|
||||
> MIT licensed | **©** [Lossless GmbH](https://lossless.gmbh)
|
||||
| By using this npm module you agree to our [privacy policy](https://lossless.gmbH/privacy)
|
||||
|
||||
[](https://maintainedby.lossless.com)
|
52
test/test.ts
52
test/test.ts
@ -1,27 +1,37 @@
|
||||
import * as smartenv from '../dist/index.js'
|
||||
import * as beautylog from 'beautylog'
|
||||
import { tap, expect } from '@pushrocks/tapbundle';
|
||||
import * as smartenv from '../ts/index.js';
|
||||
|
||||
import { tap, expect } from 'tapbundle'
|
||||
let testEnv: smartenv.Smartenv;
|
||||
|
||||
smartenv.printEnv()
|
||||
tap.test('should print env', async () => {
|
||||
testEnv = new smartenv.Smartenv();
|
||||
});
|
||||
|
||||
// test smartenv.obs.add
|
||||
smartenv.obs.add('myTestObject',{key1:'Peter'})
|
||||
smartenv.obs.add('myTestObject',{key1:'Klaus'}) // now trying to add a second
|
||||
smartenv.printEnv()
|
||||
beautylog.log(smartenv.obs.get('myTestObject').key1) // this should be Peter
|
||||
tap.test('should print a overview to console', async () => {
|
||||
testEnv.printEnv();
|
||||
});
|
||||
|
||||
// test smartenv.obs.replace
|
||||
smartenv.obs.replace('myTestObject',{key1:'Klaus'})
|
||||
beautylog.log(smartenv.obs.get('myTestObject').key1) // this should be Klaus
|
||||
tap.test('should get os', async () => {
|
||||
const resultMac = await testEnv.isMacAsync();
|
||||
const resultLinux = await testEnv.isLinuxAsync();
|
||||
const resultWindows = await testEnv.isWindowsAsync();
|
||||
const osModule = await import('os');
|
||||
if (resultMac) {
|
||||
expect(osModule.platform()).toEqual('darwin');
|
||||
console.log('platform is Mac!');
|
||||
} else if (resultLinux) {
|
||||
expect(osModule.platform()).toEqual('linux');
|
||||
console.log('platform is Linux!');
|
||||
} else {
|
||||
expect(osModule.platform()).toEqual('win32');
|
||||
console.log('platform is Windows!');
|
||||
}
|
||||
});
|
||||
|
||||
// test smartenv.obs.merge
|
||||
smartenv.obs.merge('myTestObject',{key2:'Peter'})
|
||||
beautylog.log(smartenv.obs.get('myTestObject').key1 + smartenv.obs.get('myTestObject').key2)
|
||||
// this should be KlausPeter
|
||||
tap.test('should state wether we are in CI', async () => {
|
||||
if (process.env.CI) {
|
||||
expect(testEnv.isCI).toBeTrue();
|
||||
}
|
||||
});
|
||||
|
||||
let key2 = 'hello'
|
||||
smartenv.obs.get('myTestObject').key2 = key2
|
||||
beautylog.log(smartenv.obs.get('myTestObject').key2)
|
||||
|
||||
beautylog.success('Success!')
|
||||
tap.start();
|
||||
|
8
ts/00_commitinfo_data.ts
Normal file
8
ts/00_commitinfo_data.ts
Normal file
@ -0,0 +1,8 @@
|
||||
/**
|
||||
* autocreated commitinfo by @pushrocks/commitinfo
|
||||
*/
|
||||
export const commitinfo = {
|
||||
name: '@pushrocks/smartenv',
|
||||
version: '5.0.2',
|
||||
description: 'store things about your environment and let them travel across modules'
|
||||
}
|
11
ts/index.ts
11
ts/index.ts
@ -1,10 +1 @@
|
||||
|
||||
import {getEnv, printEnv} from './smartenv.environment'
|
||||
import { obs } from './smartenv.objectstorage'
|
||||
|
||||
|
||||
export {
|
||||
getEnv,
|
||||
printEnv,
|
||||
obs
|
||||
}
|
||||
export * from './smartenv.classes.smartenv.js';
|
||||
|
9
ts/interfaces/index.ts
Normal file
9
ts/interfaces/index.ts
Normal file
@ -0,0 +1,9 @@
|
||||
export let defaultme = null;
|
||||
declare global {
|
||||
namespace NodeJS {
|
||||
interface Global {
|
||||
window: any;
|
||||
navigator: any;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,52 +0,0 @@
|
||||
import * as plugins from './smartenv.plugins'
|
||||
export let getEnvString = function (): string {
|
||||
if (typeof window !== 'undefined') {
|
||||
return 'browser'
|
||||
} else if (typeof process !== 'undefined') {
|
||||
return 'node'
|
||||
}
|
||||
}
|
||||
|
||||
export let getUserAgentString = function (): string {
|
||||
if (isBrowser()) {
|
||||
return navigator.userAgent
|
||||
} else {
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
|
||||
export let isNode = function (): boolean {
|
||||
return getEnvString() === 'node'
|
||||
}
|
||||
|
||||
export let getNodeVersion = function (): string {
|
||||
return process.version
|
||||
}
|
||||
|
||||
export let isBrowser = function (): boolean {
|
||||
return !isNode()
|
||||
}
|
||||
|
||||
export let isCI = function () {
|
||||
if (process.env.CI) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
};
|
||||
}
|
||||
|
||||
export let isC9 = function () {
|
||||
if (process.env.C9_HOSTNAME) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
export let isTravis = function () {
|
||||
if (process.env.TRAVIS) {
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
};
|
||||
}
|
149
ts/smartenv.classes.smartenv.ts
Normal file
149
ts/smartenv.classes.smartenv.ts
Normal file
@ -0,0 +1,149 @@
|
||||
import * as plugins from './smartenv.plugins.js';
|
||||
import * as interfaces from './interfaces/index.js';
|
||||
|
||||
// interfaces
|
||||
export interface IEnvObject {
|
||||
name: string;
|
||||
value: string;
|
||||
}
|
||||
|
||||
/**
|
||||
* Smartenv class that makes it easy
|
||||
*/
|
||||
export class Smartenv {
|
||||
public async getEnvAwareModule(optionsArg: {
|
||||
nodeModuleName: string;
|
||||
webUrlArg: string;
|
||||
getFunction: () => any;
|
||||
}) {
|
||||
if (this.isNode) {
|
||||
const moduleResult = await this.getSafeNodeModule(optionsArg.nodeModuleName);
|
||||
return moduleResult;
|
||||
} else if (this.isBrowser) {
|
||||
const moduleResult = await this.getSafeWebModule(optionsArg.webUrlArg, optionsArg.getFunction);
|
||||
} else {
|
||||
console.error('platform for loading not supported by smartenv');
|
||||
}
|
||||
}
|
||||
|
||||
public async getSafeNodeModule<T = any>(moduleNameArg: string): Promise<T> {
|
||||
if (!this.isNode) {
|
||||
console.error('You tried to load a node module in a wrong context');
|
||||
return;
|
||||
}
|
||||
// tslint:disable-next-line: function-constructor
|
||||
return (new Function(`return import('${moduleNameArg}')`))() as Promise<T>;
|
||||
}
|
||||
|
||||
public loadedScripts: string[] = [];
|
||||
public async getSafeWebModule(urlArg: string, getFunctionArg: () => any) {
|
||||
if (!this.isBrowser) {
|
||||
console.error('You tried to load a web module in a wrong context');
|
||||
return;
|
||||
}
|
||||
|
||||
if (this.loadedScripts.includes(urlArg)) {
|
||||
return getFunctionArg();
|
||||
} else {
|
||||
this.loadedScripts.push(urlArg);
|
||||
}
|
||||
|
||||
const done = plugins.smartpromise.defer();
|
||||
if (globalThis.importScripts) {
|
||||
globalThis.importScripts(urlArg);
|
||||
done.resolve();
|
||||
} else {
|
||||
const script = document.createElement('script');
|
||||
script.onload = () => {
|
||||
done.resolve();
|
||||
};
|
||||
script.src = urlArg;
|
||||
document.head.appendChild(script);
|
||||
}
|
||||
await done.promise;
|
||||
return getFunctionArg();
|
||||
}
|
||||
|
||||
public get runtimeEnv() {
|
||||
if (typeof process !== 'undefined') {
|
||||
return 'node';
|
||||
} else {
|
||||
return 'browser';
|
||||
}
|
||||
}
|
||||
|
||||
public get isBrowser(): boolean {
|
||||
return !this.isNode;
|
||||
}
|
||||
|
||||
public get userAgent(): string {
|
||||
if (this.isBrowser) {
|
||||
// make sure we are in Browser
|
||||
return navigator.userAgent;
|
||||
} else {
|
||||
return 'undefined';
|
||||
}
|
||||
}
|
||||
|
||||
public get isNode(): boolean {
|
||||
return this.runtimeEnv === 'node';
|
||||
}
|
||||
|
||||
public get nodeVersion(): string {
|
||||
return process.version;
|
||||
}
|
||||
|
||||
public get isCI(): boolean {
|
||||
if (this.isNode) {
|
||||
if (process.env.CI) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isMacAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'darwin';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isWindowsAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'win32';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public async isLinuxAsync(): Promise<boolean> {
|
||||
if (this.isNode) {
|
||||
const os = await this.getSafeNodeModule('os');
|
||||
return os.platform() === 'linux';
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
public async printEnv() {
|
||||
if (this.isNode) {
|
||||
console.log('running on NODE');
|
||||
console.log(
|
||||
'node version is ' + this.nodeVersion
|
||||
);
|
||||
} else {
|
||||
console.log('running on BROWSER');
|
||||
console.log('browser is ' + this.userAgent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
import helpers = require('./smartenv.classes.helpers')
|
||||
|
||||
export class Environment {
|
||||
runtimeEnv: string
|
||||
isBrowser: boolean
|
||||
userAgent: string
|
||||
isNode: boolean
|
||||
nodeVersion: string
|
||||
isCI: boolean
|
||||
isTravis: boolean
|
||||
isC9: boolean
|
||||
constructor() {
|
||||
this.runtimeEnv = helpers.getEnvString()
|
||||
this.isBrowser = helpers.isBrowser()
|
||||
this.userAgent = helpers.getUserAgentString()
|
||||
this.isNode = helpers.isNode()
|
||||
this.nodeVersion = helpers.getNodeVersion()
|
||||
this.isCI = helpers.isCI()
|
||||
this.isTravis = helpers.isTravis()
|
||||
this.isC9 = helpers.isC9()
|
||||
};
|
||||
}
|
@ -1,38 +0,0 @@
|
||||
/**
|
||||
* Deals with the environment the current JS script is running in.
|
||||
*/
|
||||
import * as plugins from './smartenv.plugins'
|
||||
import * as classes from './smartenv.classes'
|
||||
import * as objectStorage from './smartenv.objectstorage'
|
||||
|
||||
|
||||
let environment: classes.Environment
|
||||
let envDetermined: boolean = false
|
||||
|
||||
/**
|
||||
* returns the environment
|
||||
* @returns {Environment}
|
||||
*/
|
||||
export var getEnv = function(){
|
||||
if (!envDetermined) {
|
||||
environment = new classes.Environment()
|
||||
envDetermined = true // ensure code above only runs once
|
||||
};
|
||||
return environment
|
||||
}
|
||||
|
||||
/**
|
||||
* prints the environment to console
|
||||
*/
|
||||
export var printEnv = function() {
|
||||
if (this.getEnv().isNode) {
|
||||
console.log('running on NODE')
|
||||
let smartenvVersion = require('../package.json').version
|
||||
console.log('node version is ' + this.getEnv().nodeVersion + ' and smartenv version is ' + smartenvVersion)
|
||||
} else {
|
||||
console.log('running on BROWSER')
|
||||
console.log('browser is ' + this.getEnv().userAgent)
|
||||
}
|
||||
console.log('the smartenv registration store currently holds the following properties:')
|
||||
console.log(Object.getOwnPropertyNames(objectStorage.obs.getAll()))
|
||||
}
|
@ -1,44 +0,0 @@
|
||||
import plugins = require('./smartenv.plugins')
|
||||
|
||||
export let obsItems: any = {}
|
||||
|
||||
/**
|
||||
* Objectstorage allows easy sharing of objects within node
|
||||
*/
|
||||
export let obs: any = {
|
||||
add: function (paramNameArg = 'undefined', objectArg = 'undefined') {
|
||||
if (paramNameArg === 'undefined') {
|
||||
console.log('paramName is undefined')
|
||||
return
|
||||
}
|
||||
if (objectArg === 'undefined') {
|
||||
console.log('objectArg is undefined')
|
||||
}
|
||||
if (typeof obsItems[ paramNameArg ] === 'undefined') {
|
||||
obsItems[ paramNameArg ] = objectArg
|
||||
} else {
|
||||
console.log('object is already present, so add operation has failed.')
|
||||
}
|
||||
return obsItems[ paramNameArg ]
|
||||
},
|
||||
replace: function (paramNameArg, objectArg) {
|
||||
obsItems[ paramNameArg ] = objectArg
|
||||
},
|
||||
merge: function (paramNameArg, objectArg) {
|
||||
if (!(typeof obsItems[ paramNameArg ] === 'undefined')) {
|
||||
obsItems[ paramNameArg ] = plugins.lodash.assign(obsItems[ paramNameArg ], objectArg)
|
||||
} else {
|
||||
console.log('object is not present, so there is nothing to merge')
|
||||
}
|
||||
},
|
||||
get: function (keyName) {
|
||||
return obsItems[ keyName ]
|
||||
},
|
||||
getAll: function () {
|
||||
return obsItems
|
||||
},
|
||||
addComplete: function (itemsArg) {
|
||||
obsItems = plugins.lodash.assign(obsItems, itemsArg)
|
||||
return obsItems
|
||||
}
|
||||
}
|
@ -1,8 +1,3 @@
|
||||
import 'typings-global'
|
||||
import * as smartq from 'smartq'
|
||||
import * as lodash from 'lodash'
|
||||
import * as smartpromise from '@pushrocks/smartpromise';
|
||||
|
||||
export {
|
||||
smartq,
|
||||
lodash
|
||||
}
|
||||
export { smartpromise };
|
||||
|
9
tsconfig.json
Normal file
9
tsconfig.json
Normal file
@ -0,0 +1,9 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"useDefineForClassFields": false,
|
||||
"target": "ES2022",
|
||||
"module": "ES2022",
|
||||
"moduleResolution": "nodenext"
|
||||
}
|
||||
}
|
@ -1,3 +0,0 @@
|
||||
{
|
||||
"extends": "tslint-config-standard"
|
||||
}
|
Reference in New Issue
Block a user