npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

kingdesign-valid

v0.1.6

Published

Standalone static validator for @king-design/vue SFC usage

Readme

kingdesign-valid

@king-design/vue 的独立静态校验项目。

当前项目内置:

  • generated_components_api/ 组件元数据
  • src/ 编译检查、导入检查、props / events / slots / nesting 校验
  • tests/validate-tests/ 这条校验线的独立测试

src/ 当前按职责拆成:

  • src/core/ 校验入口、编译检查、元数据注册表
  • src/analysis/ SFC 脚本导入分析、模板表达式和模板遍历
  • src/validators/ props / events / slots / nesting 规则校验
  • src/shared/ 通用类型、常量、上下文、工具函数
  • src/catalogs/ 错误类型常量和中文目录

用法

import { validateCode } from 'kingdesign-valid';
const { validateCode } = require('kingdesign-valid');

主要导出:

  • validateCode(code)
  • validateCompilation(code)
  • analyzeCode(code)

兼容别名也保留:

  • validateCodeWithGeneratedAPI
  • validateCodeWithValid
  • validateGeneratedApiCompilation
  • analyzeCodeWithGeneratedAPI

返回结构

validateCode(code) 返回:

interface ValidValidationResult {
  passed: boolean;
  compilation: {
    name: string;
    passed: boolean;
    errors: Array<{
      type: ValidCompilationErrorType;
      message: string;
    }>;
  };
  violations: Array<{
    type: ValidRuleViolationType;
    rule: string;
    match: string;
    suggestion: string;
  }>;
  summary: string;
}

编译错误类型常量:

  • VALIDATION_COMPILATION_ERROR_TYPES
  • VALIDATION_COMPILATION_ERROR_TYPE_CATALOG_ZH_CN

规则违规类型常量:

  • VALIDATION_VIOLATION_TYPES
  • VALIDATION_VIOLATION_TYPE_CATALOG_ZH_CN

统一中文目录:

  • VALIDATION_TYPE_CATALOG_ZH_CN
    • compilationErrors
    • violations

示例:

import {
  validateCode,
  VALIDATION_COMPILATION_ERROR_TYPES,
  VALIDATION_VIOLATION_TYPES,
  VALIDATION_VIOLATION_TYPE_CATALOG_ZH_CN,
} from 'kingdesign-valid';

const result = await validateCode(code);

if (!result.compilation.passed) {
  for (const error of result.compilation.errors) {
    if (error.type === VALIDATION_COMPILATION_ERROR_TYPES.SCRIPT_COMPILE_ERROR) {
      console.log('脚本编译失败:', error.message);
    }
  }
}

for (const violation of result.violations) {
  if (violation.type === VALIDATION_VIOLATION_TYPES.TEMPLATE_UNDEFINED_VARIABLE) {
    const meta = VALIDATION_VIOLATION_TYPE_CATALOG_ZH_CN[violation.type];
    console.log(meta.label, violation.match);
  }
}

发布内容

npm 包内会直接携带:

  • dist/
  • generated_components_api/

安装后可直接运行校验,不需要再生成元数据。

开发

仓库开发场景下,如果你需要重新从 KPC 文档生成元数据:

yarn generate:api-docs 3.7.0 ksc-fe/kpc

api/ 转成校验用元数据:

yarn generate:api-components

快速查看 generated_components_api 里每个组件的 props / events / slots 数量:

yarn audit:generated-api-stats

输出格式示例:

Button props:13 events:0 slots:0
Dialog props:18 events:6 slots:5
Select props:26 events:2 slots:5

生成结果会写到项目根目录的:

  • api/
  • generated_components_api/