1.0.0-beta.7 • Published 11 months ago

@klnjs/referrer-policy v1.0.0-beta.7

Weekly downloads
-
License
MIT
Repository
github
Last release
11 months ago

@klnjs/referrer-policy

This module provides types and functionality for parsing and stringifying Referrer Policy.

Installation

Install the @klnjs/referrer-policy package using your preferred package manager.

npm install @klnjs/referrer-policy

How to Use

Importing

Import the module, and optionally the ReferrerPolicy type.

import RR, { type ReferrerPolicy } from '@klnjs/referrer-policy'

Parsing

Parse a permission policy string into a ReferrerPolicy object with the parse method:

const policy = RR.parse('strict-origin-when-cross-origin')

Stringifying

Serialize a ReferrerPolicy object with the stringify method:

const header = RR.stringify('strict-origin-when-cross-origin')

Validation

Parsing validates the referrer policy. If an invalid policy is encountered, a SyntaxError is thrown.

try {
	const policy = RR.parse('invalid-policy')
} catch (error) {
	console.error(error) // SyntaxError: ReferrerPolicy.parse: invalid policy "invalid-policy"
}
1.0.0-beta.7

11 months ago

1.0.0-beta.6

1 year ago

1.0.0-beta.5

1 year ago

1.0.0-beta.4

1 year ago

1.0.0-beta.3

1 year ago