rescript-clean-deep

2.0.0 • Public • Published

rescript-clean-deep

NPM version Build Status

ReScript bindings for clean-deep, a library for removing empty or nullable values from javascript objects.

Getting started

yarn add rescript-clean-deep

Then add rescript-clean-deep as a dependency to bsconfig.json:

"bs-dependencies": [
+  "rescript-clean-deep"
]

Example

open RescriptCleanDeep;

let jsObject = [%bs.raw {|
{
  bar: {},
  baz: null,
  biz: 'baz',
  foo: '',
  net: [],
  nit: undefined,
  qux: {
    baz: 'boz',
    txi: ''
  }
}
|}];

let cleaned = CleanDeep.cleanDeep(jsObject, ());

Js.log(cleaned);
/* => { biz: 'baz', qux: { baz: 'boz' } } */

let cleanedKeepStrings = jsObject->CleanDeep.cleanDeep(~emptyStrings=false, ());

Js.log(cleanedKeepStrings);
/* => { biz: 'baz', foo: '', qux: { baz: 'boz', txi: '' } } */

let cleanedCustomValues = jsObject->CleanDeep.cleanDeep(~cleanValues=[|"baz"|], ());

Js.log(cleanedCustomValues);
/* => { qux: { baz: 'boz' } } */

See also example-project.

Contribute

If you find bugs or there are updates in clean-deep, feel free to open an issue or PR. If you are upgrading any dependencies, please use yarn so yarn.lock is updated.

Readme

Keywords

Package Sidebar

Install

npm i rescript-clean-deep

Weekly Downloads

14

Version

2.0.0

License

MIT

Unpacked Size

15.3 kB

Total Files

14

Last publish

Collaborators

  • mikaello