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

mock-get

v1.2.1

Published

Isomorphic light mock HTTP get request and return Promise

Downloads

1

Readme

mock-get

npm Travis license

:arrow_upper_right: Isomorphic light mock HTTP get request and return Promise, support both node and browser environment

Install

$ npm install --save mock-get

Usage


// ES6
import get from 'mock-get';

// node
const get = require('mock-get');

get(delay, mockData, hasError);
  • delay milliseconds you want to delay your request, default value is 0
  • mockData json object will be resolve in the Promise (optional)
  • hasError default is false, set to true if you want the Promise to reject (optional)

Use second parameter as boolean to set hasError if you do not have your own mock data.

Mock Request

get(1000)
.then(res => console.log(res))
.catch(err => console.error(err));

will log the response data

Fire an Error

get(1000, true)
.then(res => console.log(res))
.catch(err => console.error(err));

will log error message

Use your own mock data

get(1000, { name: 'foo', value: 'bar' })
.then(res => console.log(res));
import myMockData from './myMockData';

get(1000, myMockData)
.then(res => console.log(res));

Default Response

This is how default response look like, you can use your own mock data if you want.

[{
  "id": 1,
  "name": "Bruce Banner",
  "title": "Hulk",
  "email": "[email protected]",
  "gender": "Male",
  "date": "12/18/1969",
  "age": 46
}, {
  "id": 2,
  "name": "Steve Rogers",
  "title": "Captain America",
  "email": "[email protected]",
  "gender": "Male",
  "date": "7/4/1918",
  "age": 98
}, {
  "id": 3,
  "name": "Natalia Romanoff",
  "title": "Black Widow",
  "email": "[email protected]",
  "gender": "Female",
  "date": "11/22/1984",
  "age": 31
}, {
  "id": 4,
  "name": "Tony Stark",
  "title": "Iron Man",
  "email": "[email protected]",
  "gender": "Male",
  "date": "5/29/1970",
  "age": 46
}, {
  "id": 5,
  "name": "Clint Barton",
  "title": "Hawkeye",
  "email": "[email protected]",
  "gender": "Male",
  "date": "1/7/1971",
  "age": 45
}]

License

MIT