netlify-headers-parser
Advanced tools
Comparing version 2.1.0 to 2.1.1
{ | ||
"name": "netlify-headers-parser", | ||
"version": "2.1.0", | ||
"version": "2.1.1", | ||
"description": "Parses Netlify headers into a JavaScript object representation", | ||
@@ -5,0 +5,0 @@ "main": "src/index.js", |
const { inspect, isDeepStrictEqual } = require('util') | ||
const { splitResults } = require('./results') | ||
// Merge headers from `_headers` with the ones from `netlify.toml`. | ||
@@ -18,20 +20,12 @@ // When: | ||
const mergeHeaders = function ({ fileHeaders = [], configHeaders = [] }) { | ||
const errors = validateArrays(fileHeaders, configHeaders) | ||
if (errors.length !== 0) { | ||
return { headers: [], errors } | ||
} | ||
const headers = [...fileHeaders, ...configHeaders].filter(isUniqueHeader) | ||
return { headers, errors: [] } | ||
const results = [...validateArray(fileHeaders), ...validateArray(configHeaders)] | ||
const { headers, errors } = splitResults(results) | ||
const mergedHeaders = headers.filter(isUniqueHeader) | ||
return { headers: mergedHeaders, errors } | ||
} | ||
const validateArrays = function (fileHeaders, configHeaders) { | ||
const fileError = validateArray(fileHeaders) | ||
const configError = validateArray(configHeaders) | ||
return [fileError, configError].filter(Boolean) | ||
} | ||
const validateArray = function (headers) { | ||
if (!Array.isArray(headers)) { | ||
return new TypeError(`Headers should be an array: ${inspect(headers, { colors: false })}`) | ||
} | ||
return Array.isArray(headers) | ||
? headers | ||
: [new TypeError(`Headers should be an array: ${inspect(headers, { colors: false })}`)] | ||
} | ||
@@ -38,0 +32,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
16050
318