Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
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
- Host: GitHub
- URL: https://github.com/runk/dtrim
- Owner: runk
- License: mit
- Created: 2018-12-28T21:57:58.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2024-08-01T07:18:48.000Z (5 months ago)
- Last Synced: 2024-08-02T04:15:00.610Z (5 months ago)
- Topics: hacktoberfest
- Language: TypeScript
- Homepage:
- Size: 1.02 MB
- Stars: 1
- Watchers: 3
- Forks: 2
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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