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

@feq/mokia

v0.6.2

Published

A simple mock server.

Downloads

7

Readme

Mokia

Fork of varHarrie/mokia;

  • Remove image & canvas .
  • Switch tslint to eslint.
  • Upgrade department expired dependency packages.

A mock server integrated data simulation and http service.

中文文档

Features

  • 🤟 Simple, easy to use
  • 🔄 Reusable model
  • 💎 Support TypeScript

Basic Usage

  1. Install mokia
$ npm install @feq/mokia --save-dev
# Or
$ yarn add @feq/mokia --dev
  1. Adds a ts file like mock.ts:
import { mock, PORT, ServerConfig } from '@feq/mokia'

const config: ServerConfig = {
  [PORT]: 3000,
  'GET /users': () => {
    return {
      users: mock.array({
        id: mock.uuid(),
        name: mock.fullName()
      }, 0, 5)
    }
  },
  'GET /users/:id': () => {
    return {
      id: mock.uuid(),
      name: mock.fullName()
    }
  }
}

export default config
  1. Add script to package.json:
"scripts": {
  "mock": "mokia mock.ts",
}
  1. Run script npm run mock to start a http server.

Advanced Usage

To reduce duplicated code and keep reusability, we recommend to use class style:

import { decorators, mock, PORT, ServerConfig } from '@feq/mokia'

class User {
  @decorators.uuid()
  id: string

  @decorators.fullName()
  name: string
}

const config: ServerConfig = {
  [PORT]: 3000,
  'GET /users': () => {
    return {
      users: mock.array(User, 0, 5)
    }
  },
  'GET /users/:id': () => {
    return mock(User)
  }
}

export default config

APIs

Server Config

  • HOST Server host, default to 'localhost'
  • PORT Server port, default to 8080
  • PREFIX URL prefix, default to ''
  • PRIORITY priority url,all requests are redirected to this address first, default to''
  • SILENT whether to hide request logs, default to false
  • INTERCEPTORS route interceptors, default to {}

Note: The keys of those parameters are Symbol, instead of string, so you should import they from mokia.

import { HOST, PORT, PREFIX, PRIORITY, SILENT, INTERCEPTORS } from '@feq/mokia'

export default {
  [HOST]: 'localhost',
  [PORT]: 3000,
  [PREFIX]: '/apis',
  [PRIORITY]: 'http://another.domain.com',
  [SILENT]: true,
  [INTERCEPTORS]: {
    request: (req, res) => {
      console.log('before')
    },
    response: (req, res, data) => {
      console.log('after')

      return {
        code: 200,
        data
      }
    }
  }
  // ...
}

Generators

All generators can be use as function or decorator.

import { decorators, generators, mock } from '@feq/mokia'

// As decorator
class User {
  @decorators.boolean()
  isAdmin: boolean
}

// Or just a normal function
const bool = generators.boolean()

// Be equivalent to
const bool = mock.boolean()
  • Basic

    • boolean(chance?: number, value?: boolean): boolean
    • integer(max?: number): number
    • integer(min: number, max: number): number
    • natural(max?: number): number
    • natural(min: number, max: number): number
    • float(max?: number): number
    • float(min: number, max, fixed?): number
    • float(min: number, max, dmin: number, dmax: number): number
    • char(pool: string): string
    • string(pool: string, length?: number): string
    • string(pool: string, min: number, max: number): string
  • Complex

    • generate(mockable: Object | Function): any
    • array(proto: any, length?: number): any[]
    • array(proto: any, min: number, max: number): any[]
    • oneOf(list: any[]): any
    • manyOf(list: any[], length?: number): any[]
    • manyOf(list: any[], min: number, max: number): any[]
    • pick(proto: Object, length?: number): Object
    • pick(proto: Object, props: string | string[]): Object
    • pick(proto: Object, min: number, max: number): Object
  • Date

    • datetime(format?: string): string
    • datetime(format: string, max: DateType): string
    • datetime(format: string, min: DateType, max: DateType): string
    • date(format?: string): string
    • date(format: string, max: DateType): string
    • date(format: string, min: DateType, max: DateType): string
    • time(format?: string): string
    • time(format: string, max: DateType): string
    • time(format: string, min: DateType, max: DateType): string
    • timestamp(max?: DateType): string
    • timestamp(min: DateType, max: DateType): string
    • now(format?: string): string
  • Text

    • word(length?: number): string
    • word(min: number, max: number): string
    • title(length?: number): string
    • title(min: number, max: number): string
    • sentence(length?: number): string
    • sentence(min: number, max: number): string
    • paragraph(length?: number): string
    • paragraph(min: number, max: number): string
    • passage(length?: number): string
    • passage(min: number, max: number): string
    • zh.word(length?: number): string
    • zh.word(min: number, max: number): string
    • zh.title(length?: number): string
    • zh.title(min: number, max: number): string
    • zh.sentence(length?: number): string
    • zh.sentence(min: number, max: number): string
    • zh.paragraph(length?: number): string
    • zh.paragraph(min: number, max: number): string
    • zh.passage(length?: number): string
    • zh.passage(min: number, max: number): string
  • Color

    • color(): string
    • rgb(): string
    • rgba(): string
    • hex(): string
    • hsl(): string
  • Web

    • protocol(): string
    • tld(): string
    • ip(): string
    • ipv6(): string
    • port(min?: number, max?: number): number
    • domain(tld?: string): string
    • url(protocol?: string, host?: string, prefix?: string): string
    • email(domain?: string)
  • Person

    • age(min?: number, max?: number): number
    • birthday(format?: string): string
    • fullName(): string
    • firstName(): string
    • lastName(): string
    • zh.fullName(): string
    • zh.firstName(): string
    • zh.lastName(): string
    • zh.phone(): string
    • zh.idNumber(): string
  • Region

    • zh.region(): { code: string, name: string }
    • zh.regionName(): string
    • zh.province(): { code: string, name: string }
    • zh.provinceName(): string
    • zh.city(): { code: string, name: string }
    • zh.cityName(): string
    • zh.county(): { code: string, name: string }
    • zh.countyName(): string
    • zh.zipCode(): string
  • Id

    • uuid(): string
    • increment(step: number): number

License

MIT