X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=shared%2Fcore-utils%2Fcommon%2Farray.ts;h=e1b422165c00b0c884fe42f83a51c249b76be7fe;hb=99b757488c077cee7d0ab89eeec181a7ee6290eb;hp=9e326a5aa7590e4ab0dea051f240e2c4272a57c1;hpb=c55e3d7227fe1453869e309025996b9d75256d5d;p=github%2FChocobozzz%2FPeerTube.git diff --git a/shared/core-utils/common/array.ts b/shared/core-utils/common/array.ts index 9e326a5aa..e1b422165 100644 --- a/shared/core-utils/common/array.ts +++ b/shared/core-utils/common/array.ts @@ -8,6 +8,20 @@ function findCommonElement (array1: T[], array2: T[]) { return null } +// Avoid conflict with other toArray() functions +function arrayify (element: T | T[]) { + if (Array.isArray(element)) return element + + return [ element ] +} + +// Avoid conflict with other uniq() functions +function uniqify (elements: T[]) { + return Array.from(new Set(elements)) +} + export { - findCommonElement + uniqify, + findCommonElement, + arrayify }