@connectv/marked
Version:
component-based markdown renderer
63 lines • 1.77 kB
JavaScript
function normalize(x) {
x = x.trim();
if ((x.startsWith('"') && x.endsWith('"')) ||
(x.startsWith('`') && x.endsWith('`')) ||
(x.startsWith("'") && x.endsWith("'")))
x = x.substr(1, x.length - 2);
return x.trim();
}
export function extractCompProps(propString) {
const props = {};
let mode = 'key';
let curr = undefined;
let currkey = undefined;
let strmark = undefined;
for (let c of propString) {
if (strmark) {
if (c === strmark) {
curr += c;
strmark = undefined;
}
else
curr += c;
}
else {
if (c === '"' || c === '`' || c === "'") {
strmark = c;
curr = curr || '';
curr += c;
}
else if (c === '=') {
if (mode === 'key') {
currkey = curr;
curr = undefined;
mode = 'value';
}
else {
curr = curr || '';
curr += c;
}
}
else if (c === ',') {
if (mode === 'value') {
props[normalize(currkey || '')] = normalize(curr || '');
curr = undefined;
mode = 'key';
}
else {
curr = curr || '';
curr += c;
}
}
else {
curr = curr || '';
curr += c;
}
}
}
if (currkey) {
props[normalize(currkey)] = normalize(curr || '');
}
return props;
}
//# sourceMappingURL=extract-comp-props.js.map