Svelte - 获取组件信息
用于从斯维尔特文件中提取道具,动作,槽和css变量等信息的函数. 旨在简化文件编制
国家预防机制联系: @ el3um4s/ svelte- get- 组件- info
我建议用它 el3um4s/ svelte- 组件- info (不详: @el3um4s/ svelte- 组件- info(中文(简体) )
安装和使用软件包
要在项目中使用软件包:
npm i @el3um4s/svelte-get-component-info
然后在文件中 :
import type { SvelteInformations } from "@el3um4s/svelte-get-component-info";
import { getInfo, readFileSvelte } from "@el3um4s/svelte-get-component-info";
const info: SvelteInformations = getInfo(readFileSvelte("./src/lib/hello.svelte").content.content);
console.log(info.props); // [{ name: "message", type: "string", defaultValue: "Hello World" }]
console.log(info.actions); /// [ { name: "notify" }]
info 看起来像这样:
{
"props": [
{ "name": "color", "type":"string", "defaultValue":"red" },
{ "name": "steps", "type":"number", "defaultValue":"8" }
{ "name": "title", "type":"string" },
{ "name": "description"}
],
"actions": [
{ "name": "click" },
{ "name": "hover" },
{ "name": "customAction" }
],
"slots": [
{ "anonymous": true },
{ "name": "header", "anonymous": false },
{ "name": "footer", "anonymous": false }
],
"css": [
{ "name": "--color-primary" },
{ "name": "--color-secondary" }
]
}
要执行的列表 :
- 获取道具 :
- 名称
- 类型
- 默认值
- 动作
- 插槽
- 匿名
- 名称
- css 变量