minify-groq
Minifies a GROQ-query by reducing unnecessary whitespace.
Note: This module is not using full GROQ-parser, so it doesn't know where whitespace is "required". Thus, it can only reduce the amount of whitespace, not fully remove it. It does however make sure to not minify whitespace inside of GROQ strings.
Disclaimer
Still early days - please report any bugs you find.
Installation
$ npm install --save minify-groq
Usage
You can either use this module as a tagged template literal, or as a function. Placeholders used inside of a template will be JSON-encoded automatically.
const tag = 'fantasy'const query = groq` *[_type == "book" && in tags] { title, publishDate }` // Output (roughly speaking):// *[_type == "book" && "fantasy" in tags] { title, publishDate }
... or, as a function:
const query = console// Output (roughly speaking):// *[ _type == "author" && birthYear > 1950] { name, birthYear, "books": books[]->{ title } } | order(birthYear asc) | [0 ... 50]
Browser support
Internet Explorer 9 and up!
License
MIT licensed. See LICENSE.