Skip to content

Commit

Permalink
➕ Added shortcuts consonoJSON.
Browse files Browse the repository at this point in the history
✅️ Update ES modules definition.
⬆️ Dev dependencies updated.
  • Loading branch information
r37r0m0d3l committed Mar 25, 2021
1 parent af789c9 commit ec9f994
Show file tree
Hide file tree
Showing 19 changed files with 229 additions and 32 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

---

## 1.4.11

- ➕ Added shortcuts `consonoJSON`.

- ✅️ Update ES modules definition.

- ⬆️ Dev dependencies updated.

## 1.4.10

- ⬇️ Fixed exception with frozen object
Expand Down
2 changes: 1 addition & 1 deletion dist/consono.browser.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.browser.mjs.map

Large diffs are not rendered by default.

98 changes: 98 additions & 0 deletions dist/consono.d.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,109 @@
/**
* @typedef IConsonoOptions
* @type {object}
* @property {number} [arrayMaxElements=99] Maximum number of elements in array to show.
* @property {string} [assignSymbol='→'] Assign symbol.
* @property {boolean} [clear=false] Clear console before output.
* @property {boolean} [colorize=true] Colorize the output.
* @property {boolean} [console=true] Output to console.
* @property {number} [depth=20] Default depth of object.
* @property {boolean|number} [exit=false] Number greater than zero - exit status with passed error code. 'false' - do nothing. 'true' - exit status ok.
* @property {boolean} [immediate=false] Call console.log immediately.
* @property {string} [indent='ˑˑ'] Print indentation.
* @property {number} [mapMaxEntries=99] Maximum number of entries in map to show.
* @property {number} [objectMaxProps=99] Maximum number of properties in object to show.
* @property {string} [quotesEnd='"'] Quote end.
* @property {string} [quotesStart='"'] Quote start.
* @property {boolean} [returns=true] Return inspected variable as string.
* @property {number} [setMaxValues=99] Maximum number of values in set to show.
* @property {boolean} [stdout=false] Call `process.stdout.write` instead of `console.log`.
* @property {number} [stringMaxLength=360] Maximum length of string to show.
*/
export interface IConsonoOptions {
/**
* @description Maximum number of elements in array to show.
* @default 99
*/
arrayMaxElements?: number;
/**
* @description Assign symbol.
* @default "→"
*/
assignSymbol?: string;
/**
* @description Clear console before output.
* @default false
*/
clear?: boolean;
/**
* @description Colorize the output.
* @default true
*/
colorize?: boolean;
/**
* @description Output to console.
* @default true
*/
console?: boolean;
/**
* @description Default depth of object.
* @default 20
*/
depth?: number;
/**
* @description Number greater than zero - exit status with passed error code. 'false' - do nothing. 'true' - exit status ok.
* @default false
*/
exit?: boolean | number;
/**
* @description Call console.log immediately.
* @default false
*/
immediate?: boolean;
/**
* @description Print indentation.
* @default "ˑˑ"
*/
indent?: string;
/**
* @description Maximum number of entries in map to show.
* @default 99
*/
mapMaxEntries?: number;
/**
* @description Maximum number of properties in object to show.
* @default 99
*/
objectMaxProps?: number;
/**
* @description Quote end.
* @default `"`
*/
quotesEnd?: string;
/**
* @description Quote start.
* @default `"`
*/
quotesStart?: string;
/**
* @description Return inspected variable as string.
* @default true
*/
returns?: boolean;
/**
* @description Maximum number of values in set to show.
* @default 99
*/
setMaxValues?: number;
/**
* @description Call `process.stdout.write` instead of `console.log`.
* @default false
*/
stdout?: boolean;
/**
* @description Maximum length of string to show.
* @default 360
*/
stringMaxLength?: number;
}

Expand Down Expand Up @@ -62,6 +151,15 @@ export declare function consonoExit(
exitCode?: boolean | number,
): string | void;

/**
* @name consonoJSON
* @description Print variable as JSON without highlighting
* @param {*} variable
* @param {boolean|Object} [options=true]
* @returns {string|undefined}
*/
export declare function consonoJSON(variable: any, options?: boolean | IConsonoOptions): string | void;

/**
* @name consonoPlain
* @description Print variable without highlighting
Expand Down
2 changes: 1 addition & 1 deletion dist/consono.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.cjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.cjs.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.mjs

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/consono.node.mjs.map

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -303,19 +303,19 @@ yarn add consono
The default is a function for printing variable.

```javascript
const { consono } = require("consono");
import { consono } from "consono";
```

Require multiple items: function, constructor, options object, theme objects.

```javascript
const {
import {
Consono,
consono,
options,
THEME_DARK,
THEME_LIGHT,
} = require("consono");
} from "consono";
```

Import as ECMAScript module.
Expand All @@ -335,7 +335,7 @@ UNPKG CDN.
## ⚙️ Options

```javascript
const { Consono } = require("consono");
import { Consono } from "consono";
const options = {
clear: true,
quotesEnd: ``,
Expand All @@ -350,7 +350,7 @@ consono.log("Cleared before output. Different quotes. And cut to 54!");
```

```javascript
const { Consono } = require("consono");
import { Consono } from "consono";
const theme = {
argument: [253, 151, 31],
boolean: [174, 129, 255],
Expand All @@ -367,14 +367,14 @@ consono.log("Themed");
```

```javascript
const { Consono, options } = require("consono");
import { Consono, options } from "consono";
options.colorize = false;
const consono = new Consono(options);
consono.log("Text without colorization");
```

```javascript
const { consono } = require("consono");
import { consono } from "consono";
console.debug(
consono("Outputs a message only at the debug log level.", false)
);
Expand All @@ -390,7 +390,7 @@ consono("This is log function with your own options");
## 🔖 Log function

```javascript
const { consono } = require("consono");
import { consono } from "consono";
const map = new Map();
map.add("key", true);
consono(map);
Expand Down Expand Up @@ -453,6 +453,7 @@ consono("Some variable", defaultOptions);

```javascript
consonoExit("Some value", null, null, 15); // Exit code - 15
consonoJSON("Some value"); // No colorization, no description, only printing
consonoPlain("Some value"); // No colorization
consonoReturn("Some value"); // Return only, no `console.log`
```
Expand Down
2 changes: 1 addition & 1 deletion docs/manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -48,5 +48,5 @@
"keyword": "npm"
},
"short_name": "Consono",
"version": "1.0.201217"
"version": "1.0.210325"
}
22 changes: 11 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,17 @@
},
"description": "The most correct, informative, appealing and configurable variable inspector for JavaScript",
"devDependencies": {
"@babel/core": "7.12.10",
"@babel/plugin-proposal-class-properties": "7.12.1",
"@babel/plugin-proposal-private-methods": "7.12.1",
"@babel/preset-env": "7.12.11",
"@rollup/plugin-commonjs": "17.0.0",
"@rollup/plugin-node-resolve": "11.0.1",
"@babel/core": "7.13.10",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/plugin-proposal-private-methods": "7.13.0",
"@babel/preset-env": "7.13.12",
"@rollup/plugin-commonjs": "17.1.0",
"@rollup/plugin-node-resolve": "11.2.0",
"babel-core": "7.0.0-bridge.0",
"babel-eslint": "10.1.0",
"eslint": "7.17.0",
"eslint-config-prettier": "7.1.0",
"eslint-plugin-prettier": "3.3.0",
"eslint": "7.22.0",
"eslint-config-prettier": "8.1.0",
"eslint-plugin-prettier": "3.3.1",
"jest": "26.6.3",
"npm-check": "5.9.2",
"prettier": "2.2.1",
Expand All @@ -33,7 +33,7 @@
"remark-preset-lint-consistent": "4.0.0",
"remark-preset-lint-markdown-style-guide": "4.0.0",
"remark-preset-lint-recommended": "5.0.0",
"rollup": "2.35.1",
"rollup": "2.42.4",
"rollup-plugin-auto-external": "2.0.0",
"rollup-plugin-babel": "4.4.0",
"rollup-plugin-terser": "7.0.2"
Expand Down Expand Up @@ -105,5 +105,5 @@
},
"type": "module",
"types": "./dist/consono.d.ts",
"version": "1.4.10"
"version": "1.4.11"
}
44 changes: 44 additions & 0 deletions src/helpers/browser/consonoJSON.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Consono from "../../core/browser/consono.js";
import cliExit from "../../utils/cliExit.js";
import processExit from "../../utils/processExit.js";

/**
* @name consonoJSON
* @description Print variable as JSON without highlighting
* @param {*} variable
* @param {boolean|Object} [options=true]
* @returns {string|undefined}
*/
export default function consonoJSON(variable, options = true) {
let out;
if (variable === undefined) {
out = undefined;
} else {
out = JSON.parse(JSON.stringify(variable), null, 2);
}
const createdOptions = Consono.createOptions({ ...options, colorize: false });
if (createdOptions.console) {
if (createdOptions.clear) {
cliExit();
}
if (createdOptions.immediate) {
setTimeout(() => {
if (out === undefined) {
console.dir(undefined);
} else {
console.dir(out);
}
}, 0);
} else {
if (out === undefined) {
console.dir(undefined);
} else {
console.dir(out);
}
}
processExit(createdOptions.exit);
}
if (createdOptions.returns) {
return out;
}
}
44 changes: 44 additions & 0 deletions src/helpers/node/consonoJSON.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
import Consono from "../../core/browser/consono.js";
import cliExit from "../../utils/cliExit.js";
import processExit from "../../utils/processExit.js";

/**
* @name consonoJSON
* @description Print variable as JSON without highlighting
* @param {*} variable
* @param {boolean|Object} [options=true]
* @returns {string|undefined}
*/
export default function consonoJSON(variable, options) {
let out;
if (variable === undefined) {
out = undefined;
} else {
out = JSON.parse(JSON.stringify(variable), null, 2);
}
const createdOptions = Consono.createOptions({ ...options, colorize: false });
if (createdOptions.console) {
if (createdOptions.clear) {
cliExit();
}
if (createdOptions.immediate) {
setTimeout(() => {
if (out === undefined) {
console.dir(undefined);
} else {
console.dir(out);
}
}, 0);
} else {
if (out === undefined) {
console.dir(undefined);
} else {
console.dir(out);
}
}
processExit(createdOptions.exit);
}
if (createdOptions.returns) {
return out;
}
}
3 changes: 2 additions & 1 deletion src/index.browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import THEME_DARK from "./const/theme_dark.js";
import THEME_LIGHT from "./const/theme_light.js";
import consono from "./helpers/browser/consono.js";
import consonoExit from "./helpers/browser/consonoExit.js";
import consonoJSON from "./helpers/browser/consonoJSON.js";
import consonoPlain from "./helpers/browser/consonoPlain.js";
import consonoReturn from "./helpers/browser/consonoReturn.js";
import options from "./const/options_default.js";

export { Consono, THEME_DARK, THEME_LIGHT, consono, consonoExit, consonoPlain, consonoReturn, options };
export { Consono, THEME_DARK, THEME_LIGHT, consono, consonoExit, consonoJSON, consonoPlain, consonoReturn, options };
3 changes: 2 additions & 1 deletion src/index.node.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import THEME_DARK from "./const/theme_dark.js";
import THEME_LIGHT from "./const/theme_light.js";
import consono from "./helpers/node/consono.js";
import consonoExit from "./helpers/node/consonoExit.js";
import consonoJSON from "./helpers/node/consonoJSON.js";
import consonoPlain from "./helpers/node/consonoPlain.js";
import consonoReturn from "./helpers/node/consonoReturn.js";
import options from "./const/options_default.js";

export { Consono, THEME_DARK, THEME_LIGHT, consono, consonoExit, consonoPlain, consonoReturn, options };
export { Consono, THEME_DARK, THEME_LIGHT, consono, consonoExit, consonoJSON, consonoPlain, consonoReturn, options };

0 comments on commit ec9f994

Please sign in to comment.