lodash-clean
Advanced tools
Comparing version 2.0.1 to 2.1.0
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,57 +6,72 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.cleanObject = cleanObject; | ||
exports.cleanString = cleanString; | ||
exports.cleanArray = cleanArray; | ||
exports.reducer = void 0; | ||
var _trim2 = require('lodash/trim'); | ||
var _trim2 = _interopRequireDefault(require("lodash/fp/trim")); | ||
var _trim3 = _interopRequireDefault(_trim2); | ||
var _set2 = _interopRequireDefault(require("lodash/fp/set")); | ||
var _transform2 = require('lodash/transform'); | ||
var _reject2 = _interopRequireDefault(require("lodash/fp/reject")); | ||
var _transform3 = _interopRequireDefault(_transform2); | ||
var _reduce2 = _interopRequireDefault(require("lodash/fp/reduce")); | ||
var _set2 = require('lodash/set'); | ||
var _map2 = _interopRequireDefault(require("lodash/fp/map")); | ||
var _set3 = _interopRequireDefault(_set2); | ||
var _isUndefined2 = _interopRequireDefault(require("lodash/fp/isUndefined")); | ||
var _reject2 = require('lodash/reject'); | ||
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty")); | ||
var _reject3 = _interopRequireDefault(_reject2); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _map2 = require('lodash/map'); | ||
var transform = _reduce2.default.convert({ | ||
cap: false | ||
}); // Build up a new so fresh, so clean object. | ||
var _map3 = _interopRequireDefault(_map2); | ||
var _isUndefined2 = require('lodash/isUndefined'); | ||
var reducer = function reducer(clean) { | ||
return function (result, value, key) { | ||
var cleanValue = clean(value, clean); | ||
return (0, _isUndefined2.default)(cleanValue) ? result : (0, _set2.default)([key], cleanValue, result); | ||
}; | ||
}; // Assume we have a fairly normal data object here? | ||
var _isUndefined3 = _interopRequireDefault(_isUndefined2); | ||
var _isEmpty2 = require('lodash/isEmpty'); | ||
exports.reducer = reducer; | ||
var _isEmpty3 = _interopRequireDefault(_isEmpty2); | ||
exports.cleanObject = cleanObject; | ||
exports.cleanString = cleanString; | ||
exports.cleanArray = cleanArray; | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
// Assume we have a fairly normal data object here? | ||
function cleanObject(obj, clean) { | ||
// Build up a new so fresh, so clean object. | ||
function reducer(result, value, key) { | ||
var cleanValue = clean(value, clean); | ||
return (0, _isUndefined3.default)(cleanValue) ? result : (0, _set3.default)(result, key, cleanValue); | ||
} | ||
var item = (0, _transform3.default)(obj, reducer); | ||
return (0, _isEmpty3.default)(item) ? undefined : item; | ||
var item = transform(reducer(clean), undefined, obj); | ||
return (0, _isEmpty2.default)(item) ? undefined : item; | ||
} | ||
function cleanString(string) { | ||
return (0, _trim3.default)(string) || undefined; | ||
return (0, _trim2.default)(string) || undefined; | ||
} | ||
function cleanArray(items, clean) { | ||
var cleanItems = (0, _map3.default)(items, function (item) { | ||
var cleanItems = (0, _map2.default)(function (item) { | ||
return clean(item, clean); | ||
}); | ||
var remainingItems = (0, _reject3.default)(cleanItems, _isUndefined3.default); | ||
return (0, _isEmpty3.default)(remainingItems) ? undefined : remainingItems; | ||
} | ||
}, items); | ||
var remainingItems = (0, _reject2.default)(_isUndefined2.default, cleanItems); | ||
return (0, _isEmpty2.default)(remainingItems) ? undefined : remainingItems; | ||
} | ||
/** | ||
* [isWorthless description] | ||
* @param {any} value | ||
* @return {bool} Tells you if value is empty. | ||
* @example isWorthless({}) // => true | ||
* @example isWorthless([' ', null]) // => true | ||
* @example isWorthless(' ') // => true | ||
* @example isWorthless({ foo: null, bar: 0 }) // => true | ||
*/ | ||
// export const isWorthless = overSome([ | ||
// isNull, isFalse, isZero, isEmptyString, isEmptyArray, isEmptyObject, | ||
// ]) | ||
// export const rejectWorthless = reject(isWorthless) | ||
// export const cleanObject = omitBy(isWorthless) | ||
// export const clean = condId( | ||
// [isArray, flow(compact, map(clean))], // eslint-disable-line no-use-before-define | ||
// [isPlainObject, cleanObject], | ||
// [isString, trim], | ||
// ) |
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,26 +6,34 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.getValue = exports.buildGetValue = exports.fieldTypeCleaners = undefined; | ||
exports.buildCleaner = buildCleaner; | ||
Object.defineProperty(exports, "fieldTypeCleaners", { | ||
enumerable: true, | ||
get: function get() { | ||
return _munge.fieldTypeCleaners; | ||
} | ||
}); | ||
Object.defineProperty(exports, "buildGetValue", { | ||
enumerable: true, | ||
get: function get() { | ||
return _munge.buildGetValue; | ||
} | ||
}); | ||
Object.defineProperty(exports, "getValue", { | ||
enumerable: true, | ||
get: function get() { | ||
return _munge.getValue; | ||
} | ||
}); | ||
exports.default = exports.cleaner = void 0; | ||
var _partialRight2 = require('lodash/partialRight'); | ||
var _isFunction2 = _interopRequireDefault(require("lodash/fp/isFunction")); | ||
var _partialRight3 = _interopRequireDefault(_partialRight2); | ||
var _munge = require("./munge"); | ||
var _isFunction2 = require('lodash/isFunction'); | ||
var _isFunction3 = _interopRequireDefault(_isFunction2); | ||
exports.buildCleaner = buildCleaner; | ||
var _munge = require('./munge'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function getMungeFunc(mungeOption) { | ||
if ((0, _isFunction3.default)(mungeOption)) return mungeOption(_munge.fieldTypeCleaners); | ||
if ((0, _isFunction2.default)(mungeOption)) return mungeOption(_munge.fieldTypeCleaners); | ||
return (0, _munge.buildGetValue)(mungeOption); | ||
} | ||
exports.fieldTypeCleaners = _munge.fieldTypeCleaners; | ||
exports.buildGetValue = _munge.buildGetValue; | ||
exports.getValue = _munge.getValue; | ||
function buildCleaner(mungeOption) { | ||
@@ -38,2 +46,8 @@ var cleaner = getMungeFunc(mungeOption); | ||
exports.default = (0, _partialRight3.default)(_munge.getValue, _munge.getValue); | ||
var cleaner = function cleaner(obj) { | ||
return (0, _munge.getValue)(obj, _munge.getValue); | ||
}; | ||
exports.cleaner = cleaner; | ||
var _default = cleaner; | ||
exports.default = _default; |
100
lib/munge.js
@@ -1,2 +0,2 @@ | ||
'use strict'; | ||
"use strict"; | ||
@@ -6,81 +6,87 @@ Object.defineProperty(exports, "__esModule", { | ||
}); | ||
exports.getValue = exports.fieldTypeCleaners = undefined; | ||
exports.buildGetValue = buildGetValue; | ||
exports.getValue = exports.fieldTypeCleaners = exports.isEmptyArray = exports.rejectEmpty = exports.isEmptyArr = exports.isEmptyObject = exports.isEmptyString = void 0; | ||
var _noop2 = require('lodash/noop'); | ||
var _trim2 = _interopRequireDefault(require("lodash/fp/trim")); | ||
var _noop3 = _interopRequireDefault(_noop2); | ||
var _reject2 = _interopRequireDefault(require("lodash/fp/reject")); | ||
var _isUndefined2 = require('lodash/isUndefined'); | ||
var _pickBy2 = _interopRequireDefault(require("lodash/fp/pickBy")); | ||
var _isUndefined3 = _interopRequireDefault(_isUndefined2); | ||
var _overSome2 = _interopRequireDefault(require("lodash/fp/overSome")); | ||
var _isString2 = require('lodash/isString'); | ||
var _overEvery2 = _interopRequireDefault(require("lodash/fp/overEvery")); | ||
var _isString3 = _interopRequireDefault(_isString2); | ||
var _noop2 = _interopRequireDefault(require("lodash/fp/noop")); | ||
var _isPlainObject2 = require('lodash/isPlainObject'); | ||
var _isUndefined2 = _interopRequireDefault(require("lodash/fp/isUndefined")); | ||
var _isPlainObject3 = _interopRequireDefault(_isPlainObject2); | ||
var _isString2 = _interopRequireDefault(require("lodash/fp/isString")); | ||
var _isNull2 = require('lodash/isNull'); | ||
var _isPlainObject2 = _interopRequireDefault(require("lodash/fp/isPlainObject")); | ||
var _isNull3 = _interopRequireDefault(_isNull2); | ||
var _isNull2 = _interopRequireDefault(require("lodash/fp/isNull")); | ||
var _isFunction2 = require('lodash/isFunction'); | ||
var _isFunction2 = _interopRequireDefault(require("lodash/fp/isFunction")); | ||
var _isFunction3 = _interopRequireDefault(_isFunction2); | ||
var _isEmpty2 = _interopRequireDefault(require("lodash/fp/isEmpty")); | ||
var _isDate2 = require('lodash/isDate'); | ||
var _identity2 = _interopRequireDefault(require("lodash/fp/identity")); | ||
var _isDate3 = _interopRequireDefault(_isDate2); | ||
var _isDate2 = _interopRequireDefault(require("lodash/fp/isDate")); | ||
var _isBoolean2 = require('lodash/isBoolean'); | ||
var _isBoolean2 = _interopRequireDefault(require("lodash/fp/isBoolean")); | ||
var _isBoolean3 = _interopRequireDefault(_isBoolean2); | ||
var _isArray2 = _interopRequireDefault(require("lodash/fp/isArray")); | ||
var _isArray2 = require('lodash/isArray'); | ||
var _flow2 = _interopRequireDefault(require("lodash/fp/flow")); | ||
var _isArray3 = _interopRequireDefault(_isArray2); | ||
var _defaults2 = _interopRequireDefault(require("lodash/fp/defaults")); | ||
var _identity2 = require('lodash/identity'); | ||
var _compact2 = _interopRequireDefault(require("lodash/fp/compact")); | ||
var _identity3 = _interopRequireDefault(_identity2); | ||
var _clean = require("./clean"); | ||
var _defaults2 = require('lodash/defaults'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var _defaults3 = _interopRequireDefault(_defaults2); | ||
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)]); | ||
exports.isEmptyObject = isEmptyObject; | ||
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. :-( | ||
exports.buildGetValue = buildGetValue; | ||
var _clean = require('./clean'); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var fieldTypeCleaners = exports.fieldTypeCleaners = { | ||
exports.rejectEmpty = rejectEmpty; | ||
var isEmptyArray = (0, _overEvery2.default)([_isArray2.default, (0, _flow2.default)(_compact2.default, rejectEmpty, _isEmpty2.default)]); | ||
exports.isEmptyArray = isEmptyArray; | ||
var fieldTypeCleaners = { | ||
isArray: _clean.cleanArray, | ||
isBoolean: _identity3.default, | ||
isDate: _identity3.default, | ||
isFunction: _noop3.default, | ||
isNull: _identity3.default, | ||
isBoolean: _identity2.default, | ||
isDate: _identity2.default, | ||
isFunction: _noop2.default, | ||
isNull: _identity2.default, | ||
isPlainObject: _clean.cleanObject, | ||
isString: _clean.cleanString, | ||
isUndefined: _noop3.default | ||
isUndefined: _noop2.default | ||
}; | ||
exports.fieldTypeCleaners = fieldTypeCleaners; | ||
function buildGetValue() { | ||
var mungeWithOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {}; | ||
var mungeWith = (0, _defaults3.default)(mungeWithOptions, fieldTypeCleaners); | ||
var mungeWith = (0, _defaults2.default)(fieldTypeCleaners, mungeWithOptions); | ||
return function getVal(node, clean) { | ||
if ((0, _isUndefined3.default)(node)) return mungeWith.isUndefined(node); | ||
if ((0, _isFunction3.default)(node)) return mungeWith.isFunction(node); | ||
if ((0, _isBoolean3.default)(node)) return mungeWith.isBoolean(node); | ||
if ((0, _isNull3.default)(node)) return mungeWith.isNull(node); | ||
if ((0, _isString3.default)(node)) return mungeWith.isString(node); | ||
if ((0, _isDate3.default)(node)) return mungeWith.isDate(node); | ||
if ((0, _isArray3.default)(node)) return mungeWith.isArray(node, clean); | ||
if ((0, _isPlainObject3.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, _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); | ||
return node; | ||
}; | ||
} | ||
var getValue = exports.getValue = buildGetValue(); | ||
var getValue = buildGetValue(); | ||
exports.getValue = getValue; |
{ | ||
"name": "lodash-clean", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"description": "Remove object keys that have empty values.", | ||
@@ -13,21 +13,21 @@ "main": "lib/index.js", | ||
"build": "mkdir -p lib && babel ./src -d lib", | ||
"dev": "", | ||
"prepublish": "npm run build", | ||
"test": "babel-tape-runner test/**/*spec.js" | ||
"test": "jest --watch" | ||
}, | ||
"license": "ISC", | ||
"dependencies": { | ||
"lodash": "^4.17.4" | ||
"lodash": "^4.17.11" | ||
}, | ||
"devDependencies": { | ||
"babel-cli": "^6.14.0", | ||
"babel-plugin-add-module-exports": "^0.2.1", | ||
"babel-plugin-lodash": "^3.2.8", | ||
"babel-preset-es2015": "^6.14.0", | ||
"babel-preset-stage-1": "^6.13.0", | ||
"babel-tape-runner": "^2.0.1", | ||
"eslint": "^3.5.0", | ||
"eslint-config-airbnb-base": "^7.1.0", | ||
"eslint-plugin-import": "^1.15.0", | ||
"tape": "^4.6.0" | ||
"@babel/cli": "^7.2.3", | ||
"@babel/core": "^7.3.4", | ||
"@babel/preset-env": "^7.3.4", | ||
"babel-plugin-lodash": "^3.3.4", | ||
"eslint": "^5.14.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" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# lodash-clean v2.0.1 | ||
# lodash-clean | ||
@@ -33,2 +33,3 @@ Remove object properties that are undefined, functions, empty arrays, or empty strings. | ||
start: true, | ||
'nathan.drake@example.com': 'Issue #1', | ||
} | ||
@@ -45,2 +46,3 @@ const after = clean(before) | ||
// start: true, | ||
// 'nathan.drake@example.com': 'Issue #1', | ||
// } | ||
@@ -47,0 +49,0 @@ ``` |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
9
164
80
11264
8
1
Updatedlodash@^4.17.11