@squeep/web-linking
v1.1.0
Published
Parser for RFC 8288 Link headers
Readme
An RFC8288 Parsing Library
What
This is a minimal parser for HTTP Link Headers, basically just a wrapper around a PEG grammar.
API
parse(text: string, options?: object)
Parse string as a Link header value, returning an array of link objects.
The available options are as documented in peggy.
Produces this:const { parse, SyntaxError: ParserSyntaxError } = require('@squeep/web-linking'); const result = parse('</TheBook/chapter2>;rel="previous"; title*=UTF-8\'de\'letztes%20Kapitel,</TheBook/chapter4>;rel="next"; title*=UTF-8\'de\'n%c3%a4chstes%20Kapitel'); console.log(JSON.stringify(result, undefined, 2));[ { "target": "/TheBook/chapter2", "attributes": [ { "name": "rel", "extended": false, "value": "previous" }, { "name": "title*", "extended": true, "value": "UTF-8'de'letztes%20Kapitel" } ] }, { "target": "/TheBook/chapter4", "attributes": [ { "name": "rel", "extended": false, "value": "next" }, { "name": "title*", "extended": true, "value": "UTF-8'de'n%c3%a4chstes%20Kapitel" } ] } ]
Notes
After updating the grammar, npm run generate will compile the parser.
