lodash#omitBy JavaScript Examples
The following examples show how to use
lodash#omitBy.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: hash-utils.js From ThreatMapper with Apache License 2.0 | 7 votes |
export function hashDifferenceDeep(A, B) {
// If the elements have exactly the same content, the difference is an empty object.
// This could fail if the objects are both hashes with different permutation of keys,
// but this case we handle below by digging in recursively.
if (stableStringify(A) === stableStringify(B)) return {};
// Otherwise, if either element is not a hash, always return the first element
// unchanged as this function only takes difference of hash objects.
if (!isPlainObject(A) || !isPlainObject(B)) return A;
// If both elements are hashes, recursively take the difference by all keys
const rawDiff = mapValues(A, (value, key) => hashDifferenceDeep(value, B[key]));
// ... and filter out all the empty values.
return omitBy(rawDiff, value => isEmpty(value));
}
Example #2
Source File: router-utils.js From ThreatMapper with Apache License 2.0 | 7 votes |
function omitDefaultValues(urlState) {
// A couple of cases which require special handling because their URL state
// default values might be in different format than their Redux defaults.
if (!urlState.controlPipe) {
urlState = omit(urlState, 'controlPipe');
}
if (isEmpty(urlState.nodeDetails)) {
urlState = omit(urlState, 'nodeDetails');
}
if (isEmpty(urlState.topologyOptions)) {
urlState = omit(urlState, 'topologyOptions');
}
// Omit all the fields which match their initial Redux state values.
return omitBy(urlState, (value, key) => (
isDeepEqual(fromJS(value), initialRootState.get(key))
));
}
Example #3
Source File: index.js From datapass with GNU Affero General Public License v3.0 | 6 votes |
function flattenDiffTransformer(accumulatorObject, fullObjectDiff, objectKey) {
if (!isObject(fullObjectDiff[0])) {
accumulatorObject[objectKey] = fullObjectDiff;
return accumulatorObject;
}
// {contacts: [[{'name': 'c', email: 'd', work_email: 'a'}], [{'name': 'e', email: 'd'}]]}
const objectBefore = flatten(fullObjectDiff[0], objectKey);
const objectAfter = flatten(fullObjectDiff[1], objectKey);
const objectDiff = mergeWith(
objectBefore,
objectAfter,
(valueBefore, valueAfter) => [valueBefore, valueAfter]
);
// {0.name: ['c', 'e'], 0.email: ['d', 'd'], 0.work_email: 'a'}
const objectDiffNoUnchangedNoDeprecated = omitBy(
objectDiff,
(value) => !isArray(value) || value[0] === value[1]
);
// {0.name: ['c', 'e']}
const objectDiffPrefixedKey = mapKeys(
objectDiffNoUnchangedNoDeprecated,
(value, flatKey) => `${objectKey}.${flatKey}`
);
// {contacts.0.name: ['c', 'e']}
Object.assign(accumulatorObject, objectDiffPrefixedKey);
return accumulatorObject;
}
Example #4
Source File: index.js From datapass with GNU Affero General Public License v3.0 | 6 votes |
findModifiedScopes = (
demarcheState = {},
enrollmentState = {}
) => {
if (!findModifiedFields(demarcheState, enrollmentState).includes('scopes')) {
return {};
}
return omitBy(enrollmentState.scopes, function (v, k) {
return demarcheState.scopes[k] === v;
});
}
Example #5
Source File: index.js From datapass with GNU Affero General Public License v3.0 | 6 votes |
getScopesFromEnrollments = (enrollments) =>
chain(enrollments)
.map(({ scopes }) =>
chain(scopes)
.omitBy((v) => !v)
.keys()
.value()
)
.flatten()
.uniq()
.value()
Example #6
Source File: addTrackedExchanges.js From bonded-stablecoin-ui with MIT License | 6 votes |
addTrackedExchanges = ({ payload = {}, aa, ...props }) => async (dispatch, _, socket) => {
await socket.justsaying("light/new_aa_to_watch", { aa });
const cleanPayload = omitBy(payload, isNil);
dispatch({
type: ADD_TRACKED_EXCHANGES,
payload: { ...props, created_at: Date.now(), payload: cleanPayload, aa }
})
}
Example #7
Source File: enrollmentReducer.js From datapass with GNU Affero General Public License v3.0 | 5 votes |
globalUpdate = ({ previousEnrollment, futureEnrollment }) =>
merge(
{},
previousEnrollment,
omitBy(futureEnrollment, (e) => e === null) // do not merge null properties, keep empty string instead to avoid controlled input to switch to uncontrolled input
)
Example #8
Source File: EventDetail.js From hivemind with Apache License 2.0 | 4 votes |
EventDetail = ({ event, setNode }) => {
const { user } = useUser()
const { data, error } = useFetch(user, getDiffURL(event))
const diffRef = useRef(null)
if (error && window.notify) {
const options = {
place: 'tr',
message: 'Failed to fetch event details!',
type: 'danger',
autoDismiss: 7,
}
window.notify(options)
}
useEffect(() => {
const container = diffRef.current
if (!error && data && data.ok) {
const diff = data.data
let contents, node, baseText, newText
switch (event.event) {
case 'updated':
baseText = JSON.stringify(
omitBy(
pick(diff.v1, 'name', 'title', 'summary', 'content', 'audio'),
isEmpty
),
null,
2
)
newText = JSON.stringify(
omitBy(
pick(diff.v2, 'name', 'title', 'summary', 'content', 'audio'),
isEmpty
),
null,
2
)
contents = difflib.buildView({
baseText,
newText,
baseTextName: 'Previous Version',
newTextName: 'This Version',
inline: false,
})
if (diff.v1.title !== diff.v2.title) {
node = `${diff.v1.title} : ${diff.v2.title}`
} else {
node = diff.v1.title
}
break
case 'created':
case 'restored':
node = diff.v2.title
contents = document.createElement('span')
contents.innerHTML = `<b>Title:</b> ${diff.v2.title}`
break
case 'deleted':
node = `[${diff.v1.length} item(s)]`
contents = document.createElement('div')
diff.v1.forEach((d) => {
const rows = document.createElement('div')
rows.classNames = ['row']
const title = document.createElement('div')
title.classNames = ['row']
title.innerHTML = `<b>Title:</b> ${d.title}`
rows.appendChild(title)
if (d.summary) {
const summary = document.createElement('div')
summary.classNames = ['row']
summary.innerHTML = `<b>Summary:</b> ${d.summary}`
rows.appendChild(summary)
}
if (d.content) {
const content = document.createElement('div')
content.classNames = ['row']
content.innerHTML = `<b>Content:</b> ${d.content}`
rows.appendChild(content)
}
if (d.audio) {
const content = document.createElement('div')
audio.classNames = ['row']
audio.innerHTML = `<b>Audio:</b> ${d.content}`
rows.appendChild(content)
}
contents.appendChild(rows)
contents.appendChild(document.createElement('hr'))
})
break
default:
contents = document.createTextNode('WTF!')
node = 'WTF!'
}
setNode(node)
if (container.firstChild) {
container.replaceChild(contents, container.firstChild)
} else {
container.appendChild(contents)
}
} else {
ReactDOM.render(<Spinner />, container)
}
}, [data, error, event, setNode])
return <div id={'diff'} ref={diffRef} />
}
Example #9
Source File: controls.js From iceberg-editor with GNU General Public License v2.0 | 4 votes |
render() {
const {
isActive,
title,
rootBlocks,
selectBlock,
selectedBlockClientId,
headingBlockCount,
} = this.props;
if ( ! isActive ) {
return false;
}
if ( headingBlockCount === 0 ) {
return false;
}
return (
<Fragment>
<div className="components-iceberg-table-of-contents">
<ul className="components-iceberg-table-of-contents__list">
<li
key="toc-post-title"
className={ classnames(
'components-iceberg-heading-level--1'
) }
>
<Button
className={ classnames(
'iceberg-block-navigation__item-button'
) }
onClick={ () => {
this.scrollToSelected(
'.editor-post-title__input',
true
);
document
.querySelector(
'.editor-post-title__input'
)
.focus();
} }
>
{ title }
</Button>
</li>
{ map( omitBy( rootBlocks, isNil ), ( block ) => {
const isSelected =
block.clientId === selectedBlockClientId;
// Limit to Heading blocks only.
if ( ! [ 'core/heading' ].includes( block.name ) ) {
return false;
}
return (
<li
key={ block.clientId }
className={ classnames(
'components-iceberg-heading-level--' +
block.attributes.level,
{
'is-selected': isSelected,
}
) }
>
<Button
className={ classnames(
'iceberg-block-navigation__item-button'
) }
onClick={ () => {
this.scrollToSelected(
'block-' + block.clientId
);
selectBlock( block.clientId );
} }
>
{ block.attributes.content.replace(
/(<([^>]+)>)/gi,
''
) }
</Button>
</li>
);
} ) }
</ul>
</div>
</Fragment>
);
}