netlify-headers-parser
Advanced tools
Comparing version 5.0.0 to 6.0.0
{ | ||
"name": "netlify-headers-parser", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Parses Netlify headers into a JavaScript object representation", | ||
"main": "src/index.js", | ||
"type": "module", | ||
"exports": "./src/index.js", | ||
"main": "./src/index.js", | ||
"scripts": { | ||
@@ -21,4 +23,4 @@ "prepublishOnly": "npm ci && npm test", | ||
"config": { | ||
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"*.{js,md}\" \"{src,tests}/**/*.js\"", | ||
"prettier": "--ignore-path .gitignore --loglevel=warn \".github/**/*.{md,yml}\" \"*.{js,yml,json}\" \"{src,tests}/**/*.js\" \"!package-lock.json\" \"!CHANGELOG.md\"" | ||
"eslint": "--ignore-path .gitignore --cache --format=codeframe --max-warnings=0 \"*.{cjs,mjs,js,md}\" \"{src,tests}/**/*.{cjs,mjs,js}\"", | ||
"prettier": "--ignore-path .gitignore --loglevel=warn \".github/**/*.{md,yml}\" \"*.{cjs,mjs,js,yml,json}\" \"{src,tests}/**/*.{cjs,mjs,js}\" \"!package-lock.json\" \"!CHANGELOG.md\"" | ||
}, | ||
@@ -41,3 +43,3 @@ "keywords": [ | ||
"devDependencies": { | ||
"@netlify/eslint-config-node": "^3.3.8", | ||
"@netlify/eslint-config-node": "^3.3.11", | ||
"ava": "^3.0.0", | ||
@@ -44,0 +46,0 @@ "nyc": "^15.1.0", |
@@ -1,10 +0,15 @@ | ||
const { parseFileHeaders } = require('./line_parser') | ||
const { mergeHeaders } = require('./merge') | ||
const { parseConfigHeaders } = require('./netlify_config_parser') | ||
const { normalizeHeaders } = require('./normalize') | ||
const { splitResults, concatResults } = require('./results') | ||
import { parseFileHeaders } from './line_parser.js' | ||
import { mergeHeaders } from './merge.js' | ||
import { parseConfigHeaders } from './netlify_config_parser.js' | ||
import { normalizeHeaders } from './normalize.js' | ||
import { splitResults, concatResults } from './results.js' | ||
// Parse all headers from `netlify.toml` and `_headers` file, then normalize | ||
// and validate those. | ||
const parseAllHeaders = async function ({ headersFiles = [], netlifyConfigPath, configHeaders = [], minimal = false }) { | ||
export const parseAllHeaders = async function ({ | ||
headersFiles = [], | ||
netlifyConfigPath, | ||
configHeaders = [], | ||
minimal = false, | ||
}) { | ||
const [ | ||
@@ -47,3 +52,1 @@ { headers: fileHeaders, errors: fileParseErrors }, | ||
} | ||
module.exports = { parseAllHeaders } |
'use strict' | ||
const escapeStringRegExp = require('escape-string-regexp') | ||
import escapeStringRegExp from 'escape-string-regexp' | ||
// Retrieve `forRegExp` which is a `RegExp` used to match the `for` path | ||
const getForRegExp = function (forPath) { | ||
export const getForRegExp = function (forPath) { | ||
const pattern = forPath.split('/').map(trimString).filter(Boolean).map(getPartRegExp).join('/') | ||
@@ -39,3 +39,1 @@ return new RegExp(`^/${pattern}/?$`, 'iu') | ||
const CATCH_ALL_CHAR_REGEXP = /\*/g | ||
module.exports = { getForRegExp } |
@@ -1,3 +0,1 @@ | ||
const { parseAllHeaders } = require('./all') | ||
module.exports = { parseAllHeaders } | ||
export { parseAllHeaders } from './all.js' |
@@ -1,7 +0,7 @@ | ||
const fs = require('fs') | ||
const { promisify } = require('util') | ||
import fs from 'fs' | ||
import { promisify } from 'util' | ||
const pathExists = require('path-exists') | ||
import pathExists from 'path-exists' | ||
const { splitResults } = require('./results') | ||
import { splitResults } from './results.js' | ||
@@ -12,3 +12,3 @@ const readFileAsync = promisify(fs.readFile) | ||
// the `headers` property in `netlify.toml` | ||
const parseFileHeaders = async function (headersFile) { | ||
export const parseFileHeaders = async function (headersFile) { | ||
const results = await parseHeaders(headersFile) | ||
@@ -107,3 +107,1 @@ const { headers, errors: parseErrors } = splitResults(results) | ||
} | ||
module.exports = { parseFileHeaders } |
@@ -1,4 +0,4 @@ | ||
const { isDeepStrictEqual } = require('util') | ||
import { isDeepStrictEqual } from 'util' | ||
const { splitResults } = require('./results') | ||
import { splitResults } from './results.js' | ||
@@ -19,3 +19,3 @@ // Merge headers from `_headers` with the ones from `netlify.toml`. | ||
// as `netlify.toml` headers. | ||
const mergeHeaders = function ({ fileHeaders, configHeaders }) { | ||
export const mergeHeaders = function ({ fileHeaders, configHeaders }) { | ||
const results = [...fileHeaders, ...configHeaders] | ||
@@ -34,3 +34,1 @@ const { headers, errors } = splitResults(results) | ||
} | ||
module.exports = { mergeHeaders } |
@@ -1,8 +0,8 @@ | ||
const { readFile } = require('fs') | ||
const { promisify } = require('util') | ||
import { readFile } from 'fs' | ||
import { promisify } from 'util' | ||
const pathExists = require('path-exists') | ||
const { parse: loadToml } = require('toml') | ||
import pathExists from 'path-exists' | ||
import { parse as loadToml } from 'toml' | ||
const { splitResults } = require('./results') | ||
import { splitResults } from './results.js' | ||
@@ -14,3 +14,3 @@ const pReadFile = promisify(readFile) | ||
// normalizes it. | ||
const parseConfigHeaders = async function (netlifyConfigPath) { | ||
export const parseConfigHeaders = async function (netlifyConfigPath) { | ||
if (!(await pathExists(netlifyConfigPath))) { | ||
@@ -39,3 +39,1 @@ return splitResults([]) | ||
} | ||
module.exports = { parseConfigHeaders } |
@@ -1,6 +0,6 @@ | ||
const isPlainObj = require('is-plain-obj') | ||
const mapObj = require('map-obj') | ||
import isPlainObj from 'is-plain-obj' | ||
import mapObj from 'map-obj' | ||
const { getForRegExp } = require('./for_regexp') | ||
const { splitResults } = require('./results') | ||
import { getForRegExp } from './for_regexp.js' | ||
import { splitResults } from './results.js' | ||
@@ -10,3 +10,3 @@ // Validate and normalize an array of `headers` objects. | ||
// `netlify.toml` or `_headerss`. | ||
const normalizeHeaders = function (headers, minimal) { | ||
export const normalizeHeaders = function (headers, minimal) { | ||
if (!Array.isArray(headers)) { | ||
@@ -133,3 +133,1 @@ const error = new TypeError(`Headers must be an array not: ${headers}`) | ||
} | ||
module.exports = { normalizeHeaders } |
// If one header fails to parse, we still try to return the other ones | ||
const splitResults = function (results) { | ||
export const splitResults = function (results) { | ||
const headers = results.filter((result) => !isError(result)) | ||
@@ -13,3 +13,3 @@ const errors = results.filter(isError) | ||
// Concatenate an array of `{ headers, erors }` | ||
const concatResults = function (resultsArrays) { | ||
export const concatResults = function (resultsArrays) { | ||
// eslint-disable-next-line unicorn/prefer-spread | ||
@@ -29,3 +29,1 @@ const headers = [].concat(...resultsArrays.map(getHeaders)) | ||
} | ||
module.exports = { splitResults, concatResults } |
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
Yes
16938
351