diff --git a/js/components/ascribe_buttons/acl_information.js b/js/components/ascribe_buttons/acl_information.js index 4a6f5f50..87395546 100644 --- a/js/components/ascribe_buttons/acl_information.js +++ b/js/components/ascribe_buttons/acl_information.js @@ -90,7 +90,7 @@ let AclInformation = React.createClass({ verbsToDisplay = verbsToDisplay.concat(verbs); } else if(aim === 'button' && this.props.aclObject) { const { aclObject } = this.props; - const sanitizedAclObject = sanitize(aclObject, (val) => !val); + const sanitizedAclObject = sanitize(aclObject); verbsToDisplay = verbsToDisplay.concat(intersectLists(verbs, Object.keys(sanitizedAclObject))); } diff --git a/js/components/ascribe_forms/form.js b/js/components/ascribe_forms/form.js index 3f5bf96b..7e1371ed 100644 --- a/js/components/ascribe_forms/form.js +++ b/js/components/ascribe_forms/form.js @@ -370,7 +370,7 @@ let Form = React.createClass({ const validatedRef = this._hasRefErrors(refToValidate); validatedFormInputs[refName] = validatedRef; }); - const errorMessagesForRefs = sanitize(validatedFormInputs, (val) => !val); + const errorMessagesForRefs = sanitize(validatedFormInputs); this.handleError({ json: { errors: errorMessagesForRefs } }); return !Object.keys(errorMessagesForRefs).length; }, diff --git a/js/utils/acl.js b/js/utils/acl.js index 91ca47b7..c6b3c312 100644 --- a/js/utils/acl.js +++ b/js/utils/acl.js @@ -20,7 +20,7 @@ export function getAvailableAcls(editions, filterFn) { edition.acl.edition = false; edition.acl.piece = false; - edition.acl = sanitize(edition.acl, (val) => !val); + edition.acl = sanitize(edition.acl); edition.acl = Object.keys(edition.acl); // additionally, the user can specify a filter function for diff --git a/js/utils/general.js b/js/utils/general.js index 8be36871..7d7c1f96 100644 --- a/js/utils/general.js +++ b/js/utils/general.js @@ -6,23 +6,10 @@ */ export { default as isShallowEqual } from 'shallow-equals'; -/** - * Takes an object and returns a shallow copy without any keys - * that fail the passed in filter function. - * Does not modify the passed in object. - * - * @param {object} obj regular javascript object - * @return {object} regular javascript object without null values or empty strings - */ -export function sanitize(obj, filterFn) { - if (!filterFn) { - // By matching null with a double equal, we can match undefined and null - // http://stackoverflow.com/a/15992131 - filterFn = (val) => val == null || val === ''; - } - - return omitFromObject(obj, filterFn); -} +// Re-export general utilities from js-utility-belt for easier access +export { + sanitize +} from 'js-utility-belt/es6'; /** * Removes all falsy values (undefined, null, false, ...) from a list/array