@youngjuning/interface-comments-parser
TypeScript icon, indicating that this package has built-in type declarations

5.1.0 • Public • Published

@youngjuning/interface-comments-parser

WIP: This is an initial draft, API is not stable

NPM version build status Test coverage

$ yarn add -D @youngjuning/interface-comments-parser

Usage

Parse

You can use parse to parse file.

const path = require("path");
const { parse } = require("@youngjuning/interface-comments-parser");

parse(path.resolve(__dirname, "./demo.ts"), "DemoProps");

GetFieldMeta

const path = require("path");
const { parse, getFieldMeta } = require("@youngjuning/interface-comments-parser");

const result = parse(path.resolve(__dirname, "./demo.ts"), "DemoProps");
const meta = result.map(o => getFieldMeta(o, "zh-CN"));

Type

export interface IField {
  /**
   * @language en-US
   * @description name of fields
   */
  /**
   * @language zh-CN
   * @description 字段名
   */
  name: string;

  /**
   * @language zh-CN
   * @description 字段是否可选(即有没有问号)
   */
  optional: string;

  /**
   * @language zh-CN
   * @description 字段类型
   */
  types: string;

  /**
   * @language zh-CN
   * @description 字段信息,用户备注。
   */
  meta?: IFieldMeta;
}

export interface IMeta {
  [key: string]: string;
}

export interface IFieldMeta {
  base: IMeta;
  i18n: {
    [language: string]: IMeta;
  };
}

API

parse(filePath: string, name: string): IField[];

getFieldMeta(field: IField, language?: string): IMeta;

Readme

Keywords

none

Package Sidebar

Install

npm i @youngjuning/interface-comments-parser

Weekly Downloads

1

Version

5.1.0

License

MIT

Unpacked Size

16.2 kB

Total Files

12

Last publish

Collaborators

  • youngjuning