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

request-options-gen

v1.0.5

Published

generates the options object to request library from a hierarchy of files

Downloads

34

Readme

request-options-gen

JS Library to generate options for request library by templates files

NPM version npm Build Status codecov dependencies Status Known Vulnerabilities

Install

npm install --save request
npm install --save request-options-gen

Super simple to use:

var rog = require('request-options-gen');
var request = require('request');

var options = rog.gen({
  basePath: 'tests/data',
  path: 'reqres/list-users'
});

console.log('Options: ');
console.log(JSON.stringify(options));

request(options,  function (error, response, body) {
  console.log('\nBody: ');
  console.log(JSON.stringify(JSON.parse(body)));
});

Will process the following files with this template folder:

♦
└┄ ▼ tests
   └┄ ▼ data
      ├┄ ▼ reqres
      │  ├┄ ▼ list-users
      │  │  ├┄ • qs.txt
      │  │  └┄ • url.txt
      │  ├┄ • default-headers.txt
      │  └┄ • init-config.js
      ├┄ • config.js
      └┄ • generic-headers.txt
Options:
{
	"headers": {
		"Content-Type": "application/json",
		"gtw-transaction-id": "2017-09-28T16:33:45.280Z-Note_M_17294",
		"Pragma": "no-cache",
		"Cache-Control": "no-cache"
	},
	"qs": {
		"page": "2"
	},
	"url": "https://reqres.in/api/users"
}

Body: 
{
	"page": 2,
	"per_page": 3,
	"total": 12,
	"total_pages": 4,
	"data": [{
			"id": 4,
			"first_name": "Eve",
			"last_name": "Holt",
			"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/marcoramires/128.jpg"
		}, {
			"id": 5,
			"first_name": "Charles",
			"last_name": "Morris",
			"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/stephenmoon/128.jpg"
		}, {
			"id": 6,
			"first_name": "Tracey",
			"last_name": "Ramos",
			"avatar": "https://s3.amazonaws.com/uifaces/faces/twitter/bigmancho/128.jpg"
		}
	]
}

Table of contents

back to top


Methods

See: Options Method 1: Without edit options

const rog = require('request-options-gen');
rog.gen(options).request(callback);

Method 2: Permit edit options

const request = require('request');
const rog = require('request-options-gen');
let data = rog.gen(options);
request(data.options, callback);

back to top


Options

back to top


Specials Files

Named files that end with:

url.txt

Generate:

{
  "url": "${value}"
}

Sample File 1:

http://google.com
  ↕
{
  "url": "http://google.com"
}

Sample File 2:

`http://${p.host}:${p.port}.com/my-url/`
  ↕
{
  "url": "http://my-host:8080.com/my-url/"
}

qs.txt

Generate:

{
  "qs": {
    "${attr-name-1}": "${attr-value}",
    "${attr-name-2}": "${attr-value}",
    "${attr-name-n}": "${attr-value}"
  }
}

Sample File:

id:`require('uuid/v4')()`
page:2
  ↕
{
  "qs": {
    "id": "110ec58a-a0f2-4ac4-8393-c866d813b8d1",
    "page": "2"
  }
}

headers.txt

{
  "headers": {
    "${attr-name-1}": "${attr-value}",
    "${attr-name-2}": "${attr-value}",
    "${attr-name-n}": "${attr-value}"
  }
}

Sample File:

Pragma:no-cache
Cache-Control:no-cache
x-time:`new Date().toISOString()`
  ↕
{
  "headers": {
    "Pragma": "no-cache",
    "Cache-Control": "no-cache",
    "x-time": "2017-10-02T14:11:35.511Z"
  }
}

body.txt

{
  "body": "${value}"
}

config.js

Generates temporary values to be used by other processors.

Sample:
data/main-config.js
'use strict';
module.exports = function (p) {
  p.env = process.env.ENVIRONMENT || 'PRD';
  p.hotels = p.hotels || {};
  p.hotels.middleware = p.hotels.middleware || {};

  switch (p.env) {
    case 'PRD':
      p.hotels.middleware.host = 'prod.sample.com.br';
      p.hotels.middleware.port = '80';
      break;
    default:
      p.hotels.middleware.host = '127.0.0.1';
      p.hotels.middleware.port = '7011';
  }
};
data/hotel/url.txt
`http://${p.hotels.middleware.host}:${p.hotels.middleware.port}/hotels`

Generate:

  • if ENVIRONMENT == PRD: http://prod.sample.com.br:80/hotels
  • if ENVIRONMENT <> PRD: http://127.0.0.1:7011/hotels

back to top