@themezernx/layout-id-parser
Advanced tools
Comparing version 1.0.4 to 1.1.0
export declare const parseID: (ID: any) => { | ||
service: string; | ||
id: string; | ||
piece_uuids: string[]; | ||
piece_variables: any; | ||
optionUuids: string[]; | ||
}; | ||
export declare const stringifyID: ({ service, id, piece_uuids, piece_variables, }: { | ||
export declare const stringifyID: ({ service, id, optionUuids, }: { | ||
service?: string; | ||
id: string; | ||
piece_uuids?: string[]; | ||
piece_variables?: any; | ||
optionUuids?: string[]; | ||
}) => string; | ||
export declare const getDefaultID: (target: string) => string; |
@@ -70,7 +70,6 @@ "use strict"; | ||
ID = converted; | ||
var no_comments = ID.replace(/\(.*?\)/gm, ""); | ||
var service = null; | ||
var data = null; | ||
var split1 = no_comments.split(":"); | ||
if (no_comments.includes(":")) { | ||
var split1 = ID.split(":"); | ||
if (ID.includes(":")) { | ||
service = split1[0]; | ||
@@ -84,14 +83,7 @@ data = split1[1]; | ||
var id = split2[0]; | ||
var pieces = (split2[1] || "").split(",").filter(function (p) { return p !== ""; }); | ||
var piece_variables = {}; | ||
var piece_uuids = pieces.map(function (piece) { | ||
var json = piece.match(/{.+}/m); | ||
piece_variables[piece] = json ? JSON.parse(json[0]) : null; | ||
return piece.replace(/{.+}/m, ""); | ||
}); | ||
var optionUuids = (split2[1] || "").split(",").filter(function (p) { return p !== ""; }); | ||
return { | ||
service: service, | ||
id: id, | ||
piece_uuids: piece_uuids, | ||
piece_variables: piece_variables | ||
optionUuids: optionUuids | ||
}; | ||
@@ -101,8 +93,4 @@ }; | ||
var stringifyID = function (_a) { | ||
var _b = _a.service, service = _b === void 0 ? "" : _b, _c = _a.id, id = _c === void 0 ? "" : _c, _d = _a.piece_uuids, piece_uuids = _d === void 0 ? [] : _d, _e = _a.piece_variables, piece_variables = _e === void 0 ? {} : _e; | ||
var pieces = piece_uuids.map(function (uuid) { | ||
var pv = piece_variables[uuid]; | ||
return uuid + (pv ? JSON.stringify(pv) : ""); | ||
}); | ||
var ID = service + ":" + id + (pieces.length > 0 ? "|" + pieces.join() : ""); | ||
var _b = _a.service, service = _b === void 0 ? "" : _b, _c = _a.id, id = _c === void 0 ? "" : _c, _d = _a.optionUuids, optionUuids = _d === void 0 ? [] : _d; | ||
var ID = service + ":" + id + (optionUuids.length > 0 ? "|" + optionUuids.join() : ""); | ||
var converted = convertID.getReverse(ID); | ||
@@ -109,0 +97,0 @@ if (converted) |
{ | ||
"name": "@themezernx/layout-id-parser", | ||
"version": "1.0.4", | ||
"version": "1.1.0", | ||
"description": "Simple module to parse the ID string in a layout.", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/ThemezerNX/Layout-ID-Parser.git", |
@@ -13,2 +13,4 @@ # Layout ID Parser | ||
// --> {service: "Themezer", id: "3", piece_uuids: ["b77b434f-5811-42fc-bd5e-ab44d7f24b61"]} | ||
console.log(parseID("Themezer:3|b77b434f-5811-42fc-bd5e-ab44d7f24b61, adfasdff-5811-42fc-bd5e-ab44d7f24b61")); | ||
// --> {service: "Themezer", id: "3", piece_uuids: ["b77b434f-5811-42fc-bd5e-ab44d7f24b61", "adfasdff-5811-42fc-bd5e-ab44d7f24b61"]} | ||
@@ -15,0 +17,0 @@ // Parse an Object to a layout ID string |
40
5922
123