Skip to content

Commit

Permalink
perf: use built-in String.raw if available
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Oct 23, 2020
1 parent cc683a9 commit 0da5573
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/content/en/helpers/groq.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ category: Helpers
position: 12
---

This module exports a `groq` helper function to assist with GROQ syntax highlighting (a duplicate of [this package](https://github.com/sanity-io/sanity/tree/next/packages/groq)). Make sure to install [the VSCode extension](https://github.com/sanity-io/vscode-sanity) - and enjoy!
This module exports a `groq` helper function to assist with GROQ syntax highlighting and [eslint rules](https://github.com/asbjornh/eslint-plugin-groq). Make sure to install [the VSCode extension](https://github.com/sanity-io/vscode-sanity) - and enjoy!

## Example

Expand Down
9 changes: 6 additions & 3 deletions src/helpers.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
/**
* From https://github.com/sanity-io/sanity/tree/next/packages/groq
* For use with https://github.com/asbjornh/eslint-plugin-groq
* and https://github.com/sanity-io/vscode-sanity
*
* based on https://github.com/sanity-io/sanity/tree/next/packages/groq
*/
export const groq = (strings: TemplateStringsArray, ...keys: any[]) => {
export const groq = String.raw || ((strings: TemplateStringsArray, ...keys: any[]) => {
const lastIndex = strings.length - 1
return (
strings
Expand All @@ -11,4 +14,4 @@ export const groq = (strings: TemplateStringsArray, ...keys: any[]) => {
'',
) + strings[lastIndex]
)
}
})

0 comments on commit 0da5573

Please sign in to comment.