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

fake-tag

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

Installation

For Node.js, to install fake-tag with npm, run:

npm install fake-tag

For Deno and browsers, an example import map:

{
  "imports": {
    "fake-tag": "https://unpkg.com/fake-tag@5.0.0/fakeTag.mjs"
  }
}

Then, import and use the template literal tag fakeTag.

Examples

Tagging a GraphQL SDL string with gql:

import gql from "fake-tag";

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

Requirements

Supported runtime environments:

Non Deno projects must configure TypeScript to use types from the ECMAScript modules that have a // @ts-check comment:

Exports

The npm package fake-tag features optimal JavaScript module design. These ECMAScript modules are exported via the package.json field exports:

FAQ

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

  • 5.0.0                                ...           latest (2 years ago)

6 Versions

  • 5.0.0                                ...           2 years ago
  • 4.0.0                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.0.0                                ...           5 years ago
  • 1.0.1                                ...           5 years ago
  • 1.0.0                                ...           7 years ago
Maintainers (1)
Downloads
Total 0
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (0)
None
Dev Dependencies (7)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE