refactor: remove lodash

Signed-off-by: GitHub <noreply@github.com>
This commit is contained in:
Fernando Fernández 2024-08-29 08:33:10 +00:00
parent 37690891f8
commit 6ee554d150
8 changed files with 43 additions and 59 deletions

View File

@ -37,7 +37,6 @@
"hls.js": "1.5.15",
"jassub": "1.7.17",
"libpgs": "0.5.0",
"lodash-es": "4.17.21",
"marked": "14.1.0",
"sortablejs": "1.15.3",
"swiper": "11.1.12",
@ -57,7 +56,6 @@
"@rollup/plugin-virtual": "3.0.2",
"@stylistic/eslint-plugin": "2.6.2",
"@types/dompurify": "3.0.5",
"@types/lodash-es": "4.17.12",
"@types/node": "22.1.0",
"@types/sortablejs": "1.15.8",
"@types/uuid": "10.0.0",

View File

@ -37,15 +37,12 @@
<script setup lang="ts">
import type { BaseItemDto } from '@jellyfin/sdk/lib/generated-client';
import { groupBy } from 'lodash-es';
import { computed, ref } from 'vue';
import { computed, shallowRef } from 'vue';
const props = defineProps<{
items: BaseItemDto[];
}>();
const currentTab = ref(0);
const children = computed(() => {
return groupBy(props.items, 'Type');
});
const currentTab = shallowRef(0);
const children = computed(() => Object.groupBy(props.items, ({ Type }) => Type!));
</script>

View File

@ -72,7 +72,9 @@
:value="dateCreated"
:label="t('dateAdded')"
@update:date="
(value) => formatAndAssignDate('DateCreated', value)
(value) => {
metadata!.DateCreated = formatISO(new Date(value))
}
" />
<VRow>
<VCol
@ -97,7 +99,9 @@
:value="premiereDate"
:label="t('releaseDate')"
@update:date="
(value) => formatAndAssignDate('PremiereDate', value)
(value) => {
metadata!.PremiereDate = formatISO(new Date(value))
}
" />
<VTextField
v-model="metadata.ProductionYear"
@ -226,7 +230,6 @@ import { getLibraryApi } from '@jellyfin/sdk/lib/utils/api/library-api';
import { getUserLibraryApi } from '@jellyfin/sdk/lib/utils/api/user-library-api';
import { AxiosError } from 'axios';
import { format, formatISO } from 'date-fns';
import { pick, set } from 'lodash-es';
import { computed, ref } from 'vue';
import { useI18n } from 'vue-i18n';
import { watchImmediate } from '@vueuse/core';
@ -234,6 +237,7 @@ import { isArray } from '@/utils/validation';
import { remote } from '@/plugins/remote';
import { useSnackbar } from '@/composables/use-snackbar';
import { useDateFns } from '@/composables/use-datefns';
import { pick } from '@/utils/data-manipulation';
interface ContentOption {
value: string;
@ -477,18 +481,6 @@ async function saveMetadata(): Promise<void> {
}
}
/**
* Formats and updates dates
*/
function formatAndAssignDate(key: keyof BaseItemDto, date: string): void {
if (!metadata.value) {
return;
}
menu.value = false;
set(metadata.value, key, formatISO(new Date(date)));
}
/**
* Handle adding a person
*/

View File

@ -120,7 +120,6 @@ import {
type BaseItemDto
} from '@jellyfin/sdk/lib/generated-client';
import { getItemsApi } from '@jellyfin/sdk/lib/utils/api/items-api';
import { groupBy } from 'lodash-es';
import { computed } from 'vue';
import { useBaseItem } from '@/composables/apis';
import { playbackManager } from '@/store/playback-manager';
@ -137,9 +136,7 @@ const { data: tracks } = await useBaseItem(getItemsApi, 'getItems')(() => ({
sortOrder: [SortOrder.Ascending]
}));
const tracksPerDisc = computed(() => {
return groupBy(tracks.value, 'ParentIndexNumber');
});
const tracksPerDisc = computed(() => Object.groupBy(tracks.value, ({ ParentIndexNumber }) => ParentIndexNumber!));
/**
* Check if a given BaseItemDto is playing

View File

@ -1,5 +1,4 @@
import { expose } from 'comlink';
import { shuffle as _shuffle } from 'lodash-es';
import { sealed } from '@/utils/validation';
/**
@ -8,7 +7,19 @@ import { sealed } from '@/utils/validation';
*/
@sealed
class GenericWorker {
public readonly shuffle = (...args: Parameters<typeof _shuffle>) => _shuffle(...args);
/**
* Shuffles an array using the Durstenfeld shuffle algorithm, an
* optimized version of Fisher-Yates shuffle.
*/
public shuffle<T>(array: T[]) {
for (let i = array.length - 1; i > 0; i--) {
const j = Math.floor(Math.random() * (i + 1));
[array[i], array[j]] = [array[j], array[i]];
}
return array;
};
}
const instance = new GenericWorker();

View File

@ -7,12 +7,12 @@ import { defu } from 'defu';
* @param defaultObject - Sample/default representation of the object that should be used to detect which keys
* should/shouldn't exist in the target.
*/
export function mergeExcludingUnknown<T extends object, K extends keyof T>(
export function mergeExcludingUnknown<T extends object>(
object: T,
defaultObject: T
): T {
const defaultKeys = new Set(Object.keys(defaultObject) as K[]);
const missingKeys = (Object.keys(object) as K[]).filter(
const defaultKeys = new Set(Object.keys(defaultObject) as (keyof T)[]);
const missingKeys = (Object.keys(object) as (keyof T)[]).filter(
key => !defaultKeys.has(key)
);
@ -53,3 +53,18 @@ export function getFontFaces() {
return results;
}
/**
* Picks certain keys from an object and returns a new object with only those keys.
*/
export function pick<T extends object>(object: T, keys: (keyof T)[]): Partial<T> {
const res = {} as Partial<T>;
for (const key of keys) {
if (key in object) {
res[key] = object[key];
}
}
return res;
}

View File

@ -8,7 +8,6 @@ import {
formatDuration,
intervalToDuration
} from 'date-fns';
import { sumBy } from 'lodash-es';
import { now } from '@/store';
import { i18n } from '@/plugins/i18n';
import { useDateFns } from '@/composables/use-datefns';
@ -120,7 +119,7 @@ export function getRuntimeTime(ticks: number): string {
export function getTotalEndsAtTime(
items: BaseItemDto[]
): string {
const aggregatedTicks = sumBy(items, 'RunTimeTicks');
const aggregatedTicks = items.reduce((acc, item) => acc + (item.RunTimeTicks ?? 0), 0);
return getEndsAtTime(aggregatedTicks);
}

25
package-lock.json generated
View File

@ -37,7 +37,6 @@
"hls.js": "1.5.15",
"jassub": "1.7.17",
"libpgs": "0.5.0",
"lodash-es": "4.17.21",
"marked": "14.1.0",
"sortablejs": "1.15.3",
"swiper": "11.1.12",
@ -57,7 +56,6 @@
"@rollup/plugin-virtual": "3.0.2",
"@stylistic/eslint-plugin": "2.6.2",
"@types/dompurify": "3.0.5",
"@types/lodash-es": "4.17.12",
"@types/node": "22.1.0",
"@types/sortablejs": "1.15.8",
"@types/uuid": "10.0.0",
@ -2522,23 +2520,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/@types/lodash": {
"version": "4.17.7",
"resolved": "https://registry.npmjs.org/@types/lodash/-/lodash-4.17.7.tgz",
"integrity": "sha512-8wTvZawATi/lsmNu10/j2hk1KEP0IvjubqPE3cu1Xz7xfXXt5oCq3SNUz4fMIP4XGF9Ky+Ue2tBA3hcS7LSBlA==",
"dev": true,
"license": "MIT"
},
"node_modules/@types/lodash-es": {
"version": "4.17.12",
"resolved": "https://registry.npmjs.org/@types/lodash-es/-/lodash-es-4.17.12.tgz",
"integrity": "sha512-0NgftHUcV4v34VhXm8QBSftKVXtbkBG3ViCjs6+eJ5a6y6Mi/jiFGPc1sC7QK+9BFhWrURE3EOggmWaSxL9OzQ==",
"dev": true,
"license": "MIT",
"dependencies": {
"@types/lodash": "*"
}
},
"node_modules/@types/node": {
"version": "22.1.0",
"resolved": "https://registry.npmjs.org/@types/node/-/node-22.1.0.tgz",
@ -7931,12 +7912,6 @@
"dev": true,
"license": "MIT"
},
"node_modules/lodash-es": {
"version": "4.17.21",
"resolved": "https://registry.npmjs.org/lodash-es/-/lodash-es-4.17.21.tgz",
"integrity": "sha512-mKnC+QJ9pWVzv+C4/U3rRsHapFfHvQFoFB92e52xeyGMcX6/OlIl78je1u8vePzYZSkkogMPJ2yjxxsb89cxyw==",
"license": "MIT"
},
"node_modules/lodash.merge": {
"version": "4.6.2",
"resolved": "https://registry.npmjs.org/lodash.merge/-/lodash.merge-4.6.2.tgz",