I need to import _ from lodash library which will import all classes from lodash. Is there any solution to avoid importing this '_', by only importing the required libraries.
import _ from 'lodash';
import './style.css';
import _ from 'lodash';
import
{pick,head,uniqBy,map,partialRight as pr,omit} from 'lodash';
const baseProps = ['dc', 'effDate', 'expDate'];
const data = [{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":1,"minCharge":2},{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":2,"minCharge":6},{"dc":1,"effDate":"1/2/2019","expDate":"1/2/2019","rate":4,"minCharge":7}];
const result =_(data).groupBy('effDate')
.map(g => ({
...pick(head(g), baseProps),
rateCharge: uniqBy(map(g, pr(omit, baseProps)), 'rate')
})).value();
console.log(result)
Actual & Expected Output
[
{
"dc": 1,
"effDate": "1/2/2019",
"expDate": "1/2/2019",
"rateCharge": [
{
"rate": 1,
"minCharge": 2
},
{
"rate": 2,
"minCharge": 6
},
{
"rate": 4,
"minCharge": 7
}
]
}
];
My organization coding standard won't allow importing '_" from 'loadash', because it will import the entire library. As I am working in Typescritp Angular I am not able to find alternate solution.