Skip to content

Commit

Permalink
Replace lodash.set() with set-value's equivalent
Browse files Browse the repository at this point in the history
  • Loading branch information
rylnd committed Apr 29, 2020
1 parent d9d8d89 commit 9979c86
Showing 1 changed file with 7 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
* you may not use this file except in compliance with the Elastic License.
*/

import { flow, set, omit } from 'lodash/fp';
import { flow, omit } from 'lodash/fp';
import set from 'set-value';
import { SearchResponse } from 'elasticsearch';

import { Logger } from '../../../../../../../src/core/server';
Expand Down Expand Up @@ -55,8 +56,11 @@ export const transformAnomalyFieldsToEcs = (anomaly: Anomaly): EcsAnomaly => {
}

const omitDottedFields = omit(errantFields.map(field => field.name));
const setNestedFields = errantFields.map(field => set(field.name, field.value));
const setTimestamp = set('@timestamp', new Date(timestamp).toISOString());
const setNestedFields = errantFields.map(field => (_anomaly: Anomaly) =>
set(_anomaly, field.name, field.value)
);
const setTimestamp = (_anomaly: Anomaly) =>
set(_anomaly, '@timestamp', new Date(timestamp).toISOString());

return flow(omitDottedFields, setNestedFields, setTimestamp)(anomaly);
};
Expand Down

0 comments on commit 9979c86

Please sign in to comment.