Skip to content

accuser/compact-groq

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

compact-groq

Remove redundant whitespace from a groq template literal.

Installation

Install as a development dependency using your favourite package manager:

npm install -D @accuser/compact-groq

pnpm add -D @accuser/compact-groq

yarn add -D @accuser/compact-groq

Usage

Import groq from @accuser/compact-groq instead of groq.

Before:

import groq from "groq";

const getPost = async (slug, sanity) => {
  const query = groq`
		*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] {
			...,
			"slug": slug.current
		}
	`;
  const queryParams = { slug };

  return sanity.fetch(query, queryParams);
};

After:

import groq from "@accuser/compact-groq";

const getPost = async (slug, sanity) => {
  const query = groq`
		*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] {
			...,
			"slug": slug.current
		}
	`;
  const queryParams = { slug };

  return sanity.fetch(query, queryParams);
};

Example

import groq from "groq";

const query = groq`
	*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] {
		...,
		"slug": slug.current
	}
`; // '\n\t*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] {\n\t\t...,\n\t\t"slug": slug.current\n\t}\n'
import groq from "@accuser/compact-groq";

const query = groq`
	*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] {
		...,
		"slug": slug.current
	}
`; // '*[_type == "post" && !(_id in path("draft.**")) && slug.current == $slug][0] { ..., "slug": slug.current }'

About

Remove redundant whitespace from a `groq` template literal.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published