mirror of
				https://github.com/zadam/trilium.git
				synced 2025-11-04 05:28:59 +01:00 
			
		
		
		
	
		
			
				
	
	
		
			37 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
			
		
		
	
	
			37 lines
		
	
	
		
			1.2 KiB
		
	
	
	
		
			TypeScript
		
	
	
	
	
	
import type { DefinitionObject } from "./promoted_attribute_definition_interface.js";
 | 
						|
 | 
						|
function parse(value: string): DefinitionObject {
 | 
						|
    const tokens = value.split(",").map((t) => t.trim());
 | 
						|
    const defObj: DefinitionObject = {};
 | 
						|
 | 
						|
    for (const token of tokens) {
 | 
						|
        if (token === "promoted") {
 | 
						|
            defObj.isPromoted = true;
 | 
						|
        } else if (["text", "number", "boolean", "date", "datetime", "time", "url"].includes(token)) {
 | 
						|
            defObj.labelType = token;
 | 
						|
        } else if (["single", "multi"].includes(token)) {
 | 
						|
            defObj.multiplicity = token;
 | 
						|
        } else if (token.startsWith("precision")) {
 | 
						|
            const chunks = token.split("=");
 | 
						|
 | 
						|
            defObj.numberPrecision = parseInt(chunks[1]);
 | 
						|
        } else if (token.startsWith("alias")) {
 | 
						|
            const chunks = token.split("=");
 | 
						|
 | 
						|
            defObj.promotedAlias = chunks[1];
 | 
						|
        } else if (token.startsWith("inverse")) {
 | 
						|
            const chunks = token.split("=");
 | 
						|
 | 
						|
            defObj.inverseRelation = chunks[1].replace(/[^\p{L}\p{N}_:]/gu, "");
 | 
						|
        } else {
 | 
						|
            console.log("Unrecognized attribute definition token:", token);
 | 
						|
        }
 | 
						|
    }
 | 
						|
 | 
						|
    return defObj;
 | 
						|
}
 | 
						|
 | 
						|
export default {
 | 
						|
    parse
 | 
						|
};
 |