avmaisak / ts-trim-object

Ultra small library which removes empty fields from the object

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

ts-trim-object

Small library which removes empty data from the object.

Usage

1. Install the package

npm i ts-trim-object --save

2. Import module

import 'ts-trim-object';

3. Define yor object

const myObject1 = { property: 'MyProperty', blankProperty:'', array: [] };
const myObject2 = { property: '      ' };
const myObject3 = { property: 'MyProperty',  array: [{ prop: 'PropText', prop2: ''}] };

// remove empty properties
const result1 = myObject1.trimProps();
const result2 = myObject2.trimProps();
const result3 = myObject3.trimProps();

result1 will be

{ property: 'MyProperty' }

result2 will be

{ }

result3 will be

{ property: 'MyProperty', array: [{ prop: 'PropText' }] }

About

Ultra small library which removes empty fields from the object

License:MIT License


Languages

Language:TypeScript 100.0%