merge ui
This commit is contained in:
10
frontend/src/utils/date/converters.util.ts
Normal file
10
frontend/src/utils/date/converters.util.ts
Normal file
@@ -0,0 +1,10 @@
|
||||
const getFullTimestamp = (n: number): number => {
|
||||
const length = String(n).length
|
||||
let str = ''
|
||||
while (str.length + length < 13) {
|
||||
str += '0'
|
||||
}
|
||||
return parseInt(`${n}${str}`)
|
||||
}
|
||||
export const toDate = (n: number) => new Date(getFullTimestamp(n))
|
||||
export const toTimestamp = (d: Date) => d.getTime()
|
||||
6
frontend/src/utils/date/getters.ts
Normal file
6
frontend/src/utils/date/getters.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const getTomorrow = (): Date => {
|
||||
const today = new Date();
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(today.getDate() + 1);
|
||||
return tomorrow;
|
||||
}
|
||||
27
frontend/src/utils/structs/defaults.util.ts
Normal file
27
frontend/src/utils/structs/defaults.util.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import type { IEntity } from "../../types/entity.type";
|
||||
import type { Scheme } from "../../types/scheme.type";
|
||||
import { getTomorrow } from "../date/getters";
|
||||
|
||||
export const getDefaultValues = <T extends IEntity>(scheme: Scheme<T>) => {
|
||||
const keys = Object.keys(scheme) as (keyof typeof scheme)[]
|
||||
let obj: any = {}
|
||||
|
||||
for (let key of keys) {
|
||||
const primitive = scheme[key]?.type?.primitive
|
||||
if (primitive == 'string' || primitive == 'multiple') {
|
||||
obj[key] = ''
|
||||
} else if (primitive == 'date') {
|
||||
obj[key] = getTomorrow()
|
||||
} else if (primitive == 'boolean') {
|
||||
obj[key] = false
|
||||
} else if (primitive == 'number') {
|
||||
obj[key] = 1
|
||||
} else if (scheme[key].type?.many) {
|
||||
obj[key] = []
|
||||
} else if (scheme[key]?.type?.nested?.values) {
|
||||
obj[key] = scheme[key].type.nested.values[0]
|
||||
}
|
||||
}
|
||||
|
||||
return obj as T
|
||||
}
|
||||
18
frontend/src/utils/structs/structs-view.util.ts
Normal file
18
frontend/src/utils/structs/structs-view.util.ts
Normal file
@@ -0,0 +1,18 @@
|
||||
export const structView = (item: any, path: any) => {
|
||||
if (!item) return;
|
||||
if (!path?.length) return item;
|
||||
let result = item
|
||||
let i = 0
|
||||
let current
|
||||
while (current != path[path.length - 1] && result) {
|
||||
current = path[i]
|
||||
result = result[current]
|
||||
i++
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
export const manyStructsView = (items: any, path: any) => {
|
||||
if (!Array.isArray(items)) return structView(items, path);
|
||||
return items.map(item => structView(item, path)).join(", ")
|
||||
}
|
||||
1
frontend/src/utils/sugar/if-null.util.ts
Normal file
1
frontend/src/utils/sugar/if-null.util.ts
Normal file
@@ -0,0 +1 @@
|
||||
export const ifNull = (data: any, elseData: any) => data? data : elseData
|
||||
Reference in New Issue
Block a user