Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

components-helper

Package Overview
Dependencies
Maintainers
1
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

components-helper - npm Package Compare versions

Comparing version 1.0.2 to 1.0.3

75

lib/index.es.js

@@ -24,2 +24,3 @@ import { readFileSync, mkdir, writeFileSync } from 'fs';

slotsDescription: 'Description',
slotsSubtags: 'Subtags',
directives: 'directives',

@@ -51,5 +52,5 @@ directivesName: 'Name',

}
function getDocUrl(options, fileName, header) {
function getDocUrl(options, fileName, header, path) {
var reDocUrl = options.reDocUrl;
return isFunction(reDocUrl) ? reDocUrl(fileName, header) : undefined;
return isFunction(reDocUrl) ? reDocUrl(fileName, header, path) : undefined;
}

@@ -60,3 +61,7 @@

var _file = normalizeFile(file);
var titleContent = _file.match(new RegExp(titleRegExp));
var titleContent = _file.match(new RegExp(titleRegExp, 'g'));
var headers = titleContent
? titleContent.map(function (item) { return parseTitle(options, item); })
: undefined;
var topHeader = headers && headers.length ? headers[0] : undefined;
var tableContent = _file.match(new RegExp(tableRegExp, 'g'));

@@ -67,5 +72,6 @@ var table = tableContent

return {
title: titleContent ? titleContent[1].trim() : undefined,
description: titleContent ? titleContent[2].trim() : undefined,
title: topHeader ? topHeader.title : undefined,
description: topHeader ? topHeader.description : undefined,
table: table,
headers: headers,
};

@@ -122,2 +128,12 @@ }

}
function parseTitle(options, str) {
var titleRegExp = options.titleRegExp;
var titleContent = str.match(new RegExp(titleRegExp));
var title = titleContent ? titleContent[1].trim() : undefined;
var description = titleContent ? titleContent[2].trim() : undefined;
return {
title: title,
description: description,
};
}
function normalizeFile(file) {

@@ -192,5 +208,7 @@ return file.replace(/\r\n/g, '\n');

var _b;
var _c;
var data = _a.data, key = _a.key, item = _a.item, title = _a.title, path = _a.path, fileName = _a.fileName, regExp = _a.regExp;
var childTitle = title.replace(regExp, '').trim();
if (childTitle) {
var childHeader = (_c = data.headers) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.title === childTitle; });
var childItem = (_b = {

@@ -200,3 +218,3 @@ path: path,

title: childTitle,
description: childTitle === data.title ? data.description : undefined
description: childHeader === null || childHeader === void 0 ? void 0 : childHeader.description
},

@@ -224,3 +242,3 @@ _b[key] = item,

function vetur(options, list) {
var propsName = options.propsName, propsType = options.propsType, propsDescription = options.propsDescription, propsOptions = options.propsOptions, propsDefault = options.propsDefault, separator = options.separator, eventsName = options.eventsName, eventsDescription = options.eventsDescription;
var propsName = options.propsName, propsType = options.propsType, propsDescription = options.propsDescription, propsOptions = options.propsOptions, propsDefault = options.propsDefault, separator = options.separator, eventsName = options.eventsName, eventsDescription = options.eventsDescription, slotsSubtags = options.slotsSubtags, reVeturDescription = options.reVeturDescription;
var tagsList = {};

@@ -233,3 +251,5 @@ var propsList = {};

var _events = events ? events.content : [];
var _slots = slots ? slots.content : [];
var tagsProps = [];
var subtags = [];
if (children && children.length) {

@@ -245,2 +265,3 @@ var _b = vetur(options, children), tags = _b.tags, attributes = _b.attributes;

if (_item) {
var docUrl_1 = getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title, path);
var _name = name + '/' + _item;

@@ -252,2 +273,5 @@ var _type = item[propsType] || '';

: undefined;
var _description_1 = isFunction(reVeturDescription)
? reVeturDescription(item[propsDescription], item[propsDefault], docUrl_1)
: reDescription(item[propsDescription], item[propsDefault], docUrl_1);
tagsProps.push(_item);

@@ -257,3 +281,3 @@ propsList[_name] = {

options: _optionsList,
description: reDescription(options, fileName, item[propsDescription], props === null || props === void 0 ? void 0 : props.title, item[propsDefault]),
description: _description_1,
};

@@ -265,13 +289,31 @@ }

if (_item) {
var docUrl_2 = getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path);
var _name = name + '/' + _item;
var _description_2 = isFunction(reVeturDescription)
? reVeturDescription(item[eventsDescription], undefined, docUrl_2)
: reDescription(item[eventsDescription], undefined, docUrl_2);
tagsProps.push(_item);
propsList[_name] = {
type: 'event',
description: item[eventsDescription],
description: _description_2,
};
}
});
_slots.forEach(function (item) {
var _subtags = item[slotsSubtags];
var _subtagsList = _subtags
? _subtags.split(separator).map(function (item) { return item.trim(); })
: undefined;
if (_subtagsList) {
subtags = subtags.concat(_subtagsList);
}
});
var docUrl = getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path);
var _description = isFunction(reVeturDescription)
? reVeturDescription(description, undefined, docUrl)
: reDescription(description, undefined, docUrl);
tagsList[name] = {
attributes: checkArray(tagsProps),
description: reDescription(options, fileName, description, title),
subtags: checkArray(subtags),
description: _description,
};

@@ -284,4 +326,3 @@ };

}
function reDescription(options, fileName, description, header, defaultVal) {
var docUrl = getDocUrl(options, fileName, header);
function reDescription(description, defaultVal, docUrl) {
var str = description || '';

@@ -335,3 +376,3 @@ if (defaultVal) {

description: item[directivesDescription],
'doc-url': getDocUrl(options, fileName, directives === null || directives === void 0 ? void 0 : directives.title),
'doc-url': getDocUrl(options, fileName, directives === null || directives === void 0 ? void 0 : directives.title, path),
value: item[directivesType]

@@ -363,3 +404,3 @@ ? {

description: item[propsDescription],
'doc-url': getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title),
'doc-url': getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title, path),
default: item[propsDefault],

@@ -381,3 +422,3 @@ value: item[propsType]

description: item[eventsDescription],
'doc-url': getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title),
'doc-url': getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path),
});

@@ -392,3 +433,3 @@ }

description: item[slotsDescription],
'doc-url': getDocUrl(options, fileName, slots === null || slots === void 0 ? void 0 : slots.title),
'doc-url': getDocUrl(options, fileName, slots === null || slots === void 0 ? void 0 : slots.title, path),
});

@@ -400,3 +441,3 @@ }

description: description,
'doc-url': getDocUrl(options, fileName, title),
'doc-url': getDocUrl(options, fileName, title, path),
attributes: checkArray(propsList),

@@ -403,0 +444,0 @@ events: checkArray(eventsList),

@@ -21,2 +21,3 @@ (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports,require('fs'),require('path')):typeof define==='function'&&define.amd?define(['exports','fs','path'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.ComponentsHelper={},g.fs,g.path));}(this,(function(exports, fs, path){'use strict';var config = {

slotsDescription: 'Description',
slotsSubtags: 'Subtags',
directives: 'directives',

@@ -44,9 +45,13 @@ directivesName: 'Name',

}
function getDocUrl(options, fileName, header) {
function getDocUrl(options, fileName, header, path) {
var reDocUrl = options.reDocUrl;
return isFunction(reDocUrl) ? reDocUrl(fileName, header) : undefined;
return isFunction(reDocUrl) ? reDocUrl(fileName, header, path) : undefined;
}function parse(options, file) {
var titleRegExp = options.titleRegExp, tableRegExp = options.tableRegExp;
var _file = normalizeFile(file);
var titleContent = _file.match(new RegExp(titleRegExp));
var titleContent = _file.match(new RegExp(titleRegExp, 'g'));
var headers = titleContent
? titleContent.map(function (item) { return parseTitle(options, item); })
: undefined;
var topHeader = headers && headers.length ? headers[0] : undefined;
var tableContent = _file.match(new RegExp(tableRegExp, 'g'));

@@ -57,5 +62,6 @@ var table = tableContent

return {
title: titleContent ? titleContent[1].trim() : undefined,
description: titleContent ? titleContent[2].trim() : undefined,
title: topHeader ? topHeader.title : undefined,
description: topHeader ? topHeader.description : undefined,
table: table,
headers: headers,
};

@@ -112,2 +118,12 @@ }

}
function parseTitle(options, str) {
var titleRegExp = options.titleRegExp;
var titleContent = str.match(new RegExp(titleRegExp));
var title = titleContent ? titleContent[1].trim() : undefined;
var description = titleContent ? titleContent[2].trim() : undefined;
return {
title: title,
description: description,
};
}
function normalizeFile(file) {

@@ -180,5 +196,7 @@ return file.replace(/\r\n/g, '\n');

var _b;
var _c;
var data = _a.data, key = _a.key, item = _a.item, title = _a.title, path = _a.path, fileName = _a.fileName, regExp = _a.regExp;
var childTitle = title.replace(regExp, '').trim();
if (childTitle) {
var childHeader = (_c = data.headers) === null || _c === void 0 ? void 0 : _c.find(function (item) { return item.title === childTitle; });
var childItem = (_b = {

@@ -188,3 +206,3 @@ path: path,

title: childTitle,
description: childTitle === data.title ? data.description : undefined
description: childHeader === null || childHeader === void 0 ? void 0 : childHeader.description
},

@@ -210,3 +228,3 @@ _b[key] = item,

}function vetur(options, list) {
var propsName = options.propsName, propsType = options.propsType, propsDescription = options.propsDescription, propsOptions = options.propsOptions, propsDefault = options.propsDefault, separator = options.separator, eventsName = options.eventsName, eventsDescription = options.eventsDescription;
var propsName = options.propsName, propsType = options.propsType, propsDescription = options.propsDescription, propsOptions = options.propsOptions, propsDefault = options.propsDefault, separator = options.separator, eventsName = options.eventsName, eventsDescription = options.eventsDescription, slotsSubtags = options.slotsSubtags, reVeturDescription = options.reVeturDescription;
var tagsList = {};

@@ -219,3 +237,5 @@ var propsList = {};

var _events = events ? events.content : [];
var _slots = slots ? slots.content : [];
var tagsProps = [];
var subtags = [];
if (children && children.length) {

@@ -231,2 +251,3 @@ var _b = vetur(options, children), tags = _b.tags, attributes = _b.attributes;

if (_item) {
var docUrl_1 = getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title, path);
var _name = name + '/' + _item;

@@ -238,2 +259,5 @@ var _type = item[propsType] || '';

: undefined;
var _description_1 = isFunction(reVeturDescription)
? reVeturDescription(item[propsDescription], item[propsDefault], docUrl_1)
: reDescription(item[propsDescription], item[propsDefault], docUrl_1);
tagsProps.push(_item);

@@ -243,3 +267,3 @@ propsList[_name] = {

options: _optionsList,
description: reDescription(options, fileName, item[propsDescription], props === null || props === void 0 ? void 0 : props.title, item[propsDefault]),
description: _description_1,
};

@@ -251,13 +275,31 @@ }

if (_item) {
var docUrl_2 = getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path);
var _name = name + '/' + _item;
var _description_2 = isFunction(reVeturDescription)
? reVeturDescription(item[eventsDescription], undefined, docUrl_2)
: reDescription(item[eventsDescription], undefined, docUrl_2);
tagsProps.push(_item);
propsList[_name] = {
type: 'event',
description: item[eventsDescription],
description: _description_2,
};
}
});
_slots.forEach(function (item) {
var _subtags = item[slotsSubtags];
var _subtagsList = _subtags
? _subtags.split(separator).map(function (item) { return item.trim(); })
: undefined;
if (_subtagsList) {
subtags = subtags.concat(_subtagsList);
}
});
var docUrl = getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path);
var _description = isFunction(reVeturDescription)
? reVeturDescription(description, undefined, docUrl)
: reDescription(description, undefined, docUrl);
tagsList[name] = {
attributes: checkArray(tagsProps),
description: reDescription(options, fileName, description, title),
subtags: checkArray(subtags),
description: _description,
};

@@ -270,4 +312,3 @@ };

}
function reDescription(options, fileName, description, header, defaultVal) {
var docUrl = getDocUrl(options, fileName, header);
function reDescription(description, defaultVal, docUrl) {
var str = description || '';

@@ -319,3 +360,3 @@ if (defaultVal) {

description: item[directivesDescription],
'doc-url': getDocUrl(options, fileName, directives === null || directives === void 0 ? void 0 : directives.title),
'doc-url': getDocUrl(options, fileName, directives === null || directives === void 0 ? void 0 : directives.title, path),
value: item[directivesType]

@@ -347,3 +388,3 @@ ? {

description: item[propsDescription],
'doc-url': getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title),
'doc-url': getDocUrl(options, fileName, props === null || props === void 0 ? void 0 : props.title, path),
default: item[propsDefault],

@@ -365,3 +406,3 @@ value: item[propsType]

description: item[eventsDescription],
'doc-url': getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title),
'doc-url': getDocUrl(options, fileName, events === null || events === void 0 ? void 0 : events.title, path),
});

@@ -376,3 +417,3 @@ }

description: item[slotsDescription],
'doc-url': getDocUrl(options, fileName, slots === null || slots === void 0 ? void 0 : slots.title),
'doc-url': getDocUrl(options, fileName, slots === null || slots === void 0 ? void 0 : slots.title, path),
});

@@ -384,3 +425,3 @@ }

description: description,
'doc-url': getDocUrl(options, fileName, title),
'doc-url': getDocUrl(options, fileName, title, path),
attributes: checkArray(propsList),

@@ -387,0 +428,0 @@ events: checkArray(eventsList),

declare type ReComponentName = (title: string, fileName: string, path: string) => string;
declare type ReDocUrl = (fileName: string, header?: string) => string;
declare type ReDocUrl = (fileName: string, header?: string, path?: string) => string;
declare type ReAttribute = (value: string, key: string, columns: string[], title: string) => string | undefined;
declare type ReVeturDescription = (description?: string, defaultValue?: string, docUrl?: string) => string;
interface OptionsConfig {

@@ -13,2 +14,3 @@ entry: string;

reAttribute?: ReAttribute;
reVeturDescription?: ReVeturDescription;
}

@@ -35,2 +37,3 @@ export interface Config {

slotsDescription: string;
slotsSubtags: string;
directives: string;

@@ -43,2 +46,6 @@ directivesName: string;

export declare type Options = OptionsConfig & Config;
export interface ParseHeader {
title?: string;
description?: string;
}
export declare type ParseTableColumn = Record<string, string | undefined>;

@@ -53,2 +60,3 @@ export interface ParseTable {

table?: ParseTable[];
headers?: ParseHeader[];
}

@@ -67,2 +75,3 @@ export interface NormalizeData extends ParseData {

attributes?: string[];
subtags?: string[];
description?: string;

@@ -69,0 +78,0 @@ };

@@ -6,2 +6,2 @@ import type { Options } from './type';

export declare function getComponentsName(options: Options, title: string | undefined, fileName: string, path: string): string;
export declare function getDocUrl(options: Options, fileName: string, header?: string): string | undefined;
export declare function getDocUrl(options: Options, fileName: string, header?: string, path?: string): string | undefined;
{
"name": "components-helper",
"version": "1.0.2",
"version": "1.0.3",
"description": "Based on the docs to provide code prompt files for vue component library",

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

@@ -95,2 +95,9 @@ # components-helper

### reVeturDescription
- Type: `(description?: string, defaultValue?: string, docUrl?: string) => string`
- Default: same like `${description}, default: ${defaultValue}.\n\n[Docs](${docUrl})`
rewriting the description of vetur
### space

@@ -123,2 +130,9 @@

### separator
- Type: `string`
- Default: `/`
the separator for propsOptions and slotsSubtags
### props

@@ -159,9 +173,2 @@

### separator
- Type: `string`
- Default: `/`
name for props options separator
### propsDefault

@@ -216,2 +223,9 @@

### slotsSubtags
- Type: `string`
- Default: `Subtags`
name for slots header subtags
### directives

@@ -218,0 +232,0 @@

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc