Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/helpers/global.helper.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,16 @@
import { CSFDColorRating } from '../dto/global';
import { CSFDColors } from '../dto/user-ratings';

const langPrefixRegex = /^[a-z]{2,3}$/;
const iso8601DurationRegex =
/(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;

export const parseIdFromUrl = (url: string): number => {
if (!url) return null;

const parts = url.split('/');
// Detect language prefix like /en/ or /sk/
const hasLangPrefix = /^[a-z]{2,3}$/.test(parts[1]);
const hasLangPrefix = langPrefixRegex.test(parts[1]);
const idSlug = parts[hasLangPrefix ? 3 : 2];
const id = idSlug?.split('-')[0];
return +id || null;
Expand Down Expand Up @@ -60,9 +64,6 @@ export const getDuration = (matches: RegExpMatchArray) => {
};

export const parseISO8601Duration = (iso: string): number => {
const iso8601DurationRegex =
/(-)?P(?:([.,\d]+)Y)?(?:([.,\d]+)M)?(?:([.,\d]+)W)?(?:([.,\d]+)D)?T(?:([.,\d]+)H)?(?:([.,\d]+)M)?(?:([.,\d]+)S)?/;

const matches = iso.match(iso8601DurationRegex);

const duration = getDuration(matches);
Expand Down
2 changes: 2 additions & 0 deletions vitest.config.mts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { configDefaults, defineConfig } from 'vitest/config';

export default defineConfig({
test: {
testTimeout: 20000,
hookTimeout: 20000,
coverage: {
provider: 'istanbul',
exclude: [...configDefaults.exclude, 'demo.ts', '**/*.polyfill.ts', 'vars.ts', 'server.ts']
Expand Down