Big News: Socket raises $60M Series C at a $1B valuation to secure software supply chains for AI-driven development.Announcement
Sign In

@vant/markdown-vetur

Package Overview
Dependencies
Maintainers
4
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@vant/markdown-vetur - npm Package Compare versions

Comparing version
2.0.0
to
2.0.1
+58
lib/codegen.js
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const FLAG_REG = /(.*?)\s*(Props|Event)/i;
function camelCaseToKebabCase(input) {
return input.replace(/[A-Z]/g, (val, index) => (index === 0 ? '' : '-') + val.toLowerCase());
}
function removeVersionTag(str) {
return str.replace(/`(\w|\.)+`/g, '').trim();
}
function getDescription(td, isProp) {
const desc = td[1] ? td[1].replace('<br>', '') : '';
const type = td[2] ? td[2].replace(/\*/g, '') : '';
const defaultVal = td[3] ? td[3].replace(/`/g, '') : '';
if (isProp) {
return `${desc}, 默认值: ${defaultVal}, 类型: ${type}`;
}
return desc;
}
function codegen(artical) {
const tags = {};
let tagDescription = '';
for (let i = 0, len = artical.length; i < len; i++) {
const item = artical[i];
if (item.type === 'title' && item.level === 2) {
if (item.content) {
tagDescription = item.content;
}
}
else if (item.type === 'table') {
const before = artical[i - 1];
if (!before || !before.content) {
continue;
}
const { table } = item;
const match = FLAG_REG.exec(before.content);
if (!match || !table) {
continue;
}
const key = camelCaseToKebabCase(match[1] || 'default');
const tag = tags[key] || {
description: tagDescription,
attributes: {}
};
tags[key] = tag;
const isProp = /Props/i.test(match[2]);
table.body.forEach(td => {
const name = removeVersionTag(td[0]);
const attr = {
description: getDescription(td, isProp),
type: isProp ? td[2].replace(/`/g, '').toLowerCase() : 'event'
};
tag.attributes[name] = attr;
});
}
}
return tags;
}
exports.codegen = codegen;
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
/* eslint-disable no-cond-assign */
const TITLE_REG = /^(#+)\s+([^\n]*)/;
const TABLE_REG = /^\|.+\n\|\s*-+/;
const TD_REG = /\s*`[^`]+`\s*|([^|`]+)/g;
const TABLE_SPLIT_LINE_REG = /^\|\s*-/;
function readLine(input) {
const end = input.indexOf('\n');
return input.substr(0, end !== -1 ? end : input.length);
}
function splitTableLine(line) {
line = line.replace('\\|', 'JOIN');
const items = line.split('|').map(item => item.trim().replace('JOIN', '|'));
// remove pipe character on both sides
items.pop();
items.shift();
return items;
}
function tableParse(input) {
let start = 0;
let isHead = true;
const end = input.length;
const table = {
head: [],
body: []
};
while (start < end) {
const target = input.substr(start);
const line = readLine(target);
if (!/^\|/.test(target)) {
break;
}
if (TABLE_SPLIT_LINE_REG.test(target)) {
isHead = false;
}
else if (!isHead && line.includes('|')) {
const matched = line.trim().match(TD_REG);
if (matched) {
table.body.push(splitTableLine(line));
}
}
start += line.length + 1;
}
return {
table,
usedLength: start
};
}
function mdParser(input) {
const artical = [];
let start = 0;
const end = input.length;
while (start < end) {
const target = input.substr(start);
let match;
if ((match = TITLE_REG.exec(target))) {
artical.push({
type: 'title',
content: match[2],
level: match[1].length
});
start += match.index + match[0].length;
}
else if ((match = TABLE_REG.exec(target))) {
const { table, usedLength } = tableParse(target.substr(match.index));
artical.push({
type: 'table',
table
});
start += match.index + usedLength;
}
else {
start += readLine(target).length + 1;
}
}
return artical;
}
exports.mdParser = mdParser;
+2
-1

@@ -14,4 +14,5 @@ "use strict";

// *boolean* -> boolean
// _boolean_ -> boolean
function formatType(type) {
return type.replace(/\*/g, '');
return type.replace(/(^(\*|_))|((\*|_)$)/g, '');
}

@@ -18,0 +19,0 @@ exports.formatType = formatType;

{
"name": "@vant/markdown-vetur",
"version": "2.0.0",
"version": "2.0.1",
"description": "simple parse markdown to vue component description for vetur auto-completion",

@@ -5,0 +5,0 @@ "main": "lib/index.js",