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

@142vip/common

v0.0.1-alpha.7

Published

公众号搜:储凡

Downloads

10

Readme

@142vip/common

随机字符串

封装随机字符串生成函数,常用的有:

  • generateRandomStr
  • generateRandomStrWithSpecials
  • generateRandomStrWithLetter

分页

请求

封装了分页请求中的常见的currentPagepageSize字段。

/**
 * 分页时的请求参数
 * - 可继承
 */
export interface PaginationParams {
  currentPage: number
  pageSize: number
}

响应

分页数据的响应结构,继承了 PaginationParams的请求参数中的currentPage和pageSize字段,同时添加了totalPage字段和data字段,data字段为分页数据,支持泛型。

/**
 * 分页相应参数
 */
export interface PaginationResponseItem<T> extends PaginationParams {
  totalPage: number
  data: T[]
}

当分页接口返回数据时,常见的结构为:

{
  "currentPage": 1,
  "pageSize": 10,
  "totalPage": 1,
  // data字段支持泛型,常见是数组对象
  "data": []
}

接口响应

通用结构

export interface VipBaseResponse {
  traceId: string
  code: HttpStatus
  success: boolean
  message: string
}

请求成功

/**
 * 成功时,接口返回结构
 */
export interface VipSuccessResponse<T> extends VipBaseResponse {
  result: T
}

请求失败

/**
 * 异常时,接口返回结构
 */
export interface VipErrorResponse<T = string> extends VipBaseResponse {
  // 生产环境,严禁暴露这个字段
  detailErrorMessage?: T
}

通用脚本

开发

建议在项目下创建scripts目录,放置一些通用的脚本,dev脚本可以用来在开发环境下启动项目,例如:

#!/usr/bin/env node

/**
 * Usage:
 * - ./scripts/dev oauth-login
 */
const { execShell } = require('@142vip/common')
const { promptList } = require('@142vip/common')
const { devApps } = require('../142vip')

/**
 * 本地运行服务
 */
;(async () => {
  let appName = process.argv[2]
  if (appName == null) {
    appName = await promptList(devApps, '选择repo模块在开发环境下运行')
  }
  await execShell({
    command: `npx turbo run dev --filter=${appName} --color --only`,
    description: `开发环境运行${appName}`
  })
})()

在终端直接使用./scripts/dev即可执行该命令

编译

建议在项目下创建scripts目录,放置一些通用的脚本,build脚本可以用来在开发环境下启动项目,例如:

#!/usr/bin/env node

/**
 * Usage:
 * - ./scripts/build oauth-client
 */

const { execShell } = require('@142vip/common')
const { promptList } = require('@142vip/common')
const { buildApps } = require('../142vip');

(async () => {
  let appName = process.argv[2]
  if (appName != null) {
    if (!buildApps.includes(appName)) {
      appName = await promptList(buildApps, '选择repo模块进行构建...')
    }
  }
  // 编译
  execShell({
    command: `npx turbo run build ${appName == null ? '' : `--filter=${appName}`} --color --only`,
    description: `编译项目${appName == null ? buildApps.join(',') : appName}`
  })
})()

在终端直接使用./scripts/build即可执行该命令

参考

证书

MIT

Copyright (c) 2019-present, 142vip 储凡