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

tic-lib

v1.1.0

Published

泰链 NodeJS 开发者库

Downloads

165

Readme

泰链 NodeJS 开发者库

该库内容会不实时更新

安装

$ npm i tic-lib
或者
$ yarn add tic-lib

如何使用

示例

const moment = require('tic-lib').zhCN;
console.log(moment().fromNow());
// 几秒前

base-context-class

提供以下继承类供 egg 框架使用

  • BaseController
    • pageSize(page, size):分页工具
  • BaseService
    • bigAdd(a,b):加
    • bigMinus(a,b):减
    • bigMul(a,b):乘
    • bigDiv(a,b):除
    • mod(a,b):取余数
    • gt(a,b):a是否大于b
    • gte(a,b):a是否大于等于b
    • equals(a,b):a是否等于b
    • bigPow(m,n):m的n次方
const { BaseController } = require('tic-lib').context;

class DemoController extends BaseController {
    async show() {
        const { bigAdd } = this;
        const res = bigAdd('10000000000000', '3233333333333333333333');
        // ...
    }
}

date-format

主要用于配合 Sequelize 做查询操作,自动格式化时间字段(YYYY-MM-DD HH:mm:ss)

// 返回值为一个钩子函数
const { dateFormat } = require('tic-lib');

config.sequelize = {
    // ...
    define: {
        // ...
        hooks: {
            afterFind: dateFormat
        }
    }
    // ...
}

errors

根据《NodeJS 开发手册》规约实现的错误类

const { InsufficientBalanceError } = require('tic-lib').clientError;

if (gt(amount, balance)) {
    throw new InsufficientBalanceError();
}

所有错误类都有默认值,具体参考以下内容
已提供以下错误类引用:

1xxx 客户端错误

  • 1000: ClientError 客户端错误
  • 1001: ParameterError 参数错误
  • 1002: UserNotFoundError 用户不存在
  • 1003: InvalidPasswordError 密码校验不通过
  • 1004: LogonExpirationError 登录过期
  • 1005: InsufficientBalanceError 余额不足
  • 1006: InvalidRequestError 无效的请求

2xxx 请求资源错误

  • 2000: ResourceError 请求资源错误
  • 2001: NotFoundError 找不到资源
  • 2002: PermissionDeniedError 权限不足
  • 2003: LoginRequiredError 需登录后访问
  • 2004: AccessDeniedError 访问拒绝
  • 2005: RedirectError 重定向
  • 2006: RequestTimeoutError 请求超时
  • 2007: BanLoginError 禁止登录
  • 2008: DataLoadingFailureError 数据加载失败

3xxx 服务器错误

  • 3000: ServerError 服务器错误
  • 3001: InternalError 内部错误
  • 3002: ThirdPartyServicesError 第三方服务异常
  • 3003: InternalServicesError 内部服务异常
  • 3004: ServerMaintenanceError 服务器更新、维护

moment

提供不同时区的 moment 实例,目前已支持:

  • 中国时区:zhCN
  • 默认(本地)时区:local
// 中国时区
const moment = require('tic-lib').zhCN;
// 本地时区
const moment = require('tic-lib').local;

sleep

线程等待(异步方式,不会造成线程阻塞)

const { sleep } = require('tic-lib');

async show() {
    // 停滞3秒
    await sleep(3000);
    // ...
}