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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@yangshunnpm/jsontocode

v1.0.2-alpha.1

Published

![image](https://gitee.com/yangshundegit/jsontocode/blob/master/tip.gif)

Readme

image

gif太大未展示,可以点击这里gif

DSL生成react代码

  1. 修改DSL配置实时更新组件
  2. 支持标签名称
  3. props字符串,函数方法或自定义参数传递
  4. props变量传参
  5. state定义
  6. 文件依赖处理,支持全局依赖和单个文件依赖
  7. 支持变量以模版字符串格式传参

react代码生成DSL

  1. 修改组件实时更新配置

run

// index.js
import { Watch } from './lib/index.js';

new Watch({
    // 存放json配置目录
    jsonDir: './src',
    // 存放code配置目录
    codeDir: './dist',
    // 全局依赖
    autoImport: [
        'react',
    ],
})
npm run watch

DSL结构定义

export default {
  // 组件级属性定义
  imports: [              // 组件依赖数组,会和全局依赖合并再生成依赖代码
    ['./wrapper', 'Wrapper']  
  ],
  displayName: 'Pages',   // 组件名称
  state: {                // 组件state定义
    visible: true,
  },

  // 组件Dom树级定义
  props: {                // dom props传参:className, onClick 或 自定义props
    visible: "{{this.state.visible}}"
  },
  componentName: "Modal", // dom组件名称
  children: [             // dom子级属性, children可以是dom,也可以是字符串
    {
      props: {},
      componentName: "Wrapper",
      children: [
        {
          props: {
            isShow: "true",
            onClick: () => {
              setState({
                visible: false,
              })
            },
          },
          componentName: "p",
          children: "这是一段{{this.props.content}}文章"
        },
      ],
    },
  ],
}

生成code示例

import React from "react";
import Wrapper from "./wrapper";
export default function Pages(props) {
  const [state, setState] = React.useState({
    visible: true,
  });
  return (
    <Modal visible={state.visible}>
      <Wrapper>
        <p
          isShow="true"
          onClick={() => {
            setState({
              visible: false,
            });
          }}
        >
          这是一段{props.content}文章
        </p>
      </Wrapper>
    </Modal>
  );
}

import 依赖格式规范和示例

{
  // (全局配置为autoImport,  页面配置为imports)
  autoImport: [
    // 'react'做了特殊处理,可以简写'react'
    'react',              =>     import React from 'react';

    // 传入数组类型  
    ['from', 'import'],
    ['react', 'React']    =>   import React from 'react';

    //传入对象类型
    {
            [package-name]: [
                'import'
            ],
            'react': [
                'useState',
                'useEffect'
            ],   =>   import { useState, useEffect } from 'react';
            [package-name]: ['import', 'alias'],
            'react': [
                'useState',
                ['useLayoutEffect', 'asyncLayoutEffect']
            ],   =>   import { useState, useLayoutEffect as asyncLayoutEffect } from 'react';
        }
  ]
}

双向转换注意事项

  1. 可能一个文件的误修改保存导致另一边的文件更新,导致另一边文件的有效修改代码丢失,保存更新代码需谨慎或及时保存文件让两边文件及时同步