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

hsipe

v2.0.1

Published

Here's Something I Prepared Earlier (via detached child-process)

Downloads

93

Readme

hsipe npm AppVeyor Status Travis CI Status

Here's Something I Prepared Earlier (via detached child-process)

Usage

I borrowed this idea by seeing how update-notifier operates.

The ideal use case is when you have a time-consuming asynchronous task (e.g. baking a cake, making an HTTP request, scanning a disk, etc), and you'd like to continue executing, even when those results are not ready yet. You assume that during a future execution of your script, you'll have access to the results of that previous run.

putInOven(options: OvenOptions, ...args: any[])

type OvenOptions = {
  bakePath: string,
  cakeName: string,
  interval?: number
}

type Cake = {
  lastBaked?: number,
  [id:string]: any
}
  • bakePath is a path to a module that exports a BakeFunction named "bake"

  • cakeName is a unique identifier for the background work, and scripts that use the same results can share this

  • interval is the milliseconds to wait after a successful baking, to throttle your time-consuming task (default = 1 day)

type BakeFunction = (...args: any[]) => Promise<Cake>
type BakeOptions = {
  cake: Cake
}
  • your BakeFunction has access to the previous Cake, which could be useful for more-efficient / partial baking

  • your BakeFunction resolves with your Cake, and we automatically set "lastBaked" value in the Cake for you (used when checking interval)

getCake(options: CakeOptions) => Cake

type CakeOptions = {
  cakeName: string
}
  • cakeName must be the same cake that you putInOven() earlier

  • returns your Cake if it's ready (you'll have to check)

Example

index.js / cli.js (your entry-point):

const path = require('path')

const Conf = require('conf')
const { getCake, putInOven } = require('hsipe')

const cakeName = 'strawberry-shortcake'

// start baking our strawberry-shortcake
putInOven({ bakePath: path.join(__dirname, 'bake.js'), cakeName })

// try to continue on, in case we already started baking last time
const cake = getCake({ cakeName })
const flavour = cake.flavour

if (flavour) {
  // yay, we must have prepared something earlier
  // TODO: eat cake, enjoy flavour
} else {
  // ah, this must be our first time through here
  // better luck next time!
  // TODO: do something that doesn't require eating delicious cake
}

bake.js:

function bake ({ cake }, ...args) {
  // e.g. something that can take a while to finish
  return new Promise((resolve) => {
    setTimeout(() => {
      resolve({ flavour: 'delicious' })
    }, 5e3)
  })
}

module.exports = { bake }

Contributing

Development

npm install --global flow-typed
npm install
flow-typed install
npm test

See Also