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

moxai

v1.1.2

Published

Moxai (mɒks-eɪ) - Express Middleware for API mocks using Open API Initiative (OAI)

Downloads

11

Readme

moxai

Moxai (mɒks-eɪ) - Express Middleware for API mocks using Open API Initiative (OAI) npm TravisCI Code Climate Code Climate Coverage Codecov Codacy Badge bitHound Overall Score bitHound Dependencies Gemnasium Dependency Status VersionEye Dependency Status GitHub Tags GitHub Contributors GitHub Issues Semver license

Moxai (mɒks-eɪ) - Express Middleware for API mocks using Open API Initiative (OAI)

Installation

This is a Node.js module available through the npm registry. Installation is done using the npm install command.

npm install moxai --save

Usage

Setup as standard third-party middleware which requires Express and mounting on a route, such as '/mocks'.

var express = require('express');
var moxai = require('moxai');
var app = express();

app.use('/mocks', moxai());

app.listen(8000, function () {
  console.log('Express web server with Moxai listening on port 8000');
})

Options

Options are passed as an object to moxai and all arguments are optional.

var opts = {
 'dir': 'mocks',
 'file': 'api',
 'random': false
};

app.use('/mocks', moxai(opts));

| Option | Type | Default | Argument | Description | | ---- | ---- | ---- | ---- | ---- | | dir | string | mocks | optional | The directory location of OAI files relative to parent directory. | | file | string | api | optional | The name of OAI JSON file. Must be located within directory location. | | random | boolean | false | optional | Use random output for regex values in OAI JSON file. |

dir

The directory where the files are stored. This is relative to the parent directory and the default is mocks. In most applications, simply add a mocks directory in the root of the application.

/
├── mocks/
├── app.js|index.js
└── package.json

file

The file of the OAI (formerly Swagger) JSON file to use. This is compatible with OAI version 2.0. This must have a .json extension and the default is api, therefore the default file is api.json. The file must be in the designated directory, which defaults to mocks.

/
├── mocks/
    └── api.json
├── app.js|index.js
└── package.json

Mock output should be in the response examples section of the OAI JSON. This should be the exact JSON output expected by the mock API request.

{
  "swagger": "2.0",
  "paths": {
    "/api/": {
      "get": {
        "responses": {
          "200": {
            "examples": {
              "application/json": {
                "key": "value"
              }
            }
          }
        }
      }
    }
  }
}

random

Randomizes the output from the OAI JSON using regular expressions. Only randomizes values that are valid regex and are enclosed in forward slashes (/). Back slashes (\) must be escaped by using double backslash (\\). Ignores any flags such as /i (ignore case) and /g (global). If error with regex, then will output original string.

{
  "swagger": "2.0",
  "paths": {
    "/api/": {
      "get": {
        "responses": {
          "200": {
            "examples": {
              "application/json": {
                "alphanumeric": "/^[a-z0-9]{2,10}$/",
                "titlecase": "/^[A-Z][a-z]{4,16}$/",
                "phonenumber": "/^[1-9]\\d{2}-\\d{3}-\\d{4}/",
                "integer": "/[0-9]{1,7}/",
                "boolean": "/true|false/",
                "ignore": "/[[[ignore/"
              }
            }
          }
        }
      }
    }
  }
}

Testing

Scripts

  • npm test to run Mocha unit tests.
  • npm run coverage for Istanbul code coverage. Results in /coverage folder.
  • npm run lint for ESLint static code analysis. Results in /lint folder.
  • npm run docs to run JSDoc code documentation. Results in /docs folder

Test Data

Dependencies

Modules

Application

Package

Dependency Trackers

Contact

Point of Contact

You can report issues and submit questions by opening a new Issue in GitHub.

Notifications

You can Watch this repo to receive notifications from GitHub when a new issue is posted, when an existing issue’s status is updated, and when a pull request is created.

Contributing

See CONTRIBUTING for additional information.

Acknowledgements

This open source project was developed for the U.S. Forest Service ePermit API project under the General Services Administration (GSA) Technology Transformation Service (TTS) 18F Agile Delivery Services Blanket Purchase Agreement (Agile BPA). Moxai is a testing dependency for the ePermit API which used this package as a temporary, placeholder mock API. Moxai is published as an independent npm package that can be used with any Express application.

License

This project is in the worldwide public domain. As stated in CONTRIBUTING:

This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.

All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.