refactor: remove lodash

This commit is contained in:
Thea Schöbl
2022-04-12 09:59:55 +00:00
parent fd7f664792
commit 72e5fcca77
58 changed files with 1294 additions and 356 deletions

View File

@@ -1,12 +1,12 @@
/*
* Copyright (C) 2021 StApps
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licens for
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
@@ -15,8 +15,8 @@
import {findRRules, RRule} from './ical';
import moment, {unitOfTime} from 'moment';
import {shuffle} from 'lodash-es';
import {SCISO8601Date} from '@openstapps/core';
import {shuffle} from '../../../_helpers/collections/shuffle';
/**
*

View File

@@ -1,12 +1,12 @@
/*
* Copyright (C) 2021 StApps
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public Licens for
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
@@ -20,16 +20,9 @@ import {
SCThingWithCategories,
SCUuid,
} from '@openstapps/core';
import {
difference,
flatMap,
isObject,
last,
mapValues,
minBy,
size,
} from 'lodash-es';
import moment, {unitOfTime} from 'moment';
import {minBy} from '../../../_helpers/collections/min';
import {mapValues} from '../../../_helpers/collections/map-values';
export interface ICalEvent {
name?: string;
@@ -126,7 +119,7 @@ export function findRRules(
for (let i = 0; i < sorted.length; i++) {
const current = sorted[i];
const next = sorted[i + 1] as SCISO8601Date | undefined;
const element = last(output);
const element = output[output.length - 1];
const units: unitOfTime.Diff[] = element?.freq
? [element.freq]
@@ -208,8 +201,9 @@ export function toICal(
options: ToICalOptions = {},
): ICalEvent[] {
const rrules = findRRules(
options.excludeCancelledEvents
? difference(dateSeries.dates, dateSeries.exceptions ?? [])
options.excludeCancelledEvents && dateSeries.exceptions
? // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
dateSeries.dates.filter(it => !dateSeries.exceptions!.includes(it))
: dateSeries.dates,
);
@@ -276,8 +270,9 @@ function stringifyLinebreaks<T extends string | unknown[] | unknown>(
if (Array.isArray(value)) {
return value.map(stringifyLinebreaks) as T;
}
if (isObject(value)) {
return mapValues(value, stringifyLinebreaks) as T;
// noinspection SuspiciousTypeOfGuard
if (value instanceof Object) {
return mapValues<object, unknown>(value, stringifyLinebreaks) as T;
}
return value;
}
@@ -348,7 +343,7 @@ export function serializeICalEvent(iCal: ICalEvent): ICalLike {
`STATUS:${normalized.cancelled === true ? 'CANCELLED' : 'CONFIRMED'}`,
`URL:${normalized.url}`,
// `RDATE;VALUE=DATE:${normalized.dates.join(',')}`,
size(normalized.exceptionDates) > 0
(normalized.exceptionDates?.length ?? 0) > 0
? `EXDATE;VALUE=DATE:${normalized.exceptionDates?.join(',')}`
: undefined,
`RRULE:${serializeRRule(normalized.rrule)}`,
@@ -372,7 +367,7 @@ export function serializeICal(iCal: ICalEvent[]): string {
'CALSCALE:GREGORIAN',
'COLOR:#FF0000',
'METHOD:PUBLISH',
...flatMap(iCal, serializeICalEvent),
...iCal.flatMap(serializeICalEvent),
'END:VCALENDAR',
]);
}
@@ -384,7 +379,7 @@ export function getNativeCalendarExport(
dateSeries: SCDateSeries[],
translator: SCThingTranslator,
): ICalEvent[] {
return flatMap(dateSeries, event =>
return dateSeries.flatMap(event =>
toICal(event, translator, {
allowRRuleExceptions: false,
excludeCancelledEvents: true,
@@ -401,14 +396,14 @@ export function getICalExport(
includeCancelled: boolean,
): ICalEvent[] {
return [
...flatMap(dateSeries, event =>
...dateSeries.flatMap(event =>
toICal(event, translator, {
allowRRuleExceptions: false,
excludeCancelledEvents: !includeCancelled,
}),
),
...(includeCancelled
? flatMap(dateSeries, event => toICalUpdates(event, translator))
? dateSeries.flatMap(event => toICalUpdates(event, translator))
: []),
];
}

View File

@@ -1,16 +1,16 @@
/*
* Copyright (C) 2021 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
* Copyright (C) 2022 StApps
* This program is free software: you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the Free
* Software Foundation, version 3.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
* You should have received a copy of the GNU General Public License along with
* this program. If not, see <https://www.gnu.org/licenses/>.
*/
/* eslint-disable unicorn/no-null */
@@ -27,8 +27,8 @@ import {
import {BehaviorSubject, Observable, Subscription} from 'rxjs';
import {DataProvider} from '../data/data.provider';
import {map} from 'rxjs/operators';
import {pick} from 'lodash-es';
import {DateFormatPipe, DurationPipe} from 'ngx-moment';
import {pick} from '../../_helpers/collections/pick';
/**
*
@@ -36,7 +36,7 @@ import {DateFormatPipe, DurationPipe} from 'ngx-moment';
export function toDateSeriesRelevantData(
dateSeries: SCDateSeries,
): DateSeriesRelevantData {
return pick(dateSeries, ...dateSeriesRelevantKeys);
return pick(dateSeries, dateSeriesRelevantKeys);
}
export type DateSeriesRelevantKeys =