nice-registry/nice-package

Name: nice-package

Owner: nice-registry

Description: ? Clean up messy package metadata from the npm registry

Created: 2016-07-05 19:46:17.0

Updated: 2017-12-21 18:00:51.0

Pushed: 2017-02-06 05:32:06.0

Homepage:

Size: 125

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

nice-package ??? Build Status

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-package-data which does a lot of work to clean this data up, but the resulting object is still a bit confusing.

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

See Also
Installation
install nice-package --save
Usage

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:

t got = require('got')
t Package = require('nice-package')

'https://registry.npmjs.com/express', {json: true})
hen(function (doc) {
var pkg = new Package(doc)
console.log(JSON.stringify(pkg, null, 2))

You can also instantiate a nice package from package.json data:

t Package = require('nice-package')
t pkg = new Package(require('node_modules/express/package.json'))

dependsOn('array-flatten')
> true
Customizing the Package Object

You can pick specific properties to return:

t pkg = new Package(pkgData, {pick: ['name', 'description']})


 name: 'tlds',
 description: 'List of TLDs'

or you can omit properties. Sometimes you don't want the other data, the readme, etc.

t pkg = new Package(pkgData, {omit: ['other', 'readme', 'versions']})

Note: pick and omit will also accept comma-delimited strings instead of arrays. This works nicely if you're using query params from a URL as options to nice-package:

t pkg = new Package(pkgData, {omit: 'other,readme,versions'})
Convenience Methods

A nice package comes with convenience methods:

pkg.mentions(query)

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

pkg.dependsOn(pkgName)

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

pkg.devDependsOn(pkgName)

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

pkg.somehowDependsOn(pkgName)

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

pkg.depNames

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

pkg.devDepNames

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

pkg.allDepNames

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

Validation

nice-package uses a JSON schema to validate packages.

The following properties are required:

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

valid
> false

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

validationErrors

The result is an array of revalidator errors.

Tests
install
test
Dependencies
Dev Dependencies
License

MIT

Credits

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

Generated by package-json-to-readme


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.