node package manager

nice-package

Clean up messy package metadata from the npm registry

nice-package ✨📦✨

Clean up messy package metadata from the npm registry

The package data served by the npm registry is messy and confusing. The folks at npm, Inc maintain a tool called normalize-registry-metadata which does a lot of work to clean this data up, but the resulting object is still kind of inhumane.

nice-package uses normalize-package-data as a baseline, then does even more package cleanup:

  • uses the doc['dist-tags'].latest as the baseline for package metadata
  • turns users object into a star count
  • turns the time object into an array of version data
  • renames _npmUser to lastPublisher
  • renames maintainers to owners
  • parses GitHUB repository URLs into useful objects
  • removes internal bookkeeping properties like _id and _from
  • more...

See also package-stream, a tool that streams nice packages from the npm registry.

npm install nice-package --save

nice-package exports a class. To create a new package instance, call new Package(doc), where doc is a JSON package object from the npm registry:

const got = require('got')
const Package = require('nice-package')
 
got('https://registry.npmjs.com/express', {json:true})
  .then(function(doc) {
    var pkg = new Package(doc)
    console.log(JSON.stringify(pkg, null, 2))
  })

A nice package comes with convenience methods:

  • query String

Performs a case-insensitive search against the JSON-stringified object. Returns a Boolean indicating whether the given query is present in the object.

  • pkgName String - The name of another package

Returns a Boolean indicating whether the given pkgName is listed in dependencies.

  • pkgName String - The name of another package

Returns a Boolean indicating whether the given pkgName is listed in devDependencies.

A getter method that returns an array of the dependencies keys.

A getter method that returns an array of the devDependencies keys.

nice-package uses a JSON schema to validate packages.

The following properties are required:

  • name String
  • description String
  • version String

To determine if a package is valid, use the pkg.valid getter method:

pkg.valid
// => false 

To see validation errors on a package, use the pkg.validationErrors getter method:

pkg.validationErrors

The result is an array of revalidator errors.

npm install
npm test
  • require-dir: Helper to require() directories.
  • standard: JavaScript Standard Style
  • tap-spec: Formatted TAP output like Mocha's spec reporter
  • tape: tap-producing test harness for node and browsers

MIT

💛 Thanks to emilyrose for giving up the nice-package name on npm.

Generated by package-json-to-readme