Skip to content

Commit

Permalink
feat: new types
Browse files Browse the repository at this point in the history
  • Loading branch information
netlob committed Mar 12, 2024
1 parent 5012617 commit 3fac792
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 6 deletions.
27 changes: 21 additions & 6 deletions src/interfaces/statsfm/stream.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ export interface StreamMinified {
h: number;
i: number[];
j?: number;
k?: number;
l?: number;
k?: number | string;
l?: number | string;
m?: string;
}

Expand All @@ -38,8 +38,8 @@ export const streamToStreamMinified = (stream: Stream): Omit<StreamMinified, 'a'
g: stream.trackName,
h: stream.albumId,
i: stream.artistIds,
k: stream.trackReleaseId ?? undefined,
l: stream.albumReleaseId ?? undefined,
k: tryParseInt(stream.trackReleaseId),
l: tryParseInt(stream.trackReleaseId),
m: stream.contextId ?? undefined
};
if ('importId' in stream) obj.j = stream.importId;
Expand All @@ -56,10 +56,25 @@ export const streamMinifiedToStream = (stream: StreamMinified): Stream => {
trackName: stream.g,
albumId: stream.h,
artistIds: stream.i,
trackReleaseId: stream.k ?? undefined,
albumReleaseId: stream.l ?? undefined,
trackReleaseId: tryParseInt(stream.k),
albumReleaseId: tryParseInt(stream.l),
contextId: stream.m ?? undefined
};
if ('j' in stream) obj.importId = stream.j;
return obj;
};

export const tryParseInt = (str: string | number | null | undefined): number | null => {
try {
if(typeof str === 'number') return str;

if (str === null || str === undefined || str.trim() === '') {
return undefined;
}

const parsedInt = parseInt(str);
return isNaN(parsedInt) ? null : parsedInt;
} catch (e) {
return undefined;
}
};
1 change: 1 addition & 0 deletions src/interfaces/statsfm/v2/artist.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ export interface Artist {

spotifyId?: string;
spotifyPopularity?: number;
spotifyFollowers?: number;
spotifyFetchedAt?: Date;

appleMusicId?: string;
Expand Down

0 comments on commit 3fac792

Please sign in to comment.