mirror of
https://github.com/20kaushik02/spotify-manager.git
synced 2026-01-25 06:04:05 +00:00
improved API request wrapper, partial completion of operations
This commit is contained in:
@@ -1,5 +1,7 @@
|
||||
export const sleep = (ms: number): Promise<unknown> =>
|
||||
const sleep = (ms: number): Promise<unknown> =>
|
||||
new Promise((resolve) => setTimeout(resolve, ms));
|
||||
|
||||
export const randomBool = (chance_of_failure = 0.25): boolean =>
|
||||
const randomBool = (chance_of_failure = 0.25): boolean =>
|
||||
Math.random() < chance_of_failure;
|
||||
|
||||
export { sleep, randomBool };
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
/**
|
||||
* Generates a random string containing numbers and letters
|
||||
*/
|
||||
export const generateRandString = (length: number): string => {
|
||||
const generateRandString = (length: number): string => {
|
||||
const possible =
|
||||
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
let text = "";
|
||||
@@ -11,3 +11,5 @@ export const generateRandString = (length: number): string => {
|
||||
}
|
||||
return text;
|
||||
};
|
||||
|
||||
export { generateRandString };
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
export type GNode = string;
|
||||
export type GEdge = { from: string; to: string };
|
||||
type GNode = string;
|
||||
type GEdge = { from: string; to: string };
|
||||
|
||||
/**
|
||||
* Directed graph, may or may not be connected.
|
||||
@@ -20,7 +20,7 @@ export type GEdge = { from: string; to: string };
|
||||
* console.log(g.detectCycle()); // true
|
||||
* ```
|
||||
*/
|
||||
export class myGraph {
|
||||
class myGraph {
|
||||
nodes: GNode[];
|
||||
edges: GEdge[];
|
||||
/**
|
||||
@@ -135,4 +135,5 @@ export class myGraph {
|
||||
}
|
||||
}
|
||||
|
||||
export { type GNode, type GEdge, myGraph };
|
||||
export default myGraph;
|
||||
|
||||
@@ -1,8 +1,5 @@
|
||||
/** Stringifies only values of a JSON object, including nested ones */
|
||||
export const getNestedValuesString = (
|
||||
obj: any,
|
||||
delimiter: string = ", "
|
||||
): string => {
|
||||
const getNestedValuesString = (obj: any, delimiter: string = ", "): string => {
|
||||
let values: string[] = [];
|
||||
for (const key in obj) {
|
||||
if (typeof obj[key] !== "object") {
|
||||
@@ -14,3 +11,5 @@ export const getNestedValuesString = (
|
||||
|
||||
return values.join(delimiter);
|
||||
};
|
||||
|
||||
export { getNestedValuesString };
|
||||
|
||||
@@ -54,12 +54,16 @@ const winstonLogger: Logger = createLogger({
|
||||
new transports.File({
|
||||
filename: path.join(import.meta.dirname, "..", "logs", "error.log"),
|
||||
level: "error",
|
||||
maxsize: 1048576,
|
||||
}),
|
||||
],
|
||||
});
|
||||
winstonLogger.on("error", (error) =>
|
||||
winstonLogger.error("Error inside logger", { error })
|
||||
);
|
||||
winstonLogger.exceptions.handle(
|
||||
new transports.File({
|
||||
filename: path.join(import.meta.dirname, "..", "logs", "exceptions.log"),
|
||||
})
|
||||
);
|
||||
|
||||
export default winstonLogger;
|
||||
|
||||
@@ -4,7 +4,7 @@ const base62Pattern: RegExp = /^[A-Za-z0-9]+$/;
|
||||
|
||||
/**
|
||||
* Returns type and ID from a Spotify URI
|
||||
* @see {@link https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids|Spotify URIs and IDs}
|
||||
* @see {@link https://web.archive.org/web/20250313174409/https://developer.spotify.com/documentation/web-api/concepts/spotify-uris-ids|Spotify URIs and IDs}
|
||||
* @param uri Spotify URI - can be of an album, track, playlist, user, episode, etc.
|
||||
* @throws {TypeError} If the input is not a valid Spotify URI
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user