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

@hashicorp/api-double

v1.6.1

Published

api-double serving via HTTP or other means

Downloads

1,853

Readme

api-double

api-double serving via HTTP or other means

See https://github.com/hashicorp/consul-api-double/ for an example of an api-double.

'Templates' use simple native javascript template literals for very basic looping and basic logic for providing fake data.

Usage

CLI/Server

api-double --dir path/to/templates

# Flags

--dir : set the path to template files (default ./)
--seed : set the seed for faker to use
--port : set the port to serve from (default: 3000)

# ENV vars

HC_API_DOUBLE_PORT : default port to use
HC_API_DOUBLE_DIR : default path to use
HC_API_DOUBLE_SEED: default seed to use

Browser/frontend only usage

TODO

Wildcard templates

To provide a double for /v1/health/service/:name

Create a /v1/health/service/_ template file. This will be used for /v1/health/service/*. Within the template the * will be in location.segment(3)

Further configuration will be provided by a /v1/health/service/.config file or similar as and when needed.

Extra template helpers:

Right now very subject to change. But the idea is to keep them as minimal as possible and just rely on faker, plus helpers to get things you need for doing stuff like this (easy way to loop, access to url params and headers)

HTTP properties

HTTP data is accessible via the http object using the following properties:

http.method
http.headers.*
http.body.*
http.cookies.*

env(key, defaultValue)

Gets the 'environment' value specified by key, if it doesn't exist, use the default value. 'environment' variables come from cookies by default, which can be easily set using the browsers Web Inspector

range(int)

Simple range function for creating loops

[
    ${
        range(100000).map(
            item => {
                return `"service-${item}"`;
            }
        );
    }
]
// yields
[
    "service-1",
    ...,
    "service-100000"
]

fake

Object containing access to various faker functions

[
    ${
        range(100000).map(
            item => {
                return `${fake.address.countryCode().toLowerCase()-${item}}`;
            }
        );
    }
]
// yields
[
    "it-1",
    ...,
    "de-100000"
]

location.pathname

Reference to the current url

// /v1/catalog/datacenters
[
    "${location.pathname}"
]
// yields
[
    "/v1/catalog/datacenters"
]

location.search

This gives you a place to access queryParams location.search.queryParamName

location.pathname.get(int)

Reference a 'segment' in the current url

// /v1/catalog/datacenters
[
    "${location.pathname.get(1)}"
]
// yields
[
    "catalog"
]

location.pathname.slice

location.pathname.isDir