From fe56c5143fffdadd192f6cbb3e099d365733b7dd Mon Sep 17 00:00:00 2001 From: Benjamin Young Date: Wed, 20 Mar 2024 17:05:11 -0400 Subject: [PATCH 1/4] Add --context option to format. --- bin/jsonld.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/jsonld.js b/bin/jsonld.js index 98234bf..9373473 100755 --- a/bin/jsonld.js +++ b/bin/jsonld.js @@ -253,6 +253,7 @@ program _jsonLdCommand(program.command('format [filename|URL|-]')) .description('format and convert JSON-LD') + .option('-c, --context ', 'context filename or URL') .option('-f, --format ', 'output format [json]', String) .option('-q, --n-quads', 'output application/n-quads [false]') .option('-j, --json', 'output application/json [true]') @@ -266,6 +267,9 @@ _jsonLdCommand(program.command('format [filename|URL|-]')) if(cmd.json) { options.format = 'application/json'; } + if(cmd.context) { + options.expandContext = cmd.context; + } let result; switch(options.format.toLowerCase()) { From aa81337a4a6f0f333b6ba79fc8959823107950e9 Mon Sep 17 00:00:00 2001 From: Benjamin Young Date: Wed, 27 Mar 2024 13:32:35 -0400 Subject: [PATCH 2/4] Add --context to expand. --- bin/jsonld.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/jsonld.js b/bin/jsonld.js index 9373473..afa6664 100755 --- a/bin/jsonld.js +++ b/bin/jsonld.js @@ -333,10 +333,14 @@ _jsonLdCommand(program.command('compact [filename|URL]')) _jsonLdCommand(program.command('expand [filename|URL|-]')) .description('expand JSON-LD') + .option('-c, --context ', 'context filename or URL') .option(' --keep-free-floating-nodes', 'keep free-floating nodes') .action(async function expand(input, cmd) { input = input || '-'; const options = _jsonLdOptions(cmd, input); + if(cmd.context) { + options.expandContext = cmd.context; + } options.keepFreeFloatingNodes = cmd.keepFreeFloatingNodes; const result = await jsonld.expand(input, options); From f2ef260cee7f8a27844b26c2b172e6306013814f Mon Sep 17 00:00:00 2001 From: Benjamin Young Date: Wed, 27 Mar 2024 13:52:59 -0400 Subject: [PATCH 3/4] Add --context to lint command. --- bin/jsonld.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/bin/jsonld.js b/bin/jsonld.js index afa6664..0243329 100755 --- a/bin/jsonld.js +++ b/bin/jsonld.js @@ -301,9 +301,13 @@ _jsonLdCommand(program.command('format [filename|URL|-]')) _jsonLdCommand(program.command('lint [filename|URL|-]')) .description('lint JSON-LD') + .option('-c, --context ', 'context filename or URL') .action(async function lint(input, cmd) { input = input || '-'; const options = _jsonLdOptions(cmd, input); + if(cmd.context) { + options.expandContext = cmd.context; + } await jsonld.expand(input, { ...options, From 5b2e13c7749ad37b3869989c91207a1b7fbb28aa Mon Sep 17 00:00:00 2001 From: Benjamin Young Date: Wed, 27 Mar 2024 13:55:16 -0400 Subject: [PATCH 4/4] Refactor cmd.command checks into _jsonLdOptions. --- bin/jsonld.js | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/bin/jsonld.js b/bin/jsonld.js index 0243329..5a1a4e1 100755 --- a/bin/jsonld.js +++ b/bin/jsonld.js @@ -208,6 +208,10 @@ function _jsonLdOptions(command, input) { options.safe = true; } + if(command.context) { + options.expandContext = command.context; + } + options.base = _getBase(command, input); // setup documentLoader @@ -267,9 +271,6 @@ _jsonLdCommand(program.command('format [filename|URL|-]')) if(cmd.json) { options.format = 'application/json'; } - if(cmd.context) { - options.expandContext = cmd.context; - } let result; switch(options.format.toLowerCase()) { @@ -305,9 +306,6 @@ _jsonLdCommand(program.command('lint [filename|URL|-]')) .action(async function lint(input, cmd) { input = input || '-'; const options = _jsonLdOptions(cmd, input); - if(cmd.context) { - options.expandContext = cmd.context; - } await jsonld.expand(input, { ...options, @@ -342,9 +340,6 @@ _jsonLdCommand(program.command('expand [filename|URL|-]')) .action(async function expand(input, cmd) { input = input || '-'; const options = _jsonLdOptions(cmd, input); - if(cmd.context) { - options.expandContext = cmd.context; - } options.keepFreeFloatingNodes = cmd.keepFreeFloatingNodes; const result = await jsonld.expand(input, options);