chore:little fixes and formating and linting and patches

This commit is contained in:
2026-03-31 15:50:54 +02:00
parent a1ce71ffb6
commit 9b197abcfa
815 changed files with 22960 additions and 8982 deletions

View File

@@ -1,12 +1,10 @@
import { isNil } from 'ramda';
import type { PreviousValue } from '@openpanel/validation';
import { isNil } from 'ramda';
import { round } from './math';
export function getPreviousMetric(
current: number,
previous: number | null | undefined,
previous: number | null | undefined
): PreviousValue {
if (isNil(previous)) {
return undefined;
@@ -20,7 +18,7 @@ export function getPreviousMetric(
: 0) -
1) *
100,
1,
1
);
return {

View File

@@ -54,7 +54,7 @@ export function groupByLabels(data: ISerieDataItem[]): GroupedResult[] {
const result = Array.from(groupedMap.values()).map((group) => ({
...group,
data: group.data.sort(
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime(),
(a, b) => new Date(a.date).getTime() - new Date(b.date).getTime()
),
}));

View File

@@ -11,7 +11,7 @@ export const average = (arr: (number | null)[], includeZero = false) => {
isNumber(n) &&
!Number.isNaN(n) &&
Number.isFinite(n) &&
(includeZero || n !== 0),
(includeZero || n !== 0)
);
const avg = filtered.reduce((p, c) => p + c, 0) / filtered.length;
return Number.isNaN(avg) ? 0 : avg;
@@ -22,13 +22,17 @@ export const sum = (arr: (number | null | undefined)[]): number =>
export const min = (arr: (number | null | undefined)[]): number => {
const filtered = arr.filter(isNumber);
if (filtered.length === 0) return 0;
if (filtered.length === 0) {
return 0;
}
return filtered.reduce((a, b) => (b < a ? b : a), filtered[0]!);
};
export const max = (arr: (number | null | undefined)[]): number => {
const filtered = arr.filter(isNumber);
if (filtered.length === 0) return 0;
if (filtered.length === 0) {
return 0;
}
return filtered.reduce((a, b) => (b > a ? b : a), filtered[0]!);
};
@@ -36,5 +40,5 @@ export const isFloat = (n: number) => n % 1 !== 0;
export const ifNaN = <T extends number>(
n: number | null | undefined,
defaultValue: T,
defaultValue: T
): T => (Number.isNaN(n) ? defaultValue : (n as T));

View File

@@ -10,7 +10,7 @@ describe('toDots', () => {
arrayWithObjects: [{ a: 1 }, { b: 2 }, { c: 3 }],
objectWithArrays: { a: [1, 2, 3] },
null: null,
undefined: undefined,
undefined,
empty: '',
jsonString: '{"a": 1, "b": 2}',
};

View File

@@ -15,7 +15,7 @@ function isMalformedJsonString(value: string): boolean {
export function toDots(
obj: Record<string, unknown>,
path = '',
path = ''
): Record<string, string> {
// Clickhouse breaks on insert if a property contains invalid surrogate pairs
function removeInvalidSurrogates(value: string): string {
@@ -67,7 +67,7 @@ export function toDots(
}
export function toObject(
obj: Record<string, string | undefined>,
obj: Record<string, string | undefined>
): Record<string, unknown> {
let result: Record<string, unknown> = {};
Object.entries(obj).forEach(([key, value]) => {

View File

@@ -4,7 +4,7 @@ import { slug } from './slug';
describe('slug', () => {
it('should remove pipes from string', () => {
expect(slug('Hello || World, | Test å å ä ä')).toBe(
'hello-world-test-a-a-a-a',
'hello-world-test-a-a-a-a'
);
});
});

View File

@@ -10,7 +10,7 @@ const slugify = (str: string) => {
.replaceAll('Ä', 'A')
.replaceAll('Ö', 'O')
.replace(/\|+/g, '-'),
{ lower: true, strict: true, trim: true },
{ lower: true, strict: true, trim: true }
);
};

View File

@@ -1,5 +1,5 @@
export function parseSearchParams(
params: URLSearchParams,
params: URLSearchParams
): Record<string, string> | undefined {
const result: Record<string, string> = {};
for (const [key, value] of params.entries()) {
@@ -25,7 +25,7 @@ export function parsePath(path?: string): {
// If path does not have a leading /,
// its probably a named route
if (!path.startsWith('/') && !hasOrigin) {
if (!(path.startsWith('/') || hasOrigin)) {
return {
path,
origin: '',
@@ -50,9 +50,9 @@ export function parsePath(path?: string): {
export function isSameDomain(
url1: string | undefined,
url2: string | undefined,
url2: string | undefined
) {
if (!url1 || !url2) {
if (!(url1 && url2)) {
return false;
}
try {