GithubHelp home page GithubHelp logo

nice-registry / all-the-packages Goto Github PK

View Code? Open in Web Editor NEW
24.0 2.0 14.0 87.75 MB

:package: All the npm registry metadata as an offline event stream. [DEPRECATED]

Home Page: https://github.com/nice-registry/all-the-packages/issues/2

JavaScript 100.00%

all-the-packages's Introduction

all-the-packages

All the npm registry metadata as an offline event stream.

Why?

See https://github.com/nice-registry/about#why

Installation

npm install all-the-packages --save

When you install this package, a postinstall script downloads the npm registry metadata to a local JSON file, which is about 540 MB.

To refresh the module once you've already installed it, just reinstall:

npm i all-the-packages@latest

Usage

This package provides a simple event emitter that emits two events: package and end.

const registry = require('all-the-packages')

registry
  .on('package', function (pkg) {
    console.log(`${pkg.name} - ${pkg.description}\n`)
  })
  .on('end', function () {
    // done
  })

To get cleaner package data, use nice-package:

const registry = require('all-the-packages')
const NicePackage = require('nice-package')
const coolPackages = []

registry
  .on('package', function (pkg) {
    if (pkg.name.match('cool') || pkg.description.match('cool')) {
      coolPackages.push(new NicePackage(pkg))
    }
  })
  .on('end', function () {
    // done
  })

Why Streams?

Streams are cool and all, but the main reason this module has a streaming interface is RAM. It would be nice to just require the module and have a giant registry object to work with, but a 400 MB JSON file is too big to fit in memory on most computers.

See Also

  • package-stream: An endless stream of clean package data from the npm registry.
  • nice-package: Clean up messy package metadata from the npm registry

Tests

npm install
npm test

Dependencies

  • JSONStream: rawStream.pipe(JSONStream.parse()).pipe(streamOfObjects)
  • event-stream: construct pipes of streams of events

Dev Dependencies

  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

License

MIT

Generated by package-json-to-readme

all-the-packages's People

Contributors

zeke avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

all-the-packages's Issues

A few invalid "test" packages in the registry

Not sure if valid bug, or if it's your job to be the package sheriff, but I got a couple errors due to my garbage coding, because it turns out now all packages in the npm registry have a name (go figure).

Steps to reproduce:

const registry = require('all-the-packages');

filterByName(/^eslint-plugin-/i)
  .then((packages) => console.log(packages.length))
  .catch(err => console.error(err));

function filterByName(name) {
  return new Promise((resolve) => {
    const packages = [];
    registry.on('package', (pkg) => {
      if (pkg.name && pkg.name.match(name)) {
        packages.push(pkg);
      }
      if (!pkg.name) {
        console.log("DEBUG:", pkg);
      }
    }).on('end', () => resolve(packages));
  });
}

Output:

$ time node index

DEBUG: { dist: { tarball: 'http://registry.npmjs.org/testx2/-/a' },
  maintainers: [ { name: 'testx5', email: '[email protected]' } ],
  _npmUser: { name: 'testx5', email: '[email protected]' } }

DEBUG: { dist: { tarball: 'http://registry.npmjs.org/zachtestproject2/-/test.tgz' },
  maintainers: [ { name: 'zlrenner', email: '[email protected]' } ],
  _npmUser: { name: 'zlrenner', email: '[email protected]' } }

DEBUG: { dist:
   { tarball: 'http://registry.npmjs.org/zachtestproject3/-/test.tgz',
     _from: 'http://zachrenner.com/test.tgz' },
  maintainers: [ { name: 'zlrenner', email: '[email protected]' } ],
  _npmUser: { name: 'zlrenner', email: '[email protected]' } }

DEBUG: { dist:
   { tarball: 'http://registry.npmjs.org/zachtestproject4/-/test.tgz',
     _from: 'http://zachrenner.com/test.tgz',
     _shasum: 'asd' },
  maintainers: [ { name: 'zlrenner', email: '[email protected]' } ],
  _npmUser: { name: 'zlrenner', email: '[email protected]' } }

346

# node index  51.87s user 1.22s system 100% cpu 52.707 total

Anyways, not sure if you want to emit the package event only if the pkg.value in question passes some basic schema (ie: has a name and version property). ๐Ÿคท

Where are all the READMEs?

I'm running this piece of code to try and count what percent of packages in the registry have README files.

let haves = 0
let total = 0

registry.on('package', (pkg) => {
  total++
  if (pkg.readme) haves++
  if (total % 1000 === 0) console.log(`${haves} / ${total}    ${(100 * haves / total).toFixed(1)}%`)
})
registry.on('end', () => {
  console.log(`${haves} / ${total}`)
  console.log('percent =', (100 * haves / total).toFixed(2))
  process.stderr.write('DONE\n')
  process.exit(0)
})

Now if I use

const registry = require('all-the-packages')

I get one answer: 25394 / 412075 or about 6.2%

But if I use

const registry = require('package-stream')()

I get a completely different answer. Right now I'm only about 1/4 of the way through (100,000 packages) but it's at 95666 READMEs or 95%.

What's going on?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.