mirror of
https://github.com/zadam/trilium.git
synced 2025-11-08 07:28:59 +01: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 tokens = value.split(',').map(t => t.trim());
|
||||||
const defObj = {};
|
const defObj: DefinitionObject = {};
|
||||||
|
|
||||||
for (const token of tokens) {
|
for (const token of tokens) {
|
||||||
if (token === 'promoted') {
|
if (token === 'promoted') {
|
||||||
defObj.isPromoted = true;
|
defObj.isPromoted = true;
|
||||||
}
|
}
|
||||||
else if (['text', 'number', 'boolean', 'date', 'datetime', 'url'].includes(token)) {
|
else if (['text', 'number', 'boolean', 'date', 'datetime', 'url'].includes(token)) {
|
||||||
defObj.labelType = token;
|
defObj.labelType = token as LabelType;
|
||||||
}
|
}
|
||||||
else if (['single', 'multi'].includes(token)) {
|
else if (['single', 'multi'].includes(token)) {
|
||||||
defObj.multiplicity = token;
|
defObj.multiplicity = token as Multiplicity;
|
||||||
}
|
}
|
||||||
else if (token.startsWith('precision')) {
|
else if (token.startsWith('precision')) {
|
||||||
const chunks = token.split('=');
|
const chunks = token.split('=');
|
||||||
Loading…
x
Reference in New Issue
Block a user