lodash-clean
Advanced tools
Comparing version 2.1.0 to 2.2.0
@@ -7,5 +7,4 @@ "use strict"; | ||
exports.cleanObject = cleanObject; | ||
exports.cleanString = cleanString; | ||
exports.cleanArray = cleanArray; | ||
exports.reducer = void 0; | ||
exports.cleanString = exports.reducer = exports.rmTrue = exports.rmEmpty = exports.branch = void 0; | ||
@@ -26,8 +25,25 @@ var _trim2 = _interopRequireDefault(require("lodash/fp/trim")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _flow2 = _interopRequireDefault(require("lodash/fp/flow")); | ||
var transform = _reduce2.default.convert({ | ||
var _curry2 = _interopRequireDefault(require("lodash/fp/curry")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var transform = _reduce2["default"].convert({ | ||
cap: false | ||
}); // Return undefined if result is empty. | ||
var branch = (0, _curry2["default"])(function (boolCheck, transformer, item) { | ||
var res = transformer(item); | ||
return boolCheck(res) ? undefined : res; | ||
}); | ||
exports.branch = branch; | ||
var rmEmpty = branch(_isEmpty2["default"]); | ||
exports.rmEmpty = rmEmpty; | ||
var rmTrue = (0, _curry2["default"])(function (transformer, item) { | ||
return transformer(item) ? undefined : item; | ||
}); // Build up a new so fresh, so clean object. | ||
exports.rmTrue = rmTrue; | ||
@@ -37,3 +53,3 @@ var reducer = function reducer(clean) { | ||
var cleanValue = clean(value, clean); | ||
return (0, _isUndefined2.default)(cleanValue) ? result : (0, _set2.default)([key], cleanValue, result); | ||
return (0, _isUndefined2["default"])(cleanValue) ? result : (0, _set2["default"])([key], cleanValue, result); | ||
}; | ||
@@ -46,16 +62,13 @@ }; // Assume we have a fairly normal data object here? | ||
function cleanObject(obj, clean) { | ||
var item = transform(reducer(clean), undefined, obj); | ||
return (0, _isEmpty2.default)(item) ? undefined : item; | ||
return transform(reducer(clean), undefined, obj); | ||
} | ||
function cleanString(string) { | ||
return (0, _trim2.default)(string) || undefined; | ||
} | ||
var cleanString = rmEmpty(_trim2["default"]); | ||
exports.cleanString = cleanString; | ||
function cleanArray(items, clean) { | ||
var cleanItems = (0, _map2.default)(function (item) { | ||
return clean(item, clean); | ||
}, items); | ||
var remainingItems = (0, _reject2.default)(_isUndefined2.default, cleanItems); | ||
return (0, _isEmpty2.default)(remainingItems) ? undefined : remainingItems; | ||
var cleanItems = (0, _flow2["default"])((0, _map2["default"])(function (x) { | ||
return clean(x, clean); | ||
}), (0, _reject2["default"])(_isUndefined2["default"])); | ||
return rmEmpty(cleanItems, items); | ||
} | ||
@@ -79,3 +92,3 @@ /** | ||
// [isPlainObject, cleanObject], | ||
// [isString, trim], | ||
// [isString, cleanString], | ||
// ) |
@@ -6,2 +6,9 @@ "use strict"; | ||
}); | ||
var _exportNames = { | ||
buildCleaner: true, | ||
cleaner: true, | ||
fieldTypeCleaners: true, | ||
buildGetValue: true, | ||
getValue: true | ||
}; | ||
exports.buildCleaner = buildCleaner; | ||
@@ -26,3 +33,3 @@ Object.defineProperty(exports, "fieldTypeCleaners", { | ||
}); | ||
exports.default = exports.cleaner = void 0; | ||
exports["default"] = exports.cleaner = void 0; | ||
@@ -33,6 +40,19 @@ var _isFunction2 = _interopRequireDefault(require("lodash/fp/isFunction")); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _clean = require("./clean"); | ||
Object.keys(_clean).forEach(function (key) { | ||
if (key === "default" || key === "__esModule") return; | ||
if (Object.prototype.hasOwnProperty.call(_exportNames, key)) return; | ||
Object.defineProperty(exports, key, { | ||
enumerable: true, | ||
get: function get() { | ||
return _clean[key]; | ||
} | ||
}); | ||
}); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
function getMungeFunc(mungeOption) { | ||
if ((0, _isFunction2.default)(mungeOption)) return mungeOption(_munge.fieldTypeCleaners); | ||
if ((0, _isFunction2["default"])(mungeOption)) return mungeOption(_munge.fieldTypeCleaners); | ||
return (0, _munge.buildGetValue)(mungeOption); | ||
@@ -54,2 +74,2 @@ } | ||
var _default = cleaner; | ||
exports.default = _default; | ||
exports["default"] = _default; |
@@ -27,2 +27,4 @@ "use strict"; | ||
var _isNumber2 = _interopRequireDefault(require("lodash/fp/isNumber")); | ||
var _isNull2 = _interopRequireDefault(require("lodash/fp/isNull")); | ||
@@ -50,24 +52,25 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { "default": obj }; } | ||
var isEmptyString = (0, _overEvery2.default)([_isString2.default, (0, _flow2.default)(_trim2.default, _isEmpty2.default)]); | ||
var isEmptyString = (0, _overEvery2["default"])([_isString2["default"], (0, _flow2["default"])(_trim2["default"], _isEmpty2["default"])]); | ||
exports.isEmptyString = isEmptyString; | ||
var isEmptyObject = (0, _overEvery2.default)([_isPlainObject2.default, (0, _flow2.default)((0, _pickBy2.default)(_identity2.default), _isEmpty2.default)]); | ||
var isEmptyObject = (0, _overEvery2["default"])([_isPlainObject2["default"], (0, _flow2["default"])((0, _pickBy2["default"])(_identity2["default"]), _isEmpty2["default"])]); | ||
exports.isEmptyObject = isEmptyObject; | ||
var isEmptyArr = (0, _overEvery2.default)([_isArray2.default, (0, _flow2.default)(_compact2.default, _isEmpty2.default)]); | ||
var isEmptyArr = (0, _overEvery2["default"])([_isArray2["default"], (0, _flow2["default"])(_compact2["default"], _isEmpty2["default"])]); | ||
exports.isEmptyArr = isEmptyArr; | ||
var rejectEmpty = (0, _reject2.default)((0, _overSome2.default)([isEmptyString, isEmptyObject, isEmptyArr])); // Only does one level of recursion. :-( | ||
var rejectEmpty = (0, _reject2["default"])((0, _overSome2["default"])([isEmptyString, isEmptyObject, isEmptyArr])); // Only does one level of recursion. :-( | ||
exports.rejectEmpty = rejectEmpty; | ||
var isEmptyArray = (0, _overEvery2.default)([_isArray2.default, (0, _flow2.default)(_compact2.default, rejectEmpty, _isEmpty2.default)]); | ||
var isEmptyArray = (0, _overEvery2["default"])([_isArray2["default"], (0, _flow2["default"])(_compact2["default"], rejectEmpty, _isEmpty2["default"])]); | ||
exports.isEmptyArray = isEmptyArray; | ||
var fieldTypeCleaners = { | ||
isArray: _clean.cleanArray, | ||
isBoolean: _identity2.default, | ||
isDate: _identity2.default, | ||
isFunction: _noop2.default, | ||
isNull: _identity2.default, | ||
isBoolean: _identity2["default"], | ||
isDate: _identity2["default"], | ||
isFunction: _noop2["default"], | ||
isNull: _identity2["default"], | ||
isNumber: _identity2["default"], | ||
isPlainObject: _clean.cleanObject, | ||
isString: _clean.cleanString, | ||
isUndefined: _noop2.default | ||
isUndefined: _noop2["default"] | ||
}; | ||
@@ -78,12 +81,13 @@ exports.fieldTypeCleaners = fieldTypeCleaners; | ||
var mungeWithOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var mungeWith = (0, _defaults2.default)(fieldTypeCleaners, mungeWithOptions); | ||
var mungeWith = (0, _defaults2["default"])(fieldTypeCleaners, mungeWithOptions); | ||
return function getVal(node, clean) { | ||
if ((0, _isUndefined2.default)(node)) return mungeWith.isUndefined(node); | ||
if ((0, _isFunction2.default)(node)) return mungeWith.isFunction(node); | ||
if ((0, _isBoolean2.default)(node)) return mungeWith.isBoolean(node); | ||
if ((0, _isNull2.default)(node)) return mungeWith.isNull(node); | ||
if ((0, _isString2.default)(node)) return mungeWith.isString(node); | ||
if ((0, _isDate2.default)(node)) return mungeWith.isDate(node); | ||
if ((0, _isArray2.default)(node)) return mungeWith.isArray(node, clean); | ||
if ((0, _isPlainObject2.default)(node)) return mungeWith.isPlainObject(node, clean); | ||
if ((0, _isArray2["default"])(node)) return mungeWith.isArray(node, clean); | ||
if ((0, _isPlainObject2["default"])(node)) return mungeWith.isPlainObject(node, clean); | ||
if ((0, _isUndefined2["default"])(node)) return mungeWith.isUndefined(node); | ||
if ((0, _isFunction2["default"])(node)) return mungeWith.isFunction(node); | ||
if ((0, _isBoolean2["default"])(node)) return mungeWith.isBoolean(node); | ||
if ((0, _isNull2["default"])(node)) return mungeWith.isNull(node); | ||
if ((0, _isNumber2["default"])(node)) return mungeWith.isNumber(node); | ||
if ((0, _isString2["default"])(node)) return mungeWith.isString(node); | ||
if ((0, _isDate2["default"])(node)) return mungeWith.isDate(node); | ||
return node; | ||
@@ -90,0 +94,0 @@ }; |
{ | ||
"name": "lodash-clean", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Remove object keys that have empty values.", | ||
@@ -11,2 +11,10 @@ "main": "lib/index.js", | ||
}, | ||
"keywords": [ | ||
"lodash", | ||
"clean", | ||
"trim", | ||
"compact", | ||
"array", | ||
"object" | ||
], | ||
"scripts": { | ||
@@ -20,3 +28,3 @@ "build": "mkdir -p lib && babel ./src -d lib", | ||
"dependencies": { | ||
"lodash": "^4.17.11" | ||
"lodash": "^4.17.15" | ||
}, | ||
@@ -28,8 +36,8 @@ "devDependencies": { | ||
"babel-plugin-lodash": "^3.3.4", | ||
"eslint": "^5.14.1", | ||
"eslint": "^6.0.1", | ||
"eslint-config-airbnb-base": "^13.1.0", | ||
"eslint-plugin-import": "^2.16.0", | ||
"eslint-plugin-lodash-fp": "^2.2.0-a1", | ||
"jest": "^24.1.0" | ||
"jest": "^24.8.0" | ||
} | ||
} |
@@ -56,2 +56,3 @@ # lodash-clean | ||
// These are the default options | ||
const options = { | ||
@@ -80,2 +81,4 @@ isArray: cleanArray, | ||
* **2.2** Code cleanup. | ||
* **2.1** Allow keys to have dots. See issue #1. | ||
* **2.0** Will now remove empty objects. Internal rewrite and code cleanup. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
12752
194
83
0
Updatedlodash@^4.17.15