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

mduash

v2.0.3

Published

> 根据日常 Node.js 开发整理的一些需求,以便后续搭建脚手架

Downloads

3

Readme

mduash

根据日常 Node.js 开发整理的一些需求,以便后续搭建脚手架

使用示例

JWT

  • sign & verify
import { JWT } from 'mduash'

const Jwt = new JWT('your-secret-key', '1h') // 盐值和有效期

// 要签发的数据
const payload = {
    username: 'user1',
    id: 1
}

// 签发 JWT
const token = Jwt.sign(payload)
console.log(token) // 输出签发的JWT字符串

// 要验证的 JWT 字符串
const tokenToVerify = 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...'

// 验证 JWT
const verified = Jwt.verify(tokenToVerify)
console.log(verified) // 输出验证结果,如果是有效的 JWT,将返回解码后的数据

MResponse

  • success & error
import { MResponse } from 'mduash'

// 使用 MResponse 类
const response = new MResponse({
    defaultSuccessText: '操作成功',
    defaultErrorText: '操作失败'
})

// 返回成功响应
const successResponse = response.success({ data: '这里是数据' }, '数据获取成功')
console.log(successResponse) // {code: 0, msg: '数据获取成功', data: '这里是数据'}

// 返回失败响应
const errorResponse = response.error(new MError(1001, '未授权访问'))
console.log(errorResponse) // {code: 1001, msg: '未授权访问', data: null}
  • MResponse.getPageParams
import { MResponse } from 'mduash'

// 获取分页参数(0是第一页)
const pageParams = MResponse.getPageParams({ pageSize: 10, pageIndex: 0 })
console.log(pageParams) // {limit: 10, offset: 0, order: {limit: 10, offset: 0}, getPageResult: Function... }

// 假设有以下数据和数据总数
const list = [{ id: 1 }, { id: 2 }, { id: 3 }]
const count = 30

// 使用 getPageResult 方法获取分页结果
const pageResult = pageParams.getPageResult(list, count)
console.log(pageResult) // {list: [...], count: 30, pageCount: 1, hasNext: false, hasPrev: false}

MError

  • MError & MError.withMsg
import { MError } from 'mduash'

const error = new MError(404, 'Not Found', 'NotFoundError')
console.log(error.code) // => 404
console.log(error.msg) // => 'Not Found'
console.log(error.name) // => 'NotFoundError'

const error = new MError(400, 'Bad Request', 'BadRequestError')
const newError = error.withMsg('Invalid input data')
console.log(newError.msg) // => 'BadRequestError:Invalid input data'
  • generatorMError
import { generatorMError } from 'mduash'

const error = generatorMError(500, 'Internal Server Error')
console.log(error.code) // => 500
console.log(error.msg) // => 'Internal Server Error'
console.log(error.name) // => 'MError'

Is

  • Is.isEmpty
import { Is } from 'mduash'

// 检查字符串是否为空
const isEmptyString = Is.isEmpty(' ')
console.log(isEmptyString) // 输出:true

// 检查数组是否为空
const isEmptyArray = Is.isEmpty([])
console.log(isEmptyArray) // 输出:true

// 检查对象是否为空
const isEmptyObject = Is.isEmpty({})
console.log(isEmptyObject) // 输出:true

Gen

  • guid
import { Is } from 'mduash'

// 检查字符串是否为空
const isEmptyString = Is.isEmpty(' ')
console.log(isEmptyString) // 输出:true

// 检查数组是否为空
const isEmptyArray = Is.isEmpty([])
console.log(isEmptyArray) // 输出:true

// 检查对象是否为空
const isEmptyObject = Is.isEmpty({})
console.log(isEmptyObject) // 输出:true

Validate

  • validateParam
import { Validate } from 'mduash'

// 验证邮箱地址
const isValidEmail = Validate.validateParam('[email protected]', 'email')
console.log(isValidEmail) // 输出:true

// 验证电话号码
const isValidPhone = Validate.validateParam('13812345678', 'phone')
console.log(isValidPhone) // 输出:true