refactor: enforce 800 line source limits
This commit is contained in:
33
web/src/utils/aiDocumentQueryText.js
Normal file
33
web/src/utils/aiDocumentQueryText.js
Normal file
@@ -0,0 +1,33 @@
|
||||
export function normalizeText(value) {
|
||||
return String(value ?? '').trim()
|
||||
}
|
||||
|
||||
export function compactText(value) {
|
||||
return normalizeText(value).replace(/\s+/g, '')
|
||||
}
|
||||
|
||||
export function normalizeDateText(value) {
|
||||
const text = normalizeText(value)
|
||||
const matched = text.match(/^(\d{4})[-/.年](\d{1,2})[-/.月](\d{1,2})/)
|
||||
if (!matched) {
|
||||
return ''
|
||||
}
|
||||
return [
|
||||
matched[1],
|
||||
String(matched[2]).padStart(2, '0'),
|
||||
String(matched[3]).padStart(2, '0')
|
||||
].join('-')
|
||||
}
|
||||
|
||||
export function parseDate(value) {
|
||||
const text = normalizeDateText(value)
|
||||
if (!text) {
|
||||
return null
|
||||
}
|
||||
const date = new Date(`${text}T00:00:00Z`)
|
||||
return Number.isNaN(date.getTime()) ? null : date
|
||||
}
|
||||
|
||||
export function formatDate(date) {
|
||||
return date.toISOString().slice(0, 10)
|
||||
}
|
||||
Reference in New Issue
Block a user