Comparing version 2.0.0 to 3.0.0
51
index.js
@@ -1,10 +0,43 @@ | ||
'use strict' | ||
'use strict'; | ||
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 | ||
}, '') | ||
} | ||
/** | ||
* A fake template literal tag that doesn’t do anything except return the | ||
* tagged template string. Import and use the fake tag with the required name, | ||
* e.g. `gql`. | ||
* @kind function | ||
* @name fakeTag | ||
* @param {Array<string>} literals Template string literals. | ||
* @param {...*} expressions Template string expressions. | ||
* @returns {string} The tagged template string. | ||
* @example <caption>How to `import`.</caption> | ||
* ```js | ||
* import fakeTag from 'fake-tag'; | ||
* ``` | ||
* @example <caption>How to `require`.</caption> | ||
* ```js | ||
* const fakeTag = require('fake-tag'); | ||
* ``` | ||
* @example <caption>Tagging a [GraphQL](https://graphql.org) SDL string with `gql`.</caption> | ||
* ```js | ||
* import gql from 'fake-tag'; | ||
* | ||
* const typeDefs = gql` | ||
* "A foo." | ||
* type Foo { | ||
* "The \`Foo\` ID." | ||
* id: ID! | ||
* } | ||
* `; | ||
* ``` | ||
*/ | ||
module.exports = function fakeTag(literals, ...expressions) { | ||
let string = ''; | ||
for (const [index, literal] of literals.entries()) { | ||
string += literal; | ||
if (index in expressions) string += expressions[index]; | ||
} | ||
return string; | ||
}; |
{ | ||
"name": "fake-tag", | ||
"version": "2.0.0", | ||
"version": "3.0.0", | ||
"description": "A fake template literal tag to trick syntax highlighters, linters and formatters into action.", | ||
@@ -27,27 +27,36 @@ "license": "MIT", | ||
], | ||
"main": "index.js", | ||
"sideEffects": false, | ||
"main": "./index.js", | ||
"exports": { | ||
".": "./index.js", | ||
"./package": "./package.json", | ||
"./package.json": "./package.json" | ||
}, | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20 || >= 14.13" | ||
}, | ||
"browserslist": "> 0.2%, not dead, not OperaMini all", | ||
"browserslist": "Node 12.20 - 13 and Node < 13, Node >= 14.13, > 0.5%, not OperaMini all, not IE > 0, not dead", | ||
"devDependencies": { | ||
"coverage-node": "^2.0.0", | ||
"eslint": "^6.8.0", | ||
"eslint-config-env": "^12.0.1", | ||
"eslint-config-prettier": "^6.7.0", | ||
"eslint-plugin-compat": "^3.3.0", | ||
"eslint-plugin-import": "^2.19.1", | ||
"eslint-plugin-jsdoc": "^18.4.3", | ||
"eslint-plugin-node": "^10.0.0", | ||
"eslint-plugin-prettier": "^3.1.2", | ||
"prettier": "^1.19.1", | ||
"test-director": "^3.0.0" | ||
"coverage-node": "^5.0.1", | ||
"eslint": "^7.28.0", | ||
"eslint-config-env": "^20.0.1", | ||
"eslint-config-prettier": "^8.3.0", | ||
"eslint-plugin-compat": "^3.9.0", | ||
"eslint-plugin-import": "^2.23.4", | ||
"eslint-plugin-jsdoc": "^35.1.3", | ||
"eslint-plugin-node": "^11.1.0", | ||
"eslint-plugin-prettier": "^3.4.0", | ||
"jsdoc-md": "^11.0.0", | ||
"prettier": "^2.3.1", | ||
"test-director": "^6.0.0" | ||
}, | ||
"scripts": { | ||
"test": "npm run test:eslint && npm run test:prettier && npm run test:api", | ||
"jsdoc": "jsdoc-md", | ||
"test": "npm run test:eslint && npm run test:prettier && npm run test:jsdoc && npm run test:api", | ||
"test:eslint": "eslint .", | ||
"test:prettier": "prettier '**/*.{json,yml,md}' -l", | ||
"test:api": "coverage-node test", | ||
"test:prettier": "prettier -c .", | ||
"test:jsdoc": "jsdoc-md -c", | ||
"test:api": "coverage-node test.mjs", | ||
"prepublishOnly": "npm test" | ||
} | ||
} |
@@ -9,3 +9,3 @@ # fake-tag | ||
Install with [npm](https://npmjs.com): | ||
To install with [npm](https://npmjs.com/get-npm), run: | ||
@@ -16,22 +16,47 @@ ```sh | ||
## Usage | ||
## API | ||
Import and use the tag with the required name: | ||
### function fakeTag | ||
```js | ||
import gql from 'fake-tag' | ||
A fake template literal tag that doesn’t do anything except return the tagged template string. Import and use the fake tag with the required name, e.g. `gql`. | ||
const typeDefs = gql` | ||
"A foo." | ||
type Foo { | ||
"The \`Foo\` ID." | ||
id: ID! | ||
} | ||
` | ||
``` | ||
| Parameter | Type | Description | | ||
| :------------ | :------------ | :--------------------------- | | ||
| `literals` | Array<string> | Template string literals. | | ||
| `expressions` | …\* | Template string expressions. | | ||
Names other than `gql` can be used for other use cases. | ||
**Returns:** string — The tagged template string. | ||
## Why not comment tags? | ||
#### Examples | ||
_How to `import`._ | ||
> ```js | ||
> import fakeTag from 'fake-tag'; | ||
> ``` | ||
_How to `require`._ | ||
> ```js | ||
> const fakeTag = require('fake-tag'); | ||
> ``` | ||
_Tagging a [GraphQL](https://graphql.org) SDL string with `gql`._ | ||
> ```js | ||
> import gql from 'fake-tag'; | ||
> | ||
> const typeDefs = gql` | ||
> "A foo." | ||
> type Foo { | ||
> "The \`Foo\` ID." | ||
> id: ID! | ||
> } | ||
> `; | ||
> ``` | ||
## FAQ | ||
### Why not comment tags? | ||
A comment tag looks like this: | ||
@@ -44,3 +69,3 @@ | ||
} | ||
` | ||
`; | ||
``` | ||
@@ -57,3 +82,3 @@ | ||
## Why not `String.raw`? | ||
### Why not `String.raw`? | ||
@@ -63,3 +88,3 @@ This may be temptingly simple: | ||
```js | ||
const gql = String.raw | ||
const gql = String.raw; | ||
const QUERY = gql` | ||
@@ -69,3 +94,3 @@ { | ||
} | ||
` | ||
`; | ||
``` | ||
@@ -72,0 +97,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Trivial Package
Supply chain riskPackages less than 10 lines of code are easily copied into your own project and may not warrant the additional supply chain risk of an external dependency.
Found 1 instance in 1 package
39
102
0
5204
12
3