netlify-headers-parser
Advanced tools
Comparing version 3.0.1 to 4.0.0
{ | ||
"name": "netlify-headers-parser", | ||
"version": "3.0.1", | ||
"version": "4.0.0", | ||
"description": "Parses Netlify headers into a JavaScript object representation", | ||
@@ -33,2 +33,3 @@ "main": "src/index.js", | ||
"dependencies": { | ||
"escape-string-regexp": "^4.0.0", | ||
"is-plain-obj": "^3.0.0", | ||
@@ -35,0 +36,0 @@ "map-obj": "^4.2.1", |
@@ -9,3 +9,3 @@ const { parseFileHeaders } = require('./line_parser') | ||
// and validate those. | ||
const parseAllHeaders = async function ({ headersFiles = [], netlifyConfigPath, configHeaders = [] }) { | ||
const parseAllHeaders = async function ({ headersFiles = [], netlifyConfigPath, configHeaders = [], minimal = false }) { | ||
const [ | ||
@@ -15,6 +15,8 @@ { headers: fileHeaders, errors: fileParseErrors }, | ||
] = await Promise.all([getFileHeaders(headersFiles), getConfigHeaders(netlifyConfigPath)]) | ||
const { headers: normalizedFileHeaders, errors: fileNormalizeErrors } = normalizeHeaders(fileHeaders) | ||
const { headers: normalizedConfigParseHeaders, errors: configParseNormalizeErrors } = | ||
normalizeHeaders(parsedConfigHeaders) | ||
const { headers: normalizedConfigHeaders, errors: configNormalizeErrors } = normalizeHeaders(configHeaders) | ||
const { headers: normalizedFileHeaders, errors: fileNormalizeErrors } = normalizeHeaders(fileHeaders, minimal) | ||
const { headers: normalizedConfigParseHeaders, errors: configParseNormalizeErrors } = normalizeHeaders( | ||
parsedConfigHeaders, | ||
minimal, | ||
) | ||
const { headers: normalizedConfigHeaders, errors: configNormalizeErrors } = normalizeHeaders(configHeaders, minimal) | ||
const { headers, errors: mergeErrors } = mergeHeaders({ | ||
@@ -21,0 +23,0 @@ fileHeaders: normalizedFileHeaders, |
const isPlainObj = require('is-plain-obj') | ||
const mapObj = require('map-obj') | ||
const { getForRegExp } = require('./for_regexp') | ||
const { splitResults } = require('./results') | ||
@@ -9,3 +10,3 @@ | ||
// `netlify.toml` or `_headerss`. | ||
const normalizeHeaders = function (headers) { | ||
const normalizeHeaders = function (headers, minimal) { | ||
if (!Array.isArray(headers)) { | ||
@@ -16,7 +17,7 @@ const error = new TypeError(`Headers must be an array not: ${headers}`) | ||
const results = headers.map(parseHeader).filter(Boolean) | ||
const results = headers.map((header, index) => parseHeader(header, index, minimal)).filter(Boolean) | ||
return splitResults(results) | ||
} | ||
const parseHeader = function (header, index) { | ||
const parseHeader = function (header, index, minimal) { | ||
if (!isPlainObj(header)) { | ||
@@ -27,3 +28,3 @@ return new TypeError(`Header must be an object not: ${header}`) | ||
try { | ||
return parseHeaderObject(header) | ||
return parseHeaderObject(header, minimal) | ||
} catch (error) { | ||
@@ -37,4 +38,4 @@ return new Error(`Could not parse header number ${index + 1}: | ||
// Parse a single `headers` object | ||
const parseHeaderObject = function ({ for: rawPath, values: rawValues }) { | ||
const path = normalizePath(rawPath) | ||
const parseHeaderObject = function ({ for: rawPath, values: rawValues }, minimal) { | ||
const forPath = normalizePath(rawPath) | ||
@@ -51,3 +52,7 @@ if (rawValues === undefined) { | ||
return { for: path, values } | ||
return { | ||
for: forPath, | ||
...(minimal || { forRegExp: getForRegExp(forPath) }), | ||
values, | ||
} | ||
} | ||
@@ -54,0 +59,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
17144
11
354
5
+ Addedescape-string-regexp@^4.0.0
+ Addedescape-string-regexp@4.0.0(transitive)