mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-11-02 05:51:30 +08:00
client-ts: Port services/promoted_attribute_definition_parser
This commit is contained in:
parent
3fbedfb0a1
commit
81327a09d5
@ -1,16 +1,28 @@
|
||||
function parse(value) {
|
||||
type LabelType = "text" | "number" | "boolean" | "date" | "datetime" | "url";
|
||||
type Multiplicity = "single" | "multi";
|
||||
|
||||
interface DefinitionObject {
|
||||
isPromoted?: boolean;
|
||||
labelType?: LabelType;
|
||||
multiplicity?: Multiplicity;
|
||||
numberPrecision?: number;
|
||||
promotedAlias?: string;
|
||||
inverseRelation?: string;
|
||||
}
|
||||
|
||||
function parse(value: string) {
|
||||
const tokens = value.split(',').map(t => t.trim());
|
||||
const defObj = {};
|
||||
const defObj: DefinitionObject = {};
|
||||
|
||||
for (const token of tokens) {
|
||||
if (token === 'promoted') {
|
||||
defObj.isPromoted = true;
|
||||
}
|
||||
else if (['text', 'number', 'boolean', 'date', 'datetime', 'url'].includes(token)) {
|
||||
defObj.labelType = token;
|
||||
defObj.labelType = token as LabelType;
|
||||
}
|
||||
else if (['single', 'multi'].includes(token)) {
|
||||
defObj.multiplicity = token;
|
||||
defObj.multiplicity = token as Multiplicity;
|
||||
}
|
||||
else if (token.startsWith('precision')) {
|
||||
const chunks = token.split('=');
|
||||
Loading…
x
Reference in New Issue
Block a user