components-helper
Advanced tools
Comparing version 1.0.5 to 2.0.0
# Changelog | ||
### 2.0.0 | ||
feat | ||
- export all function | ||
- use matchAll replace match | ||
- add RegExp for `titleRegExp` `tableRegExp` and `fileNameRegExp` | ||
#### migration guide | ||
``` diff | ||
- const helper = require('../lib/index') | ||
+ const helper = require('../lib/index').default | ||
# or | ||
- const helper = require('../lib/index') | ||
+ const { main } = require('../lib/index') | ||
``` | ||
It is recommended to replace regular strings with RegExp | ||
``` diff | ||
{ | ||
- titleRegExp: '#+\\s+(.*)\\n+([^(#|\\n)]*)', | ||
+ titleRegExp: /#+\s+(.*)\n+([^(#|\n)]*)/g, | ||
- titleRegExp: '#+\\s+(.*)\\n+>\\s\*([^(#|\\n)]*)', | ||
+ titleRegExp: /#+\s+(.*)\n+>\s\*([^(#|\n)]*)/g, | ||
- tableRegExp: '#+\\s+(.*)\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)', | ||
+ tableRegExp: /#+\s+(.*)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g, | ||
- tableRegExp: '#+\\s+(.*\\s*Props|.*\\s*Events|.*\\s*Slots|.*\\s*Directives)\\s*\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)', | ||
+ tableRegExp: /#+\s+(.*\s*Props|.*\s*Events|.*\s*Slots|.*\s*Directives)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g, | ||
- fileNameRegExp: '\\/((\\w|-)+)\\.\\w+$', | ||
+ fileNameRegExp: /\/((\w|-)+)\.\w+$/, | ||
} | ||
``` | ||
### 1.0.5 | ||
@@ -4,0 +43,0 @@ |
import type { Config } from './type'; | ||
declare const config: Config; | ||
export default config; | ||
export declare const config: Config; |
@@ -1,4 +0,10 @@ | ||
import type { InstallOptions } from './type'; | ||
declare const main: (options?: InstallOptions) => void; | ||
import { main } from './main'; | ||
export * from './main'; | ||
export * from './read'; | ||
export * from './parse'; | ||
export * from './normalize'; | ||
export * from './vetur'; | ||
export * from './webTypes'; | ||
export * from './write'; | ||
export * from './type'; | ||
export default main; |
@@ -5,5 +5,5 @@ import fg from'fast-glob';import {readFileSync,mkdir,writeFileSync}from'fs';import {resolve}from'path';var config = { | ||
webTypes: 'web-types.json', | ||
titleRegExp: '#+\\s+(.*)\\n+([^(#|\\n)]*)', | ||
tableRegExp: '#+\\s+(.*)\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)', | ||
fileNameRegExp: '\\/((\\w|-)+)\\.\\w+$', | ||
titleRegExp: /#+\s+(.*)\n+([^(#|\n)]*)/g, | ||
tableRegExp: /#+\s+(.*)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g, | ||
fileNameRegExp: /\/((\w|-)+)\.\w+$/, | ||
separator: '/', | ||
@@ -35,2 +35,5 @@ props: 'props', | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
@@ -40,2 +43,5 @@ function isFunction(val) { | ||
} | ||
function normalizeFile(file) { | ||
return file.replace(/\r\n/g, '\n'); | ||
} | ||
function getComponentsName(options, title, fileName, path) { | ||
@@ -75,13 +81,6 @@ if (title === void 0) { title = ''; } | ||
}function parse(options, file) { | ||
var titleRegExp = options.titleRegExp, tableRegExp = options.tableRegExp; | ||
var _file = normalizeFile(file); | ||
var titleContent = _file.match(new RegExp(titleRegExp, 'g')); | ||
var headers = titleContent | ||
? titleContent.map(function (item) { return parseTitle(options, item); }) | ||
: undefined; | ||
var headers = parseTitle(options, _file); | ||
var topHeader = headers && headers.length ? headers[0] : undefined; | ||
var tableContent = _file.match(new RegExp(tableRegExp, 'g')); | ||
var table = tableContent | ||
? tableContent.map(function (item) { return parseTable(options, item); }) | ||
: undefined; | ||
var table = parseTable(options, _file); | ||
return { | ||
@@ -94,16 +93,29 @@ title: topHeader ? topHeader.title : undefined, | ||
} | ||
function parseTitle(options, str) { | ||
var titleRegExp = options.titleRegExp; | ||
var _titleRegExp = isString(titleRegExp) | ||
? new RegExp(titleRegExp, 'g') | ||
: titleRegExp; | ||
var titleContent = str.matchAll(_titleRegExp); | ||
return Array.from(titleContent, function (item) { return ({ | ||
title: item[1].trim(), | ||
description: item[2].trim(), | ||
}); }); | ||
} | ||
function parseTable(options, str) { | ||
var tableRegExp = options.tableRegExp; | ||
var tableContent = str.match(new RegExp(tableRegExp)); | ||
var title = tableContent ? tableContent[1] : ''; | ||
var header = tableContent ? parseRow(tableContent[2]) : undefined; | ||
var columns = tableContent ? tableContent[3] : undefined; | ||
var content = []; | ||
if (header && columns) { | ||
content = parseColumns(options, title, header, columns); | ||
} | ||
return { | ||
title: title, | ||
content: content, | ||
}; | ||
var _tableRegExp = isString(tableRegExp) | ||
? new RegExp(tableRegExp, 'g') | ||
: tableRegExp; | ||
var tableContent = str.matchAll(_tableRegExp); | ||
return Array.from(tableContent, function (item) { | ||
var title = item ? item[1] : ''; | ||
var header = item ? parseRow(item[2]) : undefined; | ||
var columns = item ? item[3] : undefined; | ||
var content = []; | ||
if (header && columns) { | ||
content = parseColumns(options, title, header, columns); | ||
} | ||
return { title: title, content: content }; | ||
}); | ||
} | ||
@@ -143,18 +155,8 @@ function parseRow(str) { | ||
return columns; | ||
} | ||
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) { | ||
return file.replace(/\r\n/g, '\n'); | ||
}function normalize(options, data, path) { | ||
var fileNameRegExp = options.fileNameRegExp, props = options.props, events = options.events, slots = options.slots, directives = options.directives; | ||
var _path = path.match(new RegExp(fileNameRegExp)); | ||
var _fileNameRegExp = isString(fileNameRegExp) | ||
? new RegExp(fileNameRegExp) | ||
: fileNameRegExp; | ||
var _path = path.match(_fileNameRegExp); | ||
var fileName = _path ? _path[1] : ''; | ||
@@ -449,3 +451,3 @@ var _data = Object.assign(data, { path: path, fileName: fileName }); | ||
}); | ||
}var main = function (options) { | ||
}function main(options) { | ||
if (options === void 0) { options = {}; } | ||
@@ -473,3 +475,2 @@ if (!options.entry) | ||
write(_options, 'webTypes', webTypesData); | ||
}; | ||
module.exports = main;export{main as default}; | ||
}export{main as default,getWebTypes,main,normalize,parse,parseColumns,parseRow,parseTable,parseTitle,read,vetur,webTypes,write}; |
@@ -5,5 +5,5 @@ 'use strict';Object.defineProperty(exports,'__esModule',{value:true});var fg=require('fast-glob'),fs=require('fs'),path=require('path');function _interopDefaultLegacy(e){return e&&typeof e==='object'&&'default'in e?e:{'default':e}}var fg__default=/*#__PURE__*/_interopDefaultLegacy(fg);var config = { | ||
webTypes: 'web-types.json', | ||
titleRegExp: '#+\\s+(.*)\\n+([^(#|\\n)]*)', | ||
tableRegExp: '#+\\s+(.*)\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)', | ||
fileNameRegExp: '\\/((\\w|-)+)\\.\\w+$', | ||
titleRegExp: /#+\s+(.*)\n+([^(#|\n)]*)/g, | ||
tableRegExp: /#+\s+(.*)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g, | ||
fileNameRegExp: /\/((\w|-)+)\.\w+$/, | ||
separator: '/', | ||
@@ -35,2 +35,5 @@ props: 'props', | ||
} | ||
function isString(val) { | ||
return typeof val === 'string'; | ||
} | ||
// eslint-disable-next-line @typescript-eslint/ban-types | ||
@@ -40,2 +43,5 @@ function isFunction(val) { | ||
} | ||
function normalizeFile(file) { | ||
return file.replace(/\r\n/g, '\n'); | ||
} | ||
function getComponentsName(options, title, fileName, path) { | ||
@@ -75,13 +81,6 @@ if (title === void 0) { title = ''; } | ||
}function parse(options, file) { | ||
var titleRegExp = options.titleRegExp, tableRegExp = options.tableRegExp; | ||
var _file = normalizeFile(file); | ||
var titleContent = _file.match(new RegExp(titleRegExp, 'g')); | ||
var headers = titleContent | ||
? titleContent.map(function (item) { return parseTitle(options, item); }) | ||
: undefined; | ||
var headers = parseTitle(options, _file); | ||
var topHeader = headers && headers.length ? headers[0] : undefined; | ||
var tableContent = _file.match(new RegExp(tableRegExp, 'g')); | ||
var table = tableContent | ||
? tableContent.map(function (item) { return parseTable(options, item); }) | ||
: undefined; | ||
var table = parseTable(options, _file); | ||
return { | ||
@@ -94,16 +93,29 @@ title: topHeader ? topHeader.title : undefined, | ||
} | ||
function parseTitle(options, str) { | ||
var titleRegExp = options.titleRegExp; | ||
var _titleRegExp = isString(titleRegExp) | ||
? new RegExp(titleRegExp, 'g') | ||
: titleRegExp; | ||
var titleContent = str.matchAll(_titleRegExp); | ||
return Array.from(titleContent, function (item) { return ({ | ||
title: item[1].trim(), | ||
description: item[2].trim(), | ||
}); }); | ||
} | ||
function parseTable(options, str) { | ||
var tableRegExp = options.tableRegExp; | ||
var tableContent = str.match(new RegExp(tableRegExp)); | ||
var title = tableContent ? tableContent[1] : ''; | ||
var header = tableContent ? parseRow(tableContent[2]) : undefined; | ||
var columns = tableContent ? tableContent[3] : undefined; | ||
var content = []; | ||
if (header && columns) { | ||
content = parseColumns(options, title, header, columns); | ||
} | ||
return { | ||
title: title, | ||
content: content, | ||
}; | ||
var _tableRegExp = isString(tableRegExp) | ||
? new RegExp(tableRegExp, 'g') | ||
: tableRegExp; | ||
var tableContent = str.matchAll(_tableRegExp); | ||
return Array.from(tableContent, function (item) { | ||
var title = item ? item[1] : ''; | ||
var header = item ? parseRow(item[2]) : undefined; | ||
var columns = item ? item[3] : undefined; | ||
var content = []; | ||
if (header && columns) { | ||
content = parseColumns(options, title, header, columns); | ||
} | ||
return { title: title, content: content }; | ||
}); | ||
} | ||
@@ -143,18 +155,8 @@ function parseRow(str) { | ||
return columns; | ||
} | ||
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) { | ||
return file.replace(/\r\n/g, '\n'); | ||
}function normalize(options, data, path) { | ||
var fileNameRegExp = options.fileNameRegExp, props = options.props, events = options.events, slots = options.slots, directives = options.directives; | ||
var _path = path.match(new RegExp(fileNameRegExp)); | ||
var _fileNameRegExp = isString(fileNameRegExp) | ||
? new RegExp(fileNameRegExp) | ||
: fileNameRegExp; | ||
var _path = path.match(_fileNameRegExp); | ||
var fileName = _path ? _path[1] : ''; | ||
@@ -449,3 +451,3 @@ var _data = Object.assign(data, { path: path, fileName: fileName }); | ||
}); | ||
}var main = function (options) { | ||
}function main(options) { | ||
if (options === void 0) { options = {}; } | ||
@@ -473,3 +475,2 @@ if (!options.entry) | ||
write(_options, 'webTypes', webTypesData); | ||
}; | ||
module.exports = main;exports["default"]=main; | ||
}exports["default"]=main;exports.getWebTypes=getWebTypes;exports.main=main;exports.normalize=normalize;exports.parse=parse;exports.parseColumns=parseColumns;exports.parseRow=parseRow;exports.parseTable=parseTable;exports.parseTitle=parseTitle;exports.read=read;exports.vetur=vetur;exports.webTypes=webTypes;exports.write=write; |
import type { Options, ParseData, NormalizeData } from './type'; | ||
declare function normalize(options: Options, data: ParseData, path: string): NormalizeData; | ||
export default normalize; | ||
export declare function normalize(options: Options, data: ParseData, path: string): NormalizeData; |
@@ -1,3 +0,6 @@ | ||
import type { Options, ParseData } from './type'; | ||
declare function parse(options: Options, file: string): ParseData; | ||
export default parse; | ||
import type { Options, ParseData, ParseHeader, ParseTable, ParseTableColumn } from './type'; | ||
export declare function parse(options: Options, file: string): ParseData; | ||
export declare function parseTitle(options: Options, str: string): ParseHeader[]; | ||
export declare function parseTable(options: Options, str: string): ParseTable[]; | ||
export declare function parseRow(str: string): string[]; | ||
export declare function parseColumns(options: Options, title: string, header: string[], str: string): ParseTableColumn[]; |
@@ -1,2 +0,1 @@ | ||
declare function read(path: string): string; | ||
export default read; | ||
export declare function read(path: string): string; |
@@ -22,5 +22,5 @@ export declare type ReComponentName = (title: string, fileName: string, path: string) => string; | ||
webTypes: string; | ||
titleRegExp: string; | ||
tableRegExp: string; | ||
fileNameRegExp: string; | ||
titleRegExp: RegExp | string; | ||
tableRegExp: RegExp | string; | ||
fileNameRegExp: RegExp | string; | ||
separator: string; | ||
@@ -27,0 +27,0 @@ props: string; |
import type { Options, Source } from './type'; | ||
export declare function hyphenate(str: string): string; | ||
export declare function checkArray<T extends Array<unknown>>(item: T): T | undefined; | ||
export declare function isString(val: unknown): val is string; | ||
export declare function isFunction(val: unknown): val is Function; | ||
export declare function normalizeFile(file: string): string; | ||
export declare function getComponentsName(options: Options, title: string | undefined, fileName: string, path: string): string; | ||
@@ -6,0 +8,0 @@ export declare function getDocUrl(options: Options, fileName: string, header?: string, path?: string): string | undefined; |
import type { Options, NormalizeData, Tags, Props } from './type'; | ||
declare function vetur(options: Options, list: NormalizeData[]): { | ||
export declare function vetur(options: Options, list: NormalizeData[]): { | ||
tags: Tags; | ||
attributes: Props; | ||
}; | ||
export default vetur; |
@@ -1,3 +0,6 @@ | ||
import type { Options, NormalizeData, WebTypes } from './type'; | ||
declare function webTypes(options: Options, list: NormalizeData[]): WebTypes; | ||
export default webTypes; | ||
import type { Options, NormalizeData, WebTypes, WebTag, WebDirective } from './type'; | ||
export declare function webTypes(options: Options, list: NormalizeData[]): WebTypes; | ||
export declare function getWebTypes(options: Options, list: NormalizeData[]): { | ||
tags: WebTag[] | undefined; | ||
attributes: WebDirective[] | undefined; | ||
}; |
import type { Options, Tags, Props, WebTypes } from './type'; | ||
declare function write(options: Options, type: 'tags' | 'attributes' | 'webTypes', data: Tags | Props | WebTypes): void; | ||
export default write; | ||
export declare function write(options: Options, type: 'tags' | 'attributes' | 'webTypes', data: Tags | Props | WebTypes): void; |
{ | ||
"name": "components-helper", | ||
"version": "1.0.5", | ||
"version": "2.0.0", | ||
"description": "Based on the docs to provide code prompt files for vue component library", | ||
@@ -50,20 +50,23 @@ "main": "lib/index.js", | ||
"dependencies": { | ||
"fast-glob": "^3.2.7" | ||
"fast-glob": "^3.2.11" | ||
}, | ||
"devDependencies": { | ||
"@types/node": "^16.11.12", | ||
"@typescript-eslint/eslint-plugin": "^5.6.0", | ||
"@typescript-eslint/parser": "^5.6.0", | ||
"eslint": "^8.4.1", | ||
"@types/node": "^16.11.21", | ||
"@typescript-eslint/eslint-plugin": "^5.10.0", | ||
"@typescript-eslint/parser": "^5.10.0", | ||
"eslint": "^8.7.0", | ||
"eslint-plugin-prettier": "^4.0.0", | ||
"husky": "^7.0.4", | ||
"lint-staged": "^12.1.2", | ||
"lint-staged": "^12.2.2", | ||
"prettier": "^2.5.1", | ||
"rollup": "^2.61.0", | ||
"rollup-plugin-typescript2": "^0.30.0", | ||
"typescript": "^4.5.2" | ||
"rollup": "^2.66.0", | ||
"rollup-plugin-typescript2": "^0.31.1", | ||
"typescript": "^4.5.5" | ||
}, | ||
"lint-staged": { | ||
"*.{ts,js}": ["eslint --fix", "prettier --write"] | ||
"*.{ts,js}": [ | ||
"eslint --fix", | ||
"prettier --write" | ||
] | ||
} | ||
} |
@@ -20,5 +20,5 @@ # components-helper | ||
``` js | ||
const helper = require('components-helper') | ||
const { main } = require('components-helper') | ||
helper({ | ||
main({ | ||
// Options | ||
@@ -49,3 +49,2 @@ }) | ||
<summary>TOC</summary> | ||
<br> | ||
@@ -87,3 +86,2 @@ - [entry (required)](#entry) | ||
<br> | ||
</details> | ||
@@ -323,4 +321,4 @@ | ||
- Type: `string` (**This is a regular string.**) | ||
- Default: `#+\\s+(.*)\\n+([^(#|\\n)]*)` | ||
- Type: `RegExp` | `string` (**This is a regular string.**) | ||
- Default: `/#+\s+(.*)\n+([^(#|\n)]*)/g` | ||
@@ -331,4 +329,4 @@ matches the title and description information from docs | ||
- Type: `string` (**This is a regular string.**) | ||
- Default: `#+\\s+(.*)\\n+(\\|?.+\\|.+)\\n\\|?\\s*:?-+:?\\s*\\|.+((\\n\\|?.+\\|.+)+)` | ||
- Type: `RegExp` | `string` (**This is a regular string.**) | ||
- Default: `/#+\s+(.*)\n+(\|?.+\|.+)\n\|?\s*:?-+:?\s*\|.+((\n\|?.+\|.+)+)/g` | ||
@@ -339,4 +337,4 @@ matches the title and table header and table content information from docs | ||
- Type: `string` (**This is a regular string.**) | ||
- Default: `\\/((\\w|-)+)\\.\\w+$` | ||
- Type: `RegExp` | `string` (**This is a regular string.**) | ||
- Default: `/\/((\w|-)+)\.\w+$/` | ||
@@ -351,3 +349,3 @@ matches the file name from path | ||
#+\\\\s+(`.*`)\\\\n+(`[^(#|\\n)]*`) | ||
/#+\s+(`.*`)\n+(`[^(#|\n)]*`)/ | ||
@@ -367,3 +365,3 @@ <div> | ||
#+\\\\s+(`.*`)\\n+>\\\\s\*(`[^(#|\\n)]*`) | ||
/#+\s+(`.*`)\n+>\s\*(`[^(#|\n)]*`)/g | ||
@@ -379,3 +377,3 @@ <div> | ||
#+\\\\s+(`.*`)\\\\n+(`\\|?.+\\|.+`)\\\\n\\\\|?\\\\s*:?-+:?\\\\s\*\\\\|.+(`(\\n\\|?.+\\|.+)+`) | ||
/#+\s+(`.*`)\n+(`\|?.+\|.+`)\n\|?\s*:?-+:?\s*\|.+(`(\n\|?.+\|.+)+`)/g | ||
@@ -402,3 +400,3 @@ <div> | ||
#+\\\\s+(`.*\\s*Props|.*\\s*Events|.*\\s*Slots|.*\\s*Directives`)\\\\s*\\\\n+(`\\|?.+\\|.+`)\\\\n\\\\|?\\\\s*:?-+:?\\\\s*\\\\|.+(`(\\n\\|?.+\\|.+)+`) | ||
/#+\s+(`.*\s*Props|.*\s*Events|.*\s*Slots|.*\s*Directives`)\n+(`\|?.+\|.+`)\n\|?\s*:?-+:?\s*\|.+(`(\n\|?.+\|.+)+`)/g | ||
@@ -405,0 +403,0 @@ <div> |
58102
17
1128
418
Updatedfast-glob@^3.2.11