serviejs / popsicle

Simple HTTP requests for node and the browser
MIT License
246 stars 19 forks source link

Need to export 'popsicle' object #123

Closed BebopTC closed 6 years ago

BebopTC commented 6 years ago

In documentation you use commonjs style require() to import the popsicle module, and then use it as follows:

const popsicle = require('popsicle')

popsicle.request({
  method: 'POST',
...
})
.use(popsicle.plugins.parse('json'))

However, the default export is the request object. So using es6 import syntax, following the example gives a popsicle.request is not a function error. Instead, one must do:

import { request, plugins } from 'popsicle'
request(...).use(plugins.parse('json')

not so bad in this tiny example, but if you're using lots of popsicle functions you end uup with a lot of named imports that pollute the namespace. Why not export a popsicle object, either named or by default, so that es6 users one can use syntax consistent with the examples in documentation?

blakeembrey commented 6 years ago

You could just do import * as popsicle from 'popsicle'.

BebopTC commented 6 years ago

Yeah I thought of that just now and came back to close this before anyone saw it haha. Doh