json-ld-api icon indicating copy to clipboard operation
json-ld-api copied to clipboard

`expand(..., extractAllScripts)` and typing

Open anatoly-scherbakov opened this issue 1 year ago • 0 comments

As described in Process HTML section of the specification, it is described how expand() behaves on HTML documents with extractAllScripts option.

  • If that option is false then it will return a JSON-LD document (might be an object, an array, or perhaps a null);
  • If the option is true then expand() returns necessarily an array.

This means that the output type of expand() deterministically depends on its input parameters.

What if we could split expand() into two separate functions?

  • expand() will behave as it is behaving now, but it will print a deprecation message when extractAllScripts is true;
  • expand_all() will not accept extractAllScripts option and will always output an array. It will parse all scripts in a document.

Over time, expand() might be updated: it will no longer accept extractAllScripts option at all and it will only parse one <script> in the document.

P. S. This will be handy for YAML-LD to expand_all() multiple documents in a stream.

anatoly-scherbakov avatar Feb 19 '24 18:02 anatoly-scherbakov