From 10db352ef7e87327185f408f308b0b000bd7e5cb Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 22 Nov 2024 13:55:58 -0800 Subject: [PATCH] update readme with example --- README.md | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/README.md b/README.md index b332bc4..f8b3c64 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,52 @@ 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](https://peggyjs.org/documentation.html#using-the-parser). + ```javascript + const { parse, SyntaxError: ParserSyntaxError } = require('@squeep/web-linking'); + const result = parse(';rel="previous"; title*=UTF-8\'de\'letztes%20Kapitel,;rel="next"; title*=UTF-8\'de\'n%c3%a4chstes%20Kapitel'); + console.log(JSON.stringify(result, undefined, 2)); + ``` + Produces this: + ```json + [ + { + "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. -- 2.45.2