<|start_filename|>tests/node_modules/conformance/package.json<|end_filename|>
{
  "_from": "conformance@^1.0.0",
  "_id": "conformance@1.0.0",
  "_inBundle": false,
  "_integrity": "sha512-yHNr1QYQIigTHww52pFTppBQaAJVDJgOpN0I+fvzzf3V0WmGeIzHisaHoTeCN/V49Zwp4v8YNhLzDFnP0hsBEw==",
  "_location": "/conformance",
  "_phantomChildren": {},
  "_requested": {
    "type": "range",
    "registry": true,
    "raw": "conformance@^1.0.0",
    "name": "conformance",
    "escapedName": "conformance",
    "rawSpec": "^1.0.0",
    "saveSpec": null,
    "fetchSpec": "^1.0.0"
  },
  "_requiredBy": [
    "/"
  ],
  "_resolved": "https://registry.npmjs.org/conformance/-/conformance-1.0.0.tgz",
  "_shasum": "9e6dd0ef734d065394efdac4f520a2034bddc598",
  "_spec": "conformance@^1.0.0",
  "_where": "/Users/cyren/GitHub/liblice",
  "author": {
    "name": "<NAME>",
    "email": "<EMAIL>"
  },
  "bugs": {
    "url": "https://github.com/cutenode/conformance/issues"
  },
  "bundleDependencies": false,
  "dependencies": {
    "spdx-expression-parse": "^3.0.0"
  },
  "deprecated": false,
  "description": "A module that helps you get insight into compliance with SPDX conformance.",
  "devDependencies": {
    "jest": "^24.8.0",
    "standard": "^13.1.0"
  },
  "directories": {
    "example": "examples",
    "lib": "lib",
    "test": "tests"
  },
  "files": [
    "/exports",
    "/lib",
    "/licenses"
  ],
  "homepage": "https://github.com/cutenode/conformance#readme",
  "keywords": [
    "licenses",
    "license",
    "conformance",
    "conform",
    "spdx",
    "osi",
    "Open Source Initiative",
    "fsf",
    "Free Software Foundation",
    "validate"
  ],
  "license": "MIT",
  "main": "index.js",
  "name": "conformance",
  "repository": {
    "type": "git",
    "url": "git+https://github.com/cutenode/conformance.git"
  },
  "scripts": {
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "standard": {
    "ignore": [
      "/tests"
    ]
  },
  "version": "1.0.0"
}


<|start_filename|>tests/parseLicense.test.js<|end_filename|>
const parseLicense = require('../lib/parseLicense')
const loadPackagejson = require('load-json-file')
const fs = require('fs')

describe('test `license` export', () => {

  test('test the output of an array that is identified by `licenses` (rather than `license`) that contains an object that has a type property', () => {
    const pkg = loadPackagejson.sync(`${__dirname}/dummy/package.arrayObjectType.json`)
    const actual = parseLicense(pkg)

    expect(actual).toEqual(
      'LOL'
    )
  })

  test('test the output of an string that is identified by `license`', () => {
    const pkg = loadPackagejson.sync(`${__dirname}/dummy/package.stringType.json`)
    const actual = parseLicense(pkg)

    expect(actual).toEqual(
      'BRB'
    )
  })

  test('test the output of an object that is identified by `license` which has a `type` property', () => {
    const pkg = loadPackagejson.sync(`${__dirname}/dummy/package.objectType.json`)
    const actual = parseLicense(pkg)

    expect(actual).toEqual(
      'OMG'
    )
  })

  test('test the output of an array that is identified by `licenses` but misconfigured as a single object', () => {
    const pkg = loadPackagejson.sync(`${__dirname}/dummy/package.misconfiguredObjectType.json`)
    const actual = parseLicense(pkg)

    expect(actual).toEqual(
      'LMAO'
    )
  })

  test('test the output of a missing license object is informative placeholder text', () => {
    const actual = parseLicense({})

    expect(actual).toEqual(
      'invalid license'
    )
  })

})


<|start_filename|>lib/parseLicense.js<|end_filename|>
// parse as many possible ways a license could be expressed as is humanly possible

function parse (file) {
  if (file.license !== undefined) {
    if (typeof file.license === 'string') {
      return handleUndefinedAndNull(file.license)
    }

    if (typeof file.license === 'object') {
      return handleUndefinedAndNull(file.license.type)
    }
  }

  if (file.licenses !== undefined) {
    if (Array.isArray(file.licenses)) {
      return handleUndefinedAndNull(file.licenses[0].type)
    }

    if (typeof file.licenses === 'object') {
      return handleUndefinedAndNull(file.licenses.type)
    }
  }

  return handleUndefinedAndNull(undefined)
}

function handleUndefinedAndNull (licenseString) {
  if (licenseString === undefined) {
    return 'invalid license'
  } else {
    return licenseString
  }
}

module.exports = parse


<|start_filename|>index.js<|end_filename|>
const list = require('./exports/list')
const modules = require('./exports/modules')
const licenses = require('./exports/licenses')

module.exports = {
  list: list,
  modules: modules,
  licenses: licenses
}


<|start_filename|>exports/list.js<|end_filename|>
const loadPackagejson = require('load-json-file')
const parseLicense = require('../lib/parseLicense')
const filtered = require('../lib/filterFileTree')

const buildArrayExport = function (directory) {
  const arrayOfPackageJsonFiles = filtered(directory)
  const arrayOfLicenses = []

  arrayOfPackageJsonFiles.forEach(function (jsonFile) {
    const loadedJSON = loadPackagejson.sync(jsonFile)
    const parsed = parseLicense(loadedJSON)
    arrayOfLicenses.push(parsed)
  })

  return arrayOfLicenses
}

module.exports = buildArrayExport
