@klnjs/reporting-endpoints
v1.0.0-beta.7
Published
This module provides types and functionality for parsing and stringifying Strict Transport Security (HSTS).
Downloads
86
Maintainers
Readme
@klnjs/reporting-endpoints
This module provides types and functionality for parsing and stringifying Strict Transport Security (HSTS).
Installation
Install the @klnjs/reporting-endpoints
package using your preferred package manager.
npm install @klnjs/reporting-endpoints
How to Use
Importing
Import the module, and optionally the ReportingEndpoints
type.
import STS, { type ReportingEndpoints } from '@klnjs/reporting-endpoints'
Parsing
Parse a permission policy string into a ReportingEndpoints
object with the parse
method:
const endpoints = RE.parse('endpoint=https://trusted.com')
Stringifying
Serialize a ReportingEndpoints
object with the stringify
method:
const header = RE.stringify({ endpoint: 'https://trusted.com' })
Validation
Parsing validates endpoints and urls. If an invalid endpoint or url is encountered during parsing, a SyntaxError is thrown.
try {
const endpoints = RE.parse('endpoint=invalid-url')
} catch (error) {
console.error(error) // SyntaxError: ReportingEndpoints.parse: invalid url "invalid-url" for endpoint "endpoint"
}