Skip to content

Commit e9c8bb9

Browse files
lexasqPowerKiKi
andauthored
Replace lodash-es with es-toolkit (#2025)
Our demo app main.js goes from ~1003.1 KiB down to ~991.6 KiB, so saving ~11.5KiB. Co-authored-by: Adrien Crivelli <adrien.crivelli@gmail.com>
1 parent 47cc11a commit e9c8bb9

File tree

9 files changed

+44
-55
lines changed

9 files changed

+44
-55
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ The required packages will be automatically installed, and your `app.config.ts`
2222
changes to start using the library right away.
2323

2424
If you want to install [schematics](https://www.npmjs.com/package/ng2-charts-schematics) for easier code generation too:
25+
2526
```bash
2627
npm install --save-dev ng2-charts-schematics
2728
```

apps/ng2-charts-demo/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
const esModules = ['lodash-es', 'marked', 'ngx-markdown'].join('|');
1+
const esModules = ['es-toolkit', 'marked', 'ngx-markdown'].join('|');
22
export default {
33
displayName: 'ng2-charts',
44
preset: '../../jest.preset.js',

libs/ng2-charts/jest.config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/* eslint-disable */
2-
const esModules = ['lodash-es'].join('|');
2+
const esModules = ['es-toolkit'].join('|');
33
export default {
44
displayName: 'ng2-charts',
55
preset: '../../jest.preset.js',

libs/ng2-charts/ng-package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,5 @@
55
"lib": {
66
"entryFile": "src/index.ts"
77
},
8-
"allowedNonPeerDependencies": ["lodash-es"]
8+
"allowedNonPeerDependencies": ["es-toolkit"]
99
}

libs/ng2-charts/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
"rxjs": "^6.5.3 || ^7.4.0"
1212
},
1313
"dependencies": {
14-
"lodash-es": "^4.17.15"
14+
"es-toolkit": "^1.39.7"
1515
},
1616
"author": "Dmitriy Shekhovtsov <valorkin@gmail.com>",
1717
"contributors": [

libs/ng2-charts/src/lib/base-chart.directive.ts

Lines changed: 23 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import {
2525
import { ThemeService } from './theme.service';
2626
import { Subscription } from 'rxjs';
2727
import { distinctUntilChanged } from 'rxjs/operators';
28-
import { merge } from 'lodash-es';
28+
import { merge } from 'es-toolkit';
2929
import {
3030
NG_CHARTS_CONFIGURATION,
3131
NgChartsConfiguration,
@@ -209,37 +209,33 @@ export class BaseChartDirective<
209209
TData,
210210
TLabel
211211
>['options'] {
212-
const baseOptions = {
213-
onHover: (event: ChartEvent, active: object[]) => {
214-
if (!this.chartHover.observed && !this.chartHover.observers?.length) {
215-
return;
216-
}
212+
return [
213+
{
214+
onHover: (event: ChartEvent, active: object[]) => {
215+
if (!this.chartHover.observed && !this.chartHover.observers?.length) {
216+
return;
217+
}
217218

218-
this.zone.run(() => this.chartHover.emit({ event, active }));
219-
},
220-
onClick: (event?: ChartEvent, active?: object[]) => {
221-
if (!this.chartClick.observed && !this.chartClick.observers?.length) {
222-
return;
223-
}
219+
this.zone.run(() => this.chartHover.emit({ event, active }));
220+
},
221+
onClick: (event?: ChartEvent, active?: object[]) => {
222+
if (!this.chartClick.observed && !this.chartClick.observers?.length) {
223+
return;
224+
}
224225

225-
this.zone.run(() => this.chartClick.emit({ event, active }));
226+
this.zone.run(() => this.chartClick.emit({ event, active }));
227+
},
226228
},
227-
};
228-
229-
const legendOptions = {
230-
plugins: {
231-
legend: {
232-
display: this.legend,
229+
this.themeOverrides ?? {},
230+
this.options ?? {},
231+
{
232+
plugins: {
233+
legend: {
234+
display: this.legend,
235+
},
233236
},
234237
},
235-
};
236-
237-
return merge(
238-
baseOptions,
239-
this.themeOverrides || {},
240-
this.options || {},
241-
legendOptions,
242-
) as ChartConfiguration<TType, TData, TLabel>['options'];
238+
].reduce(merge, {}) as ChartConfiguration<TType, TData, TLabel>['options'];
243239
}
244240

245241
private getChartConfiguration(): ChartConfiguration<TType, TData, TLabel> {

libs/ng2-charts/src/lib/ng-charts.provider.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import {
55
registerables as defaultRegisterables,
66
} from 'chart.js';
77
import { DeepPartial } from './utils';
8-
import { merge } from 'lodash-es';
8+
import { merge } from 'es-toolkit';
99

1010
export const NG_CHARTS_CONFIGURATION =
1111
new InjectionToken<NgChartsConfiguration>('Configuration for ngCharts');
@@ -38,6 +38,6 @@ export function withDefaultRegisterables(
3838
export function provideCharts(
3939
...configurations: readonly NgChartsConfiguration[]
4040
) {
41-
const config: NgChartsConfiguration = merge({}, ...configurations);
41+
const config: NgChartsConfiguration = configurations.reduce(merge, {});
4242
return { provide: NG_CHARTS_CONFIGURATION, useValue: config };
4343
}

package-lock.json

Lines changed: 13 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@
4949
"core-js": "^3.23.5",
5050
"date-fns": "^3.3.1",
5151
"dompurify": "^3.2.1",
52+
"es-toolkit": "^1.39.7",
5253
"express": "^4.18.2",
5354
"highlight.js": "^11.6.0",
54-
"lodash-es": "^4.17.21",
5555
"marked": "^17.0.0",
5656
"ngx-highlightjs": "^10.0.0",
5757
"ngx-markdown": "21.1.0",
@@ -82,7 +82,6 @@
8282
"@schematics/angular": "21.2.0",
8383
"@types/express": "^4.17.17",
8484
"@types/jest": "^30.0.0",
85-
"@types/lodash-es": "^4.17.12",
8685
"@types/luxon": "^3.4.2",
8786
"@types/node": "^22.9.3",
8887
"@typescript-eslint/eslint-plugin": "^8.56.1",

0 commit comments

Comments
 (0)