package-license-types

Extract license types from package.json data


Keywords
spdx, data, package, license, type
License
MIT
Install
bower install package-license-types

Documentation

package-license-types

NPM version Bower version Build Status Build status Coverage Status Dependency Status devDependency Status

Extract license types from package data

var pkg = {
  name: 'foo',
  version: '1.0.0',
  description: 'Lorem ipsum dolor sit amet',
  repository: 'shinnn/foo',
  author: 'Shinnosuke Watanabe',
  licenses: [
    'BSD-3-Clause',
    {
      type: 'MIT',
      url: 'LICENSE.md'
    }
  ]
};

packageLicenseTypes(pkg); //=> ['BSD-3-Clause', 'MIT']

It supports package.json, bower.json and component.json.

Installation

Package managers

npm

npm install package-license-types

bower

bower install package-license-types

Duo

var packageLicenseTypes = require('shinnn/package-license-types');

Standalone

Download the script file directly and install the dependency.

Dependency

API

packageLicenseTypes(packageData)

packageData: Object
Return: Array of String

It returns an array of the SPDX license identifiers specified in the license and licenses properties of its first argument.

var packageLicenseTypes = require('package-license-types');

var pkg = require('./package.json');
packageLicenseTypes(pkg); //=> ['MIT']
packageLicenseTypes({
  licenses: [
    'MIT',        // valid SPDX license identifier
    'foo-bar-baz' // invalid
  ]
}); //=> ['MIT']

It returns an empty array when it cannot find any license types from data.

packageLicenseTypes({
  license: {
    url: 'https://github.com/shinnn/package-license-types/blob/master/LICENSE'
  }
}); //=> []

License

Copyright (c) 2014 - 2015 Shinnosuke Watanabe

Licensed under the MIT License.