Created
June 5, 2022 09:44
-
-
Save JanPlazovnik/aee052bf328000b9105600031e978da6 to your computer and use it in GitHub Desktop.
TypeScript implementation of the JSend specification
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface ApiResponse { | |
status: 'success' | 'fail' | 'error'; | |
data?: any; | |
message?: any; | |
} | |
export class jsend { | |
// https://github.com/omniti-labs/jsend | |
public static success(data: any): ApiResponse { | |
return { | |
status: 'success', | |
data, | |
}; | |
} | |
public static fail(data: any): ApiResponse { | |
return { | |
status: 'fail', | |
data, | |
}; | |
} | |
public static error(message: string | null, data?: any): ApiResponse { | |
return { | |
status: 'error', | |
message, | |
data, | |
}; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment