fake-tag
A fake template literal tag to trick syntax highlighters, linters and formatters into action.
Last updated 9 months ago by jaydenseric .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install fake-tag 
SYNC missed versions from official npm registry.

fake-tag

npm version CI status

A fake template literal tag to trick syntax highlighters, linters and formatters into action. Interpolations and escapes are tested.

Setup

Install with npm:

npm install fake-tag

Usage

Import and use the tag with the required name:

import gql from 'fake-tag'

const typeDefs = gql`
  "A foo."
  type Foo {
    "The \`Foo\` ID."
    id: ID!
  }
`

Names other than gql can be used for other use cases.

Why not comment tags?

A comment tag looks like this:

const QUERY = /* GraphQL */ `
  {
    foo
  }
`

They are far superior to a fake tag:

  • No dependency to manage.
  • No inconvenient imports.
  • No bundle size bloat.
  • No runtime overhead.

Unfortunately not all tools support them yet. prettier has since v1.13.0, but eslint-plugin-graphql at v3.1.0 still doesn’t.

Why not String.raw?

This may be temptingly simple:

const gql = String.raw
const QUERY = gql`
  {
    foo
  }
`

However, it doesn’t unescape characters. For the usage example, if you console.log(typeDefs) before and after replacing the import with const gql = String.raw you will see the difference in the type description markdown:

    "A foo."
    type Foo {
-     "The `Foo` ID."
+     "The \`Foo\` ID."
      id: ID!
    }

Current Tags

  • 2.0.0                                ...           latest (9 months ago)

3 Versions

  • 2.0.0                                ...           9 months ago
  • 1.0.1                                ...           10 months ago
  • 1.0.0                                ...           2 years ago
Maintainers (1)
Downloads
Today 5
This Week 57
This Month 215
Last Day 3
Last Week 54
Last Month 552
Dependencies (0)
None

Copyright 2014 - 2016 © taobao.org |