Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/runk/dtrim

A tool for trimming deep/lenghty javascript data structures
https://github.com/runk/dtrim

hacktoberfest

Last synced: 3 months ago
JSON representation

A tool for trimming deep/lenghty javascript data structures

Awesome Lists containing this project

README

        

# dtrim ![Status](https://github.com/runk/dtrim/actions/workflows/release.yml/badge.svg)

_dtrim_ is a tool for trimming deep/lengthy javascript structures. Some potential usages are: debugging, logging or data sanitization. Fully configurable.

Caters for:

- Big arrays
- Objects with lots of keys
- Nested, deep structures
- Objects with circular references
- Long strings
- Buffers
- Functions

#### Installation

```shell
npm i dtrim
```

#### Usage

```typescript
import * as dtrim from 'dtrim'

const trim = dtrim.trimmer({ depth: 4 });
const nasty = { ... a big, deep and nasty object here ... };
const nice = trim(nasty);
```

#### Options

_dtrim.trimmer([options])_

- `options`: ``

- `depth`: `` Trim depth - all structures deeper than this will be omitted from output. This is useful for truncating large complicated objects. To make it return full structure, pass `Infinity` or some arbitrary large number. _Default_: `4`.
- `size`: `` Trim size - all objects and arrays that are longer/bigger than specified size will be trimmed. Note on trimming objects: because order of properties is not guaranteed by javascript spec, objects with number of properties bigger than _size_ will be represented as string `"Object(N)"`. To make it return full structure, pass `Infinity` or some arbitrary large number. _Default_: `64`.
- `string`: `` Trim strings that are longer than specified number. To make it return full structure, pass `Infinity` or some arbitrary large number. _Default_: `512`.
- `buffer`: `` Substitues instances of a `Buffer` object with their string representation: `"Buffer(N)"`. _Default_: `true`.
- `getters`: `` Omits getter fields in objects and classes from the result. _Default_: `true`.
- `retain`: `>` A set of root paths to ignore while at depth 0. For example trimming `{a: FooClass}` with `new Set(['a'])` will result in `{a: FooClass}` instead of `{a: {}}`. _Default_: `new Set()`

- Returns: `` - trimmer function that accepts input argument of any type.

#### License

MIT