Skip to content

jslicense/correct-license-metadata.js

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

interpret old-style npm licenses arrays and other aberrations

var correct = require('correct-license-metadata')
var assert = require('assert')

assert.strictEqual(
  correct({ license: '(MIT OR GPL-2.0-only)' }), // valid metadata
  '(MIT OR GPL-2.0-only)'
)

assert.strictEqual(
  correct({
    licenses: [ // old-style licenses array
      {
        type: 'MIT',
        url: 'http://opensource.org/licenses/MIT'
      }
    ]
  }),
  'MIT'
)

assert.strictEqual(
  correct({
    license: {
      type: 'MIT',
      url: 'https://github.com/isaacs/rimraf/raw/master/LICENSE'
    }
  }),
  'MIT'
)

assert.strictEqual(
  correct({
    licenses: [
      {
        type: 'Apache License 2.0', // invalid SPDX ID
        url: 'https://github.com/Microsoft/tslib/blob/master/LICENSE.txt'
      }
    ]
  }),
  'Apache-2.0'
)

assert.strictEqual(
  correct({
    license: [ // old-style license array
      {
        type: 'MIT',
        url: 'http://opensource.org/licenses/MIT'
      }
    ]
  }),
  'MIT'
)

assert.strictEqual(
  correct({ license: "MIT/X11" }),
  'MIT'
)

assert.strictEqual(
  correct({ licenses: ['MIT'] }), // invalid
  'MIT'
)

assert.strictEqual(
  correct({
    licenses: ['MIT'], // invalid
    license: 'GPL-3.0' // valid, conflicting
  }),
  false
)

assert.throws(
  function () { correct('not an object') },
  /argument must be an object/
)

About

interpret old-style npm licenses arrays and other aberrations

Resources

License

Stars

Watchers

Forks

Packages

No packages published