1. minify-groq
Minifies GROQ-queries, removing unnecessary whitespace
minify-groq
Package: minify-groq
Created by: rexxars
Last modified: Mon, 09 May 2022 10:04:32 GMT
Version: 1.0.0
License: MIT
Downloads: 2,273
Repository: https://github.com/rexxars/minify-groq

Install

npm install minify-groq
yarn add minify-groq

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.

RELATED POST

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Enhancing Vue.js Development: Harnessing the Potential of Vue-Loader

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Simplify Data Validation in Vue.js: A Step-by-Step Guide to Using Regex

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Troubleshooting Made Easy: Common Issues and Solutions with vue-loader Without vue-cli

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Optimizing Webpack 4 with Vue CLI 3: Disabling the Cache-Loader

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin

Step-by-Step Guide: How to Add a Function to Your Vuex Plugin