0.0.13 • Published 8 years ago

run-gen v0.0.13

Weekly downloads
4
License
MIT
Repository
github
Last release
8 years ago
  • Use generators (almost) as you would normally use functions.
  • use result = yield Promise.resolve('result') to abstract the async
  • return result from generator as completion value

Install

npm i -S run-gen

Dev

git clone https://github.com/nhz-io/run-gen
cd run-gen
npm i
npm start

Coverage

npm run coverage

Example usage (NPM Downloads stats)

const fetch = require('node-fetch')
const run = require('run-gen')

const downloadsUrl = `https://api.npmjs.org/downloads/point`
const registryUrl = `https://registry.npmjs.org`

function* downloads(pkg, period) {
    const res = yield fetch(`${downloadsUrl}/${period}/${pkg}`)
    const stats = JSON.parse(yield res.text())
    return (stats && stats.downloads) || 'unknown'
}

function* info(pkg) {
    const res = yield fetch(`${registryUrl}/${pkg}`)
    const info = JSON.parse(yield res.text())
    return {
        name: info.name,
        description: info.description,
    }
}

function* stats(pkg, period = 'last-month') {
    return Object.assign(
        {},
        yield* info(pkg),
        {downloads: yield* downloads(pkg, period)}
    )
}

run(stats('npm')).then(r => console.log(r), e => console.log(e))

License

MIT

0.0.13

8 years ago

0.0.12

8 years ago

0.0.11

8 years ago

0.0.10

8 years ago

0.0.9

8 years ago

0.0.8

8 years ago

0.0.7

8 years ago

0.0.6

8 years ago

0.0.5

8 years ago

0.0.4

8 years ago

0.0.3

8 years ago

0.0.2

8 years ago

0.0.1

8 years ago