Skip to content

Commit

Permalink
add option to override parse function
Browse files Browse the repository at this point in the history
  • Loading branch information
Dan Butvinik committed Dec 10, 2018
1 parent 4b0c707 commit f1930d5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,9 @@ assert(satisfies(
assert(satisfies('(MIT OR GPL-2.0)', '(ISC OR MIT)'))
assert(satisfies('(MIT AND GPL-2.0)', '(MIT OR GPL-2.0)'))
assert(!satisfies('(MIT AND GPL-2.0)', '(ISC OR GPL-2.0)'))

// bring your own parser
satisfies('MIT', 'MIT', {
parse: function (expression) { return {license: 'MIT'} }
})
```
6 changes: 4 additions & 2 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ function normalizeGPLIdentifiers (argument) {
argument.license = license.replace('-or-later', '')
delete argument.plus
}
} else {
} else if (argument.left && argument.right) {
argument.left = normalizeGPLIdentifiers(argument.left)
argument.right = normalizeGPLIdentifiers(argument.right)
}
Expand All @@ -104,7 +104,9 @@ function endsWith (string, substring) {
return string.indexOf(substring) === string.length - 1
}

module.exports = function (first, second) {
module.exports = function (first, second, options) {
options = options || {}
parse = options.parse || parse
return recurse(
normalizeGPLIdentifiers(parse(first)),
normalizeGPLIdentifiers(parse(second))
Expand Down

0 comments on commit f1930d5

Please sign in to comment.