rdfjs / N3.js

Lightning fast, spec-compatible, streaming RDF for JavaScript
http://rdf.js.org/N3.js/
Other
715 stars 131 forks source link

Extract Character Escaping Code to Separate Package #228

Open dhurlburtusa opened 3 years ago

dhurlburtusa commented 3 years ago

I've explored many of the RDF related libraries out in the wild. As far as I know, the N3 library is the most thorough and correct when it comes to character escaping.

I was thinking of extracting the character escaping code from N3 and move to a package that N3 and other libraries can import.

Note: The plan is to allow different escaping mechanisms depending on context and options. For example, when serializing for N-Triples or N-Quads, only the double quote enclosed syntax is allowed. However, for Turtle and TriG, several variations are allowed: double quotes, single quotes, triple double quotes, and triple single quotes. It looks like N3 will always use the double quotes syntax since it is compatible with all serializations that I am aware of. However, when writing out a Turtle or Trig file that has literals with line separators, it may be desirable to use the triple quotes variation and not change line separators to \n or \r\n.

Note: There is also a need to escape characters in the local portion of a prefixed URI.

The new character escaping package could then be used to address https://github.com/rubensworks/rdf-string-ttl.js/issues/1 and https://github.com/rdfjs-base/to-ntriples/issues/3.

I'd like to add this new package to RDFJS. Initially, I'll implement it in my own GH account but won't publish to NPM. Then, if willing, you can copy it from my GH account, add it to RDFJS, and publish to NPM. Name suggestion: @rdfjs/escapes. I'll design it to be tree-shakable (i.e., side-effect-free) since some libraries would not want support for the triple quote variations or the single quote variation.

I can then integrate it into N3 and rdf-string-ttl and maybe some others if needed.

Thoughts?

RubenVerborgh commented 3 years ago

I'd personally like to keep N3.js as much as it is, but feel free to indeed lift out that code to make a package that does ths function. N3 optimizes for speed, for instance, not for customization.