https://github.com/rahul3883/utils
Node.js development utilities
https://github.com/rahul3883/utils
debug development json log nodejs npm-package pretty print
Last synced: 5 months ago
JSON representation
Node.js development utilities
- Host: GitHub
- URL: https://github.com/rahul3883/utils
- Owner: rahul3883
- License: mit
- Created: 2020-05-09T20:24:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-12-03T16:06:23.000Z (over 1 year ago)
- Last Synced: 2025-09-30T00:59:48.070Z (9 months ago)
- Topics: debug, development, json, log, nodejs, npm-package, pretty, print
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Node.js Utilities
Node.js development utilities for printing data to terminal.
## Install
```shell script
npm install @rahul1711/utils
```
## Usage
### Load the package
```javascript
const utils = require('@rahul1711/utils');
```
### Configure
Configure the global options.
```javascript
utils.configure([options]);
```
- [options (1)](#get-a-line)
- [options (2)](#get-a-json-string)
- [options (3)](#get-a-string)
### Get a line
Create a line using the character provided.
```javascript
utils.getLine([options]);
```
- `options`: `` These options override the same options provided in [`utils.configure`](#configure)
- `char`: `` A character to use for printing the line. **Default**: `-`
- `len`: `` Length of the line. **Default**: `67`
### Print a line
Print a line returned from [`utils.getLine`](#get-a-line).
```javascript
utils.line([options]);
```
- [options](#get-a-line)
### Get a string
Format the object using the built in [`util.inspect`](https://nodejs.org/api/util.html#util_util_inspect_object_options) method.
```javascript
utils.getString(obj[, option]);
```
- [options](https://nodejs.org/api/util.html#util_util_inspect_object_options)
(override options of the built in `util.inspect` method)
### Log
Print a string returned from [`utils.getString`](#get-a-string).
```javascript
utils.log(obj[, options]);
```
- [options](#get-a-string)
### Log with lines
Wrap [`utils.log`](#log) with lines.
[`utils.line`](#print-a-line) is used to print the lines.
```javascript
utils.logC(obj[, options]);
```
- [options (1)](#print-a-line)
- [options (2)](#get-a-string)
### Get a JSON string
Format the object using the built in [`JSON.stringify`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) method.
```javascript
utils.getJsonString(obj[, options]);
```
- `options`: `` These options override the same options provided in [`utils.configure`](#configure)
- `replacer`: `` A map function for object properties. [**Default**](https://github.com/rahul3883/utils/blob/master/index.js#L12)
- `indent`: ` | ` A string or number used to add whitespace in the returned string. **Default**:`4`
- `removeQuotes`: `` Remove quotes from the keys. **Default**:`true`
- `singleLineArray`: `` Print an array in a single line. **Default**:`true`
### Log using JSON method
Print a string returned from [`utils.getJsonString`](#get-a-json-string).
```javascript
utils.json(obj[, options]);
```
- [options](#get-a-json-string)
### Log with lines using JSON method
Wrap [`utils.json`](#log-using-json-method) with lines.
[`utils.line`](#print-a-line) is used to print the lines.
```javascript
utils.jsonC(obj[, options]);
```
- [options (1)](#print-a-line)
- [options (2)](#get-a-json-string)
## Samples
Sample files can be found in [`/samples`](https://github.com/rahul3883/utils/tree/master/samples) directory.
## Notes
- Options passed in [`utils.configure`](#configure) are global, and will be used
whenever options are not passed to any methods.
- Passing options to any method other than [`utils.configure`](#configure) will
be valid for that function call only.