Skip to content

Commit

Permalink
Add naive argument type checks
Browse files Browse the repository at this point in the history
  • Loading branch information
kemitchell committed Mar 25, 2019
1 parent 8cd2009 commit 99d3e82
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -192,4 +192,24 @@ assert(!satisfies(
},
[{license: 'MIT'}]
))

assert.throws(function () {
satisfies('MIT', [parse('MIT')])
}, /first argument/)

assert.throws(function () {
satisfies({invalid: 'AST'}, [parse('MIT')])
}, /first argument/)

assert.throws(function () {
satisfies(parse('MIT'), parse('MIT'))
}, /second argument/)

assert.throws(function () {
satisfies(parse('MIT'), parse('MIT'))
}, /second argument/)

assert.throws(function () {
satisfies(parse('MIT'), [{invalid: 'leaf'}])
}, /second argument/)
```
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@ var compare = require('spdx-compare')
var ranges = require('spdx-ranges')

module.exports = function (first, second) {
if (!Array.isArray(second)) throw new Error('second argument must be an Array')
if (second.some(function (element) {
return !element.hasOwnProperty('license')
})) throw new Error('second argument must contain license expression AST leaves')
if (
!first.hasOwnProperty('license') &&
!first.hasOwnProperty('conjunction')
) throw new Error('first argument must be a license expression AST')
var terms = normalizeGPLIdentifiers(first)
var whitelist = second.map(function (element) {
return normalizeGPLIdentifiers(element)
Expand Down

0 comments on commit 99d3e82

Please sign in to comment.