Ecosyste.ms: Awesome

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

Awesome Lists | Featured Topics | Projects

https://github.com/plantain-00/remove-default

A library to remove from objects properties that match default values to minimize storage or payload.
https://github.com/plantain-00/remove-default

Last synced: 12 days ago
JSON representation

A library to remove from objects properties that match default values to minimize storage or payload.

Awesome Lists containing this project

README

        

# remove-default

A library to remove from objects properties that match default values to minimize storage or payload.

[![Dependency Status](https://david-dm.org/plantain-00/remove-default.svg)](https://david-dm.org/plantain-00/remove-default)
[![devDependency Status](https://david-dm.org/plantain-00/remove-default/dev-status.svg)](https://david-dm.org/plantain-00/remove-default#info=devDependencies)
[![Build Status: Windows](https://ci.appveyor.com/api/projects/status/github/plantain-00/remove-default?branch=master&svg=true)](https://ci.appveyor.com/project/plantain-00/remove-default/branch/master)
![Github CI](https://github.com/plantain-00/remove-default/workflows/Github%20CI/badge.svg)
[![npm version](https://badge.fury.io/js/remove-default.svg)](https://badge.fury.io/js/remove-default)
[![Downloads](https://img.shields.io/npm/dm/remove-default.svg)](https://www.npmjs.com/package/remove-default)
[![gzip size](https://img.badgesize.io/https://unpkg.com/remove-default?compression=gzip)](https://unpkg.com/remove-default)
[![type-coverage](https://img.shields.io/badge/dynamic/json.svg?label=type-coverage&prefix=%E2%89%A5&suffix=%&query=$.typeCoverage.atLeast&uri=https%3A%2F%2Fraw.githubusercontent.com%2Fplantain-00%2Fremove-default%2Fmaster%2Fpackage.json)](https://github.com/plantain-00/remove-default)

## install

`yarn add remove-default`

## usage

```ts
import { removeDefault } from "remove-default";
//

const schema = {
type: 'object',
properties: {
padding: {
type: 'object',
properties: {
left: {
type: 'number',
default: 0
},
right: {
type: 'number',
default: 0
},
top: {
type: 'number',
default: 0
},
bottom: {
type: 'number',
default: 0
}
},
default: {}
}
}
}
expect(removeDefault({
padding: {
left: 0,
right: 10,
top: 0,
bottom: 0,
}
}, schema)).toEqual({
padding: {
right: 10
}
})

expect(removeDefault({
padding: {
left: 0,
right: 0,
top: 0,
bottom: 0,
}
}, schema)).toEqual({})
```