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 🙏

© 2024 – Pkg Stats / Ryan Hefner

zckoautils

v1.3.39

Published

Node.js 常用工具类 & 代码生成器

Downloads

120

Readme

Node.js 常用工具类 & 代码生成器

文档目录

代码目录结构

  • constant/ # 全局常量
    • email_template.js # 邮件模板
    • errors.js # 自定义异常类
    • phone-msg-template.js # 手机验证码短信模板
    • redis_key.js # 全局redis key
    • regex.js # 正则表达式
    • response-wrapper.js # 响应体包装函数(统一返回格式)
  • generator/ # 代码生成器
    npm run generate
  • middlewares/ # 中间件
  • test/
    npm run test
  • utils/ # 工具类
    • aliyun_green/aliyun-green-util.js # 阿里云内容安全
    • oauth/ # 第三方登录oauth2.0
      • apple_oauth.js # 苹果登录(todo)
      • facebook_oauth.js # facebook登录(todo)
      • google_oauth.js # google登录(todo)
      • wechat_oauth.js # 微信登录
    • pay/ # 第三方支付
      • paypal_util.js # paypal支付
      • wxpay_util.js # 微信支付
        const code = await AliyunMsgUtil.sendVcode(phone);
    • prototype/ # JavaScript扩展函数
      • date # 日期扩展函数
      • string # 字符串扩展函数
    • aes-util.js # AES加密
    • aliyun-msg-util.js # 阿里云SMS短信服务
      const code = await AliyunMsgUtil.sendVcode(phone);
    • aliyun-oss-util.js # 阿里云OSS工具类
      router.get('/sign', Auth(UserType.USER), async (ctx, next) => {
          // 阿里云签名直传
          const result = await AliyunOSSUtil.post(`user/${ctx.user_self.user_id}/`);
          ctx.body = SUCCESS(result);
      });
    • common-util.js # 常用函数
    • crypto-util.js # 加密工具类
    • db # sequelize初始化
      global.db = db({
          ...global.config.db[getENV()],
          // 日志开关
          log_on_off: false,
      });
    • dingtalk-util.js # 钉钉群通知
      await DingTalkUtil.sendText({config: "DEV_ROBOT", content: `AIGC手机验证码${phone}的:${code}`});
    • google-util.js # 谷歌登录
    • hello-world.js # 表情包ASCII图案字符串
    • logger.js # 日志
      const prefix = getPrefix(__filename)
      const logger = new Logger(prefix, true)
      logger.info("hello world");
    • redis_util.js # redis
      // set key value [EX seconds] [PX milliseconds] [NX|XX]
      await redisCommend("set", RedisKey.VCODE_EMAIL_USER_LOGIN(email), code, "EX", 5 * 60)
      await redisCommend("hexists", RedisKey.PAY_WXPAY_POLLING_QUERY(event, group), out_trade_no)
    • reg_util.js # 正则表达式
    • smtp_util.js # SMTP邮件发送
      const code = generateCode(6);
      await SMTPUtil.send({
          to: email,
          ...EmailTemplate.VCODE(code)
      });
    • wechat_miniprogram_util.js # 微信小程序
    • wechat_offiaccount_util.js # 微信公众号
    • youdao_util.js # 有道翻译
      if (isChinese(content)) {
          result = await youdaoapi({
              q: content,
              from: "zh-CHS",
              to: "en",
          });
      } else {
          if (isEnglish(content)) {
              result = await youdaoapi({
                  q: content,
                  from: "en",
                  to: "zh-CHS",
              });
          }
      }
  • count.sql # api访问次数统计 数据表创建脚本
  • init.js # 初始化配置

安装配置

一、安装zckoauitls

方法1(推荐)、在package.json中添加依赖
{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "clean-cache": "npm cache clean --force",
    "dev-win": "set NODE_ENV=development && nodemon app.js",
    "dev-mac": "export NODE_ENV=development && nodemon app.js",
    "staging": "export NODE_ENV=test && nodemon app.js",
    "prd": "export NODE_ENV=production && pm2 start app.js",
    "migrate-dev": "cd ./db && npx sequelize-cli db:migrate",
    "migrate-prd": "cd ./db && npx sequelize-cli db:migrate --env production"
  },
  "dependencies": {
    ......
    // 避免阿里云镜像未同步,使用npmjsg官方源的绝对路径
    "zckoautils": "https://registry.npmjs.com/zckoautils/-/zckoautils-1.2.90.tgz"
  }
}
方法2、npm install
npm i --registry https://registry.npmjs.org zckoautils

代码生成器

使用了nunjucks模板引擎

生成逻辑

  • 大小驼峰和下划线的转换
  • 字符串替换
  • 模板语法

模板语法

{% if not loop.last %},{% endif %}
循环
{% if not loop.last %},{% endif %}

模板中可以拿到的数据

_copy 初始化直接复制的文件
table_level 数据表级迭代

||| |----|----| |||

database_level 数据库级迭代
  • tables
    • config
  • table
    • columns # 当前表的所有字段
      • COLUMN_KEY
      • COLUMN_KEY
      • COLUMN_KEY
    • columns2 # 基于columns,去掉了声明的字段如:created_at、updated_at、deleted_at
    • columns3 # 基于columns2,去掉了主键字段
  • config
  • primaryKey