Skip to content

Commit

Permalink
Initial release.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydenseric committed Apr 30, 2018
0 parents commit 77a4f09
Show file tree
Hide file tree
Showing 10 changed files with 190 additions and 0 deletions.
11 changes: 11 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# http://editorconfig.org

root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
trim_trailing_whitespace = true
insert_final_newline = true
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
node_modules
package-lock.json
npm-debug.log
.DS_Store
1 change: 1 addition & 0 deletions .npmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package-lock=false
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
package.json
5 changes: 5 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
language: node_js
node_js:
- "node"
notifications:
email: false
5 changes: 5 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# fake-tag changelog

## 0.1.0

* Initial release.
8 changes: 8 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = function() {
var tagArgs = arguments
return tagArgs[0].reduce(function(accumulator, string, index) {
accumulator += string
if (index + 1 in tagArgs) accumulator += tagArgs[index + 1]
return accumulator
}, '')
}
76 changes: 76 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
{
"name": "fake-tag",
"version": "1.0.0",
"description": "A fake template literal tag to trick linters and formatters into action.",
"license": "MIT",
"author": {
"name": "Jayden Seric",
"email": "[email protected]",
"url": "https://jaydenseric.com"
},
"repository": {
"type": "git",
"url": "https://github.com/jaydenseric/fake-tag.git"
},
"homepage": "https://github.com/jaydenseric/fake-tag#readme",
"bugs": "https://github.com/jaydenseric/fake-tag/issues",
"keywords": [
"es6",
"dummy",
"fake",
"template",
"literal",
"string",
"tag"
],
"files": [
"index.js"
],
"devDependencies": {
"ava": "^1.0.0-beta.4",
"eslint": "^4.19.1",
"eslint-plugin-ava": "^4.5.1",
"eslint-plugin-prettier": "^2.5.0",
"husky": "^0.14.3",
"lint-staged": "^7.0.4",
"prettier": "^1.12.1"
},
"scripts": {
"lint": "eslint . --fix && prettier '**/*.{json,md}' --write",
"test": "ava",
"watch": "ava -w",
"precommit": "lint-staged",
"prepublishOnly": "npm run lint && npm test"
},
"lint-staged": {
"*.js": "eslint",
"*.{json,md}": "prettier -l"
},
"eslintConfig": {
"env": {
"es6": true,
"node": true,
"browser": true
},
"extends": [
"eslint:recommended",
"plugin:ava/recommended"
],
"plugins": [
"ava",
"prettier"
],
"rules": {
"curly": [
"error",
"multi"
],
"prettier/prettier": "error"
}
},
"prettier": {
"proseWrap": "never",
"singleQuote": true,
"semi": false
}
}
53 changes: 53 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# fake-tag

[![npm version](https://img.shields.io/npm/v/fake-tag.svg)](https://npm.im/fake-tag) ![Licence](https://img.shields.io/npm/l/fake-tag.svg) [![Github issues](https://img.shields.io/github/issues/jaydenseric/fake-tag.svg)](https://github.com/jaydenseric/fake-tag/issues) [![Github stars](https://img.shields.io/github/stars/jaydenseric/fake-tag.svg)](https://github.com/jaydenseric/fake-tag/stargazers) [![Travis status](https://img.shields.io/travis/jaydenseric/fake-tag.svg)](https://travis-ci.org/jaydenseric/fake-tag)

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

This hack will be redundant once comment tags are supported by tools [such as Prettier](https://github.com/prettier/prettier/issues/4360):

<!-- prettier-ignore -->
```js
/* GraphQL */`
{
foo
}
`
```

## Install

Install with [npm](https://npmjs.com):

```sh
npm install fake-tag
```

## Usage

Import and use the tag with the required name:

```js
import gql from 'fake-tag'

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

## Why not `String.raw`?

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:

```diff
"A foo."
type Foo {
- "The `Foo` ID."
+ "The \`Foo\` ID."
id: ID!
}
```
26 changes: 26 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import test from 'ava'
import tag from '.'

test('Empty.', t => {
t.is(tag``, '')
})

test('Escapes.', t => {
t.is(tag`\``, '`')
})

test('No variables.', t => {
t.is(tag`1`, '1')
})

test('Only variables.', t => {
t.is(tag`${1}${2}${3}`, '123')
})

test('Surrounding variables.', t => {
t.is(tag`${1}2${3}`, '123')
})

test('Surrounded variables.', t => {
t.is(tag`1${2}${3}4`, '1234')
})

0 comments on commit 77a4f09

Please sign in to comment.