minify-groq
TypeScript icon, indicating that this package has built-in type declarations

1.0.0 • Public • Published

minify-groq

npm versionnpm bundle sizeBuild Status

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.

import groq from 'minify-groq'
 
const tag = 'fantasy'
const query = groq`
  *[_type == "book" && ${tag} in tags] {
    title,
    publishDate
  }
`
 
// Output (roughly speaking):
// *[_type == "book" && "fantasy" in tags] { title, publishDate }

... or, as a function:

import minifyGroq from 'minify-groq'
 
const query = minifyGroq(`
  *[
    _type == "author" &&
    birthYear > 1950
  ] {
    name,
    birthYear,
    "books": books[]->{
      title
    }
  } | order (birthYear asc) | [ 0 ... 50 ]
`)
 
console.log(query)
// 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.

Dependencies (0)

    Dev Dependencies (10)

    Package Sidebar

    Install

    npm i minify-groq

    Weekly Downloads

    567

    Version

    1.0.0

    License

    MIT

    Unpacked Size

    13.4 kB

    Total Files

    8

    Last publish

    Collaborators

    • rexxars