0.1.1 • Published 2 years ago

@accuser/compact-groq v0.1.1

Weekly downloads
-
License
MIT
Repository
github
Last release
2 years ago

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 }'
0.1.1

2 years ago

0.1.0

2 years ago