Comparing version 2.0.1 to 2.0.2
@@ -1,8 +0,18 @@ | ||
/** @type {{ | ||
* (value: string, open?: string, close?: string): string | ||
* (value: string[], open?: string, close?: string): string[] | ||
* }} */ | ||
export var quotation: { | ||
(value: string, open?: string, close?: string): string | ||
(value: string[], open?: string, close?: string): string[] | ||
/** | ||
* Quote a value. | ||
* | ||
* @param value | ||
* Value(s) to wrap in quotes | ||
* @param [open='"'] | ||
* Opening quote | ||
* @param [close=open] | ||
* Closing quote | ||
*/ | ||
export const quotation: { | ||
(value: string, open?: string | undefined, close?: string | undefined): string | ||
( | ||
value: string[], | ||
open?: string | undefined, | ||
close?: string | undefined | ||
): string[] | ||
} |
68
index.js
@@ -1,36 +0,46 @@ | ||
// prettier-ignore | ||
/** @type {{ | ||
* (value: string, open?: string, close?: string): string | ||
* (value: string[], open?: string, close?: string): string[] | ||
* }} */ | ||
export var quotation = ( | ||
/** | ||
* Quote a value. | ||
* | ||
* @param value | ||
* Value(s) to wrap in quotes | ||
* @param [open='"'] | ||
* Opening quote | ||
* @param [close=open] | ||
* Closing quote | ||
*/ | ||
export const quotation = | ||
/** | ||
* Quote a value. | ||
* | ||
* @param {string | string[]} value Value(s) to wrap in quotes | ||
* @param {string} [open='"'] Opening quote | ||
* @param {string} [close=open] Closing quote | ||
* @returns {string | string[]} | ||
* @type {{ | ||
* (value: string, open?: string, close?: string): string | ||
* (value: string[], open?: string, close?: string): string[] | ||
* }} | ||
*/ | ||
function (value, open, close) { | ||
var start = open || '"' | ||
var end = close || start | ||
/** @type {string[]} */ | ||
var result = [] | ||
var index = -1 | ||
( | ||
/** | ||
* @param {string|Array<string>} value | ||
* @param {string} open | ||
* @param {string} close | ||
* @returns {string|string[]} | ||
*/ | ||
function (value, open, close) { | ||
const start = open || '"' | ||
const end = close || start | ||
/** @type {string[]} */ | ||
const result = [] | ||
let index = -1 | ||
if (Array.isArray(value)) { | ||
while (++index < value.length) { | ||
result[index] = start + value[index] + end | ||
if (Array.isArray(value)) { | ||
while (++index < value.length) { | ||
result[index] = start + value[index] + end | ||
} | ||
return result | ||
} | ||
return result | ||
} | ||
if (typeof value === 'string') { | ||
return start + value + end | ||
} | ||
if (typeof value === 'string') { | ||
return start + value + end | ||
throw new TypeError('Expected string or array of strings') | ||
} | ||
throw new TypeError('Expected string or array of strings') | ||
} | ||
) | ||
) |
{ | ||
"name": "quotation", | ||
"version": "2.0.1", | ||
"version": "2.0.2", | ||
"description": "Quote a value", | ||
@@ -41,4 +41,4 @@ "license": "MIT", | ||
"prettier": "^2.0.0", | ||
"remark-cli": "^9.0.0", | ||
"remark-preset-wooorm": "^8.0.0", | ||
"remark-cli": "^10.0.0", | ||
"remark-preset-wooorm": "^9.0.0", | ||
"rimraf": "^3.0.0", | ||
@@ -48,10 +48,10 @@ "tape": "^5.0.0", | ||
"typescript": "^4.0.0", | ||
"xo": "^0.38.0" | ||
"xo": "^0.46.0" | ||
}, | ||
"scripts": { | ||
"prepack": "npm run build && npm run format", | ||
"prepublishOnly": "npm run build && npm run format", | ||
"build": "rimraf \"*.d.ts\" && tsc && type-coverage", | ||
"format": "remark . -qfo && prettier . -w --loglevel warn && xo --fix", | ||
"test-api": "node test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov node test.js", | ||
"test-api": "node --conditions development test.js", | ||
"test-coverage": "c8 --check-coverage --branches 100 --functions 100 --lines 100 --statements 100 --reporter lcov npm run test-api", | ||
"test": "npm run build && npm run format && npm run test-coverage" | ||
@@ -68,8 +68,3 @@ }, | ||
"xo": { | ||
"prettier": true, | ||
"rules": { | ||
"import/no-mutable-exports": "off", | ||
"no-var": "off", | ||
"prefer-arrow-callback": "off" | ||
} | ||
"prettier": true | ||
}, | ||
@@ -84,4 +79,5 @@ "remarkConfig": { | ||
"detail": true, | ||
"strict": true | ||
"strict": true, | ||
"ignoreCatch": true | ||
} | ||
} |
@@ -10,9 +10,30 @@ # quotation | ||
## Contents | ||
* [What is this?](#what-is-this) | ||
* [When should I use this?](#when-should-i-use-this) | ||
* [Install](#install) | ||
* [Use](#use) | ||
* [API](#api) | ||
* [`quotation(value[, open[, close]])`](#quotationvalue-open-close) | ||
* [Types](#types) | ||
* [Compatibility](#compatibility) | ||
* [Security](#security) | ||
* [Contribute](#contribute) | ||
* [License](#license) | ||
## What is this? | ||
This package makes it quite easy to quote one or more values. | ||
## When should I use this? | ||
Use this package if you need to quote one or more strings with straight or smart | ||
quotes. | ||
## Install | ||
This package is ESM only: Node 12+ is needed to use it and it must be `import`ed | ||
instead of `require`d. | ||
This package is [ESM only][esm]. | ||
In Node.js (version 12.20+, 14.14+, or 16.0+), install with [npm][]: | ||
[npm][]: | ||
```sh | ||
@@ -22,2 +43,16 @@ npm install quotation | ||
In Deno with [Skypack][]: | ||
```js | ||
import {quotation} from 'https://cdn.skypack.dev/quotation@2?dts' | ||
``` | ||
In browsers with [Skypack][]: | ||
```html | ||
<script type="module"> | ||
import {quotation} from 'https://cdn.skypack.dev/quotation@2?min' | ||
</script> | ||
``` | ||
## Use | ||
@@ -30,3 +65,3 @@ | ||
quotation(['one', 'two']) // => ['"one"', '"two"'] | ||
quotation('one', "'") // => '\'one\'' | ||
quotation('one', "'") // => "'one'" | ||
quotation('one', '“', '”') // => '“one”' | ||
@@ -37,3 +72,3 @@ ``` | ||
This package exports the following identifiers: `quotation`. | ||
This package exports the following identifier: `quotation`. | ||
There is no default export. | ||
@@ -48,8 +83,28 @@ | ||
* `value` (`string` or `string[]`) | ||
— Value to wrap in quotes | ||
— value to wrap in quotes | ||
* `open` (`string`, default: `"`) | ||
— Character to add at start of `value` | ||
— character to add at start of `value` | ||
* `close` (`string`, default: `open` or `"`) | ||
— Character to add at end of `value` | ||
— character to add at end of `value` | ||
## Types | ||
This package is fully typed with [TypeScript][]. | ||
There are no extra exported types. | ||
## Compatibility | ||
This package is at least compatible with all maintained versions of Node.js. | ||
As of now, that is Node.js 12.20+, 14.14+, and 16.0+. | ||
It also works in Deno and modern browsers. | ||
## Security | ||
This package is safe. | ||
## Contribute | ||
Yes please! | ||
See [How to Contribute to Open Source][contribute]. | ||
## License | ||
@@ -79,4 +134,12 @@ | ||
[skypack]: https://www.skypack.dev | ||
[license]: license | ||
[author]: https://wooorm.com | ||
[esm]: https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c | ||
[typescript]: https://www.typescriptlang.org | ||
[contribute]: https://opensource.guide/how-to-contribute/ |
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
7457
60
140