UNPKG

bit-bin

Version:

<a href="https://opensource.org/licenses/Apache-2.0"><img alt="apache" src="https://img.shields.io/badge/License-Apache%202.0-blue.svg"></a> <a href="https://github.com/teambit/bit/blob/master/CONTRIBUTING.md"><img alt="prs" src="https://img.shields.io/b

38 lines (32 loc) 803 B
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = clean; function _foreach() { const data = _interopRequireDefault(require("./object/foreach")); _foreach = function () { return data; }; return data; } /** * Cleans all object's properties that contains a falsy value * and returns a new object without them. * @name clean * @param {object} obj object to clean * @returns {object} * @example new cleaned object * ```js * clean({ foo: null, bar: 'foo' }) // => { bar: 'foo' } * ``` */ function clean(obj) { const newObj = {}; (0, _foreach().default)(obj, (val, key) => { if (!val) return; newObj[key] = val; }); return newObj; }