node-dev-console
Advanced tools
Comparing version 1.1.0 to 1.2.0
76
index.js
@@ -21,7 +21,23 @@ | ||
/** | ||
* Activates console output | ||
* @returns {boolean} always returns true | ||
*/ | ||
const activate = () => DC_ON = true; // process.env.DEV_CONSOLE_ON = 1; | ||
/** | ||
* Deactivates console output | ||
* @returns {boolean} always returns false | ||
*/ | ||
const deactivate = () => DC_ON = false; //process.env.DEV_CONSOLE_ON = false; | ||
/** | ||
* @returns {boolean} true, if output is set to true and FORCE_OFF is false | ||
*/ | ||
const isOn = () => DC_ON && !FORCE_OFF; //process.env.DEV_CONSOLE_ON; // Boolean(process.env.DEV_CONSOLE_ON ); | ||
/** | ||
* Alias for console.log, if output is enabled | ||
* @param {any} args | ||
* @returns {void} | ||
*/ | ||
const l = (...args) => { | ||
@@ -32,5 +48,22 @@ if (isOn()) { | ||
}; | ||
/** | ||
* console.log's a message, if output is "on" | ||
* @returns {void} | ||
*/ | ||
const showMessageIsOn = () => l("DEV CONSOLE is ON"); | ||
/** | ||
* JSON.stringify with two spaces | ||
* @param v {any} | ||
* @returns {string} | ||
*/ | ||
const stringify = v => JSON.stringify(v, null, 2); | ||
/** | ||
* Shows content of variable (JSON.stringify), with optional name and log prefix | ||
* @param {any} d any kind of variable | ||
* @param {string | false} [name] name of the object | ||
* @param {string} [LP] Log prefix | ||
*/ | ||
const j = (d, name = false, LP = '') => | ||
@@ -41,2 +74,9 @@ name === false | ||
; | ||
/** | ||
* Shows type of variable, with optional name and log prefix | ||
* @param {any} d any kind of variable | ||
* @param {string | false} [name] name of the object | ||
* @param {string} [LP] Log prefix | ||
*/ | ||
const t = (d, name = false, LP = '') => | ||
@@ -48,3 +88,15 @@ name === false | ||
/** | ||
* Inner function of r. Returns passed variable | ||
* @typedef {(d: any) => any} rReturnFunction | ||
*/ | ||
/** | ||
* Re-usable function (ramda currying), basically doing the same as l. | ||
* Define name and log prefix first, and use resulting function to output | ||
* current variable. | ||
* @param {string} [name] name of the object | ||
* @param {string} [LP] Log prefix | ||
* @returns {rReturnFunction} | ||
*/ | ||
const r = (name = "", LP = '') => d => { | ||
@@ -55,6 +107,30 @@ l(LP + String(name), stringify(d)); | ||
/** | ||
* Alias for r("STAGE1:") | ||
* @type {rReturnFunction} | ||
*/ | ||
const r1 = r("STAGE1:"); | ||
/** | ||
* Alias for r("STAGE2:") | ||
* @type {rReturnFunction} | ||
*/ | ||
const r2 = r("STAGE2:"); | ||
/** | ||
* Alias for r("STAGE3:") | ||
* @type {rReturnFunction} | ||
*/ | ||
const r3 = r("STAGE3:"); | ||
/** | ||
* Alias for r("STAGE4:") | ||
* @type {rReturnFunction} | ||
*/ | ||
const r4 = r("STAGE4:"); | ||
/** | ||
* Alias for r("STAGE5:") | ||
* @type {rReturnFunction} | ||
*/ | ||
const r5 = r("STAGE5:"); | ||
@@ -61,0 +137,0 @@ // TODO add more |
{ | ||
"name": "node-dev-console", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "dev helper", | ||
"main": "index.js", | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Florian77/node-dev-console.git" | ||
}, | ||
"author": "Florian Tölle", | ||
"type": "commonjs", | ||
"exports": "./index.js", | ||
"scripts": { | ||
@@ -10,10 +16,19 @@ "test": "set CONSOLE_LOG_OFF=1&& npx mocha --ui bdd ./**/*.test.js", | ||
"prepublishOnly": "npm test", | ||
"publish-package": "npm publish" | ||
"publish-package": "npm publish", | ||
"generate-.d.ts-file": "tsc --declaration index.js --allowJs --emitDeclarationOnly", | ||
"generate-readme-api-documentation": "npm run generate-.d.ts-file && ts-readme-generator" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/Florian77/node-dev-console.git" | ||
"files": [ | ||
"index.js", | ||
"index.d.ts" | ||
], | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^7.1.1", | ||
"ts-readme-generator": "^0.7.2", | ||
"typescript": "^4.8.2" | ||
}, | ||
"main": "index.js", | ||
"types": "types.d.ts", | ||
"keywords": [], | ||
"author": "Florian Tölle", | ||
"license": "MIT", | ||
@@ -23,8 +38,3 @@ "bugs": { | ||
}, | ||
"homepage": "https://github.com/Florian77/node-dev-console#readme", | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"chai": "^4.2.0", | ||
"mocha": "^7.1.1" | ||
} | ||
"homepage": "https://github.com/Florian77/node-dev-console#readme" | ||
} |
105
README.md
# node-dev-console | ||
## API | ||
### `activate()` | ||
- returns `boolean` - always returns true | ||
Activates console output | ||
### `deactivate()` | ||
- returns `boolean` - always returns false | ||
Deactivates console output | ||
### `isOn()` | ||
- returns `boolean` - true, if output is set to true and FORCE_OFF is false | ||
### `l(args)` | ||
- `args` (`any`, required) | ||
Alias for console.log, if output is enabled | ||
### `j(d[, name[, LP]])` | ||
- `d` (`any`, required) - any kind of variable | ||
- `name` (`string | `, optional) - name of the object | ||
- `LP` (`string`, optional) - Log prefix | ||
Shows content of variable (JSON.stringify), with optional name and log prefix | ||
### `t(d[, name[, LP]])` | ||
- `d` (`any`, required) - any kind of variable | ||
- `name` (`string | `, optional) - name of the object | ||
- `LP` (`string`, optional) - Log prefix | ||
Shows type of variable, with optional name and log prefix | ||
### `r([name[, LP]])` | ||
- `name` (`string`, optional) - name of the object | ||
- `LP` (`string`, optional) - Log prefix | ||
- returns `rReturnFunction` - undefined | ||
Inner function of r. Returns passed variable | ||
### `or(DEV, LIVE)` | ||
- `DEV` (`any`, required) | ||
- `LIVE` (`any`, required) | ||
- returns `any` | ||
### `isDEV()` | ||
- returns `boolean` | ||
### `isLIVE()` | ||
- returns `boolean` | ||
### `stringify(v)` | ||
- `v` (`any`, required) | ||
- returns `string` - undefined | ||
JSON.stringify with two spaces | ||
### `showMessageIsOn()` | ||
console.log's a message, if output is "on" | ||
### `reEvaluateEnv()` | ||
### `r1` | ||
- type: `rReturnFunction` | ||
Alias for r("STAGE1:") | ||
### `r2` | ||
- type: `rReturnFunction` | ||
Alias for r("STAGE2:") | ||
### `r3` | ||
- type: `rReturnFunction` | ||
Alias for r("STAGE3:") | ||
### `r4` | ||
- type: `rReturnFunction` | ||
Alias for r("STAGE4:") | ||
### `r5` | ||
- type: `rReturnFunction` | ||
Alias for r("STAGE5:") |
9412
4
230
107
4