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

motypeck

v0.0.6

Published

use type definition in typescript to mock data

Downloads

9

Readme

motypeck

mo-type-ck

利用typescript 类型定义来mock数据。

该库目前仅提供以下功能,其他功能尚在完善中。,

Example:

const MoTypeCk = require('motypeck')
const mock = new MoTypeCk()
// 添加源文件
mock.addFile( __dirname +  '/models.ts')
// 传入接口名或类名,返回mock数据
let res = mock.mock('ITest')
console.log(res)

models.ts

使用 jsdoc @mock 表达式 来对mock数据进行注解

export interface ITest {
    
    // 默认返回3至5位长度的整数,即 d3-d5
    defaultNum: number

    // 默认返回长度为10的随机字符串
    defaultStr: string

    // 指定范围整数
    /** @mock 100-999 */
    pnum: number

    // 指定位数的整数
    /** @mock d3 */
    pnum2: number

    // 指定位数范围
    /** @mock d3-d9 */
    pnum3: number

    // 指定整数范围和小数位数
    /** @mock d3-d4.d3 */
    pnum4: number

    // 注:不支持小数范围

    // 以下分别返回 Number.MAX_VALUE, Number.MIN_VALUE, Number.POSITIVE_INFINITY, Number.NEGATIVE_INFINITY
    /** @mock max */
    pnum5: number
    /** @mock min */
    pnum6: number
    /** @mock max-inf */
    pnum7: number
    /** @mock min-inf */
    pnum8: number

    // 在一个数组中随机返回一个
    /** @mock ["234","6543","sdafs"] */
    pstring: string

    // 指定字符串长度
    /** @mock 8 */
    pstring2: string

    // 指定字符串长度范围
    /** @mock 3-9 */
    pstring3: string
  

    // 指定true的概率。默认为0.5
    /** @mock 0.3 */ 
    pbool: boolean
    
    // 默认返回 now
    ptime: Date


}