json-ld-api
json-ld-api copied to clipboard
`expand(..., extractAllScripts)` and typing
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
falsethen it will return a JSON-LD document (might be anobject, anarray, or perhaps anull); - If the option is
truethenexpand()returns necessarily anarray.
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 whenextractAllScriptsistrue;expand_all()will not acceptextractAllScriptsoption 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.