From 7a6bf45f426526b3fb215262fab74683298a5a68 Mon Sep 17 00:00:00 2001 From: Alexey Reznikov Date: Fri, 15 Nov 2024 18:29:19 +0200 Subject: [PATCH 1/2] expose grammar as a public object to allow for custom grammar --- README.md | 12 ++++++++++++ lib/index.js | 2 ++ 2 files changed, 14 insertions(+) diff --git a/README.md b/README.md index 91a041b..6767a1c 100644 --- a/README.md +++ b/README.md @@ -236,6 +236,18 @@ sdpTransform.write(res).split('\r\n'); // res parsed above The only thing different from the original input is we follow the order specified by the SDP RFC, and we will always do so. +## Usage - Custom grammar + +In case you need to add custom grammar (e.g. add unofficial attributes) to the parser, you can do so by mutating the `grammar` object before parsing. + +```js +sdpTransform.grammar['a'].push({ + name: 'xCustomTag', + reg: /^x-custom-tag:(\d*)/, + names: ['tagId'], + format: 'x-custom:%d +}) +``` ## License diff --git a/lib/index.js b/lib/index.js index 0a27894..800d80e 100644 --- a/lib/index.js +++ b/lib/index.js @@ -1,6 +1,8 @@ var parser = require('./parser'); var writer = require('./writer'); +var grammar = require('./grammar'); +exports.grammar = grammar; exports.write = writer; exports.parse = parser.parse; exports.parseParams = parser.parseParams; From 50b1c1f48b08a68f226d6cc9edacadd5c43c3b69 Mon Sep 17 00:00:00 2001 From: Alexey Reznikov Date: Fri, 15 Nov 2024 18:34:26 +0200 Subject: [PATCH 2/2] fixed incorrect format in readme example --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 6767a1c..7551093 100644 --- a/README.md +++ b/README.md @@ -245,7 +245,7 @@ sdpTransform.grammar['a'].push({ name: 'xCustomTag', reg: /^x-custom-tag:(\d*)/, names: ['tagId'], - format: 'x-custom:%d + format: 'x-custom-tag:%d }) ```