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

yod-mock

v0.3.1

Published

Powerful data generator tool.

Downloads

10

Readme

yod-mock

Join the chat at https://gitter.im/qiu8310/yod-mock NPM version Build Status Coverage Status Dependency Status

本项目主要用来在测试环境中生成测试数据用的,另外也可以在命令行上快速生成简单测试数据。

背景

  • 前端程序员会因为后端没有接口数据,开发某些功能可能就不太方便
  • 而后端程序员常会被前端程序员催促给接口,给数据,但你也还没开发完时会显得他们很烦人

此工具就是希望在前后端都没有数据的情况下生成大量随机的测试数据

Features:

  • 语法简洁,学习成本低,功能强大
  • 支持所有 JS 原生的函数
  • 支持所有 lodash 的函数
  • 支持自定义新的 type 和 modifier
  • 支持配置系统现有的数据(使用 yod.config('system.xxx', ...)

在线体验本项目的功能

Install

CLI

npm install --global yod-mock
  • Using yod image to get a random image
  • Using yod image -c to get a random image and copy it to clipboard
  • Using yod image .repeat 10 to get 10 random images

Node.js

npm install --save-dev yod-mock

Browser

bower install --save-dev yod-mock

Usage

DEMO:(Edit this demo online


/*

@Self:   Current plain object
@Parent: Parent plain object
@Config: Config item

*/

// Define an `User` type
yod.type('User', {
  firstName: '@First',              // Get a random firstName
  lastName: '@Last',
  sex: '@Sex',
  fullName: '@Self.firstName @Self.lastName',  // Join current object's firstName and lastName
  nickName: '@Nick',
  chineseName: '@ChineseName',
  age: '@Age(adult)',               // Call @Age with a argument
  to100: '` 100 - @Self.age `',     // Execute javascript code
  telephone: '@Tel',
  avatar: '@Avatar',
  others: {
     words: 'Hello, my name is @Parent.fullName, you can call me @Parent.nickName.',
     bestFriends: '@Nick.repeat(2, 3).join(", ")',    // Call native array's join function
     myFirstNameLength: '@Parent.firstName.length',   // Call native string's length attribute
     favouriteLetter: '@([A, B, C]).sample'           // Call lodash sample function
  }
});

// Use `User` type to generate an object with ten users in it
console.log(yod({
    status: 'ok',
    list: '@User.repeat(10)'
}));

// or Use `User` type to generate directly array
// console.log(yod('@User.repeat(10)'));

Types

BASIC

LOCATION

MEDIA

MIXED

TEXT

USER

WEB

Modifiers

Support all function in lodash:

yod('@([1, 2, 3]).sample');   // equal to `_.sample([1, 2, 3])`
yod('@Int.repeat(10).uniq');  // equal to `_.uniq(yod('@Int.repeat(10)'))`

Support all function in native javascript:

yod('@([a, b, c]).join("-")'); // equal to `['a', 'b', 'c'].join('-')`
yod('@String.replace(a, b)');  // equal to `yod('@String').replace('a', 'b')`

BASIC

Reference

  • yod:本项目的核心引擎(我写的)。
  • mockjs:阿里出的,也不错,但学习成本较高,也不够强大。
  • chance:国外的一个 mock 库,代码很简洁,但不适合中国人用。
  • jsonfy:将任意的字符串解析成 JS 里的数据,类似于 JSON.parse,但语法要求没它那么严格(我写的)。
  • sscan:字符串分析器,很多复杂的解析用正则表达式是满足不了要求的,所以需要把字符串化分成字符来一个个解析(我写的)。
  • elegant.def:优雅的定义 JS 函数,很多情况下我们定义了函数要处理参数的各种情况,用了它处理函数参数就非常简单了(我写的)。

TODO

History

ChangeLog

License

Copyright (c) 2015 Zhonglei Qiu. Licensed under the MIT license.