Tafar commited on
Commit
b38418d
·
1 Parent(s): 0a764cc

Upload 2 files

Browse files
service_src_utils_index.ts ADDED
@@ -0,0 +1,22 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ interface SendResponseOptions<T = any> {
2
+ type: 'Success' | 'Fail'
3
+ message?: string
4
+ data?: T
5
+ }
6
+
7
+ export function sendResponse<T>(options: SendResponseOptions<T>) {
8
+ if (options.type === 'Success') {
9
+ return Promise.resolve({
10
+ message: options.message ?? null,
11
+ data: options.data ?? null,
12
+ status: options.type,
13
+ })
14
+ }
15
+
16
+ // eslint-disable-next-line prefer-promise-reject-errors
17
+ return Promise.reject({
18
+ message: options.message ?? 'Failed',
19
+ data: options.data ?? null,
20
+ status: options.type,
21
+ })
22
+ }
service_src_utils_is.ts ADDED
@@ -0,0 +1,19 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ export function isNumber<T extends number>(value: T | unknown): value is number {
2
+ return Object.prototype.toString.call(value) === '[object Number]'
3
+ }
4
+
5
+ export function isString<T extends string>(value: T | unknown): value is string {
6
+ return Object.prototype.toString.call(value) === '[object String]'
7
+ }
8
+
9
+ export function isNotEmptyString(value: any): boolean {
10
+ return typeof value === 'string' && value.length > 0
11
+ }
12
+
13
+ export function isBoolean<T extends boolean>(value: T | unknown): value is boolean {
14
+ return Object.prototype.toString.call(value) === '[object Boolean]'
15
+ }
16
+
17
+ export function isFunction<T extends (...args: any[]) => any | void | never>(value: T | unknown): value is T {
18
+ return Object.prototype.toString.call(value) === '[object Function]'
19
+ }