get-spdx-license-ids

2.1.0 • Public • Published

get-spdx-license-ids

npm version Build Status Coverage Status

A Node.js module to get an array of the latest SPDX license identifiers from spdx.org

const getSpdxLicenseIds = require('get-spdx-license-ids');
 
(async () => {
  const ids = await getSpdxLicenseIds();
  //=> ['0BSD', 'AAL', 'Abstyles', 'Adobe-2006', 'Adobe-Glyph', 'ADSL', 'AFL-1.1', 'AFL-1.2', ...]
})();

Installation

Use npm.

npm install get-spdx-license-ids

API

const getSpdxLicenseIds = require('get-spdx-license-ids');

getSpdxLicenseIds([options])

options: Object (request options without json option that defaults to true)
Return: Promise<Array<string>>

It retrieves an array of non-deprecated SPDX license identifiers from https://spdx.org/licenses/licenses.json.

(async () => {
  const ids = await getSpdxLicenseIds();
  ids.includes('MIT'); //=> true
  ids.includes('ISC'); //=> true
 
  ids.includes('GPL-1.0'); //=> false
})

getSpdxLicenseIds.deprecated([options])

Retrieves deprecated IDs only.

(async () => {
  const deprecatedIds = await getSpdxLicenseIds.deprecated();
  deprecatedIds.includes('MIT'); //=> false
  deprecatedIds.includes('ISC'); //=> false
 
  deprecatedIds.includes('GPL-1.0'); //=> true
})();

getSpdxLicenseIds.all([options])

Retrieves both deprecated and non-deprecated IDs in a single array.

(async () => {
  const allIds = await getSpdxLicenseIds.all();
  allIds.includes('MIT'); //=> true
  allIds.includes('ISC'); //=> true
  allIds.includes('GPL-1.0'); //=> false
})();

getSpdxLicenseIds.both([options])

Retrieves both deprecated and non-deprecated IDs in two separate arrays.

(async () => {
  const pair = await getSpdxLicenseIds.both();
  pair.length; //=> 2
 
  const [valid, deprecated] = pair;
 
  valid.includes('MIT'); //=> true
  valid.includes('ISC'); //=> true
 
  valid.includes('GPL-1.0'); //=> false
 
  deprecated.includes('MIT'); //=> false
  deprecated.includes('ISC'); //=> false
 
  deprecated.includes('GPL-1.0'); //=> true
})();

License

ISC License © 2018 Shinnosuke Watanabe

Package Sidebar

Install

npm i get-spdx-license-ids

Weekly Downloads

198

Version

2.1.0

License

ISC

Last publish

Collaborators

  • shinnn