comma-separated-tokens
Advanced tools
Comparing version 1.0.1 to 1.0.2
@@ -5,2 +5,7 @@ <!--remark setext--> | ||
1.0.2 / 2016-07-23 | ||
================== | ||
* Refactor code-style to use `xo` ([`f7d9006`](https://github.com/wooorm/comma-separated-tokens/commit/f7d9006)) | ||
1.0.1 / 2016-02-24 | ||
@@ -7,0 +12,0 @@ ================== |
77
index.js
@@ -11,3 +11,5 @@ /** | ||
/* eslint-env commonjs */ | ||
/* Expose. */ | ||
exports.parse = parse; | ||
exports.stringify = stringify; | ||
@@ -40,26 +42,26 @@ /* | ||
function parse(value) { | ||
var values = []; | ||
var input = String(value || EMPTY); | ||
var index = input.indexOf(C_COMMA); | ||
var lastIndex = 0; | ||
var end = false; | ||
var val; | ||
var values = []; | ||
var input = String(value || EMPTY); | ||
var index = input.indexOf(C_COMMA); | ||
var lastIndex = 0; | ||
var end = false; | ||
var val; | ||
while (!end) { | ||
if (index === -1) { | ||
index = input.length; | ||
end = true; | ||
} | ||
while (!end) { | ||
if (index === -1) { | ||
index = input.length; | ||
end = true; | ||
} | ||
val = trim(input.slice(lastIndex, index)); | ||
val = trim(input.slice(lastIndex, index)); | ||
if (val || !end) { | ||
values.push(val); | ||
} | ||
lastIndex = index + 1; | ||
index = input.indexOf(C_COMMA, lastIndex); | ||
if (val || !end) { | ||
values.push(val); | ||
} | ||
return values; | ||
lastIndex = index + 1; | ||
index = input.indexOf(C_COMMA, lastIndex); | ||
} | ||
return values; | ||
} | ||
@@ -79,27 +81,18 @@ | ||
function stringify(values, options) { | ||
var settings = options || {}; | ||
var left = settings.padLeft; | ||
var settings = options || {}; | ||
var left = settings.padLeft; | ||
/* | ||
* Ensure the last empty entry is seen. | ||
*/ | ||
/* | ||
* Ensure the last empty entry is seen. | ||
*/ | ||
if (values[values.length - 1] === EMPTY) { | ||
values = values.concat(EMPTY); | ||
} | ||
if (values[values.length - 1] === EMPTY) { | ||
values = values.concat(EMPTY); | ||
} | ||
return trim(values.join( | ||
(settings.padRight ? C_SPACE : EMPTY) + | ||
C_COMMA + | ||
(left || left === undefined || left === null ? C_SPACE : EMPTY) | ||
)); | ||
return trim(values.join( | ||
(settings.padRight ? C_SPACE : EMPTY) + | ||
C_COMMA + | ||
(left || left === undefined || left === null ? C_SPACE : EMPTY) | ||
)); | ||
} | ||
/* | ||
* Expose. | ||
*/ | ||
module.exports = { | ||
'parse': parse, | ||
'stringify': stringify | ||
}; |
{ | ||
"name": "comma-separated-tokens", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"description": "Parse and stringify comma-separated tokens", | ||
@@ -15,12 +15,6 @@ "license": "MIT", | ||
], | ||
"dependencies": { | ||
"trim": "0.0.1" | ||
}, | ||
"files": [ | ||
"index.js" | ||
], | ||
"repository": { | ||
"type": "git", | ||
"url": "https://github.com/wooorm/comma-separated-tokens.git" | ||
}, | ||
"repository": "https://github.com/wooorm/comma-separated-tokens", | ||
"bugs": "https://github.com/wooorm/comma-separated-tokens/issues", | ||
@@ -31,16 +25,16 @@ "author": "Titus Wormer <tituswormer@gmail.com> (http://wooorm.com)", | ||
], | ||
"dependencies": { | ||
"trim": "0.0.1" | ||
}, | ||
"devDependencies": { | ||
"browserify": "^13.0.0", | ||
"eslint": "^2.0.0", | ||
"browserify": "^13.0.1", | ||
"esmangle": "^1.0.1", | ||
"istanbul": "^0.4.0", | ||
"jscs": "^2.0.0", | ||
"jscs-jsdoc": "^1.0.0", | ||
"remark": "^4.0.0", | ||
"remark-comment-config": "^3.0.0", | ||
"remark-github": "^4.0.1", | ||
"remark-lint": "^3.0.0", | ||
"remark-usage": "^3.0.0", | ||
"remark-validate-links": "^3.0.0", | ||
"tape": "^4.4.0" | ||
"nyc": "^7.0.0", | ||
"remark-cli": "^1.0.0", | ||
"remark-comment-config": "^4.0.0", | ||
"remark-github": "^5.0.0", | ||
"remark-lint": "^4.0.0", | ||
"remark-validate-links": "^4.0.0", | ||
"tape": "^4.0.0", | ||
"xo": "^0.16.0" | ||
}, | ||
@@ -52,9 +46,26 @@ "scripts": { | ||
"build": "npm run build-md && npm run build-bundle && npm run build-mangle", | ||
"lint-api": "eslint .", | ||
"lint-style": "jscs --reporter inline .", | ||
"lint": "npm run lint-api && npm run lint-style", | ||
"test-api": "node test.js", | ||
"test-coverage": "istanbul cover test.js", | ||
"lint": "xo", | ||
"test-api": "node test", | ||
"test-coverage": "nyc --reporter lcov tape test.js", | ||
"test": "npm run build && npm run lint && npm run test-coverage" | ||
}, | ||
"xo": { | ||
"space": true, | ||
"ignores": [ | ||
"comma-separated-tokens.js", | ||
"comma-separated-tokens.min.js" | ||
] | ||
}, | ||
"remarkConfig": { | ||
"output": true, | ||
"plugins": [ | ||
"comment-config", | ||
"github", | ||
"lint", | ||
"validate-links" | ||
], | ||
"settings": { | ||
"bullet": "*" | ||
} | ||
} | ||
} |
@@ -1,3 +0,5 @@ | ||
# comma-separated-tokens [![Build Status][build-badge]][build-page] [![Coverage Status][coverage-badge]][coverage-page] | ||
# comma-separated-tokens [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] | ||
<!--lint disable heading-increment list-item-spacing no-duplicate-headings--> | ||
Parse and stringify comma-separated tokens according to the [spec][]. | ||
@@ -7,3 +9,3 @@ | ||
[npm][]: | ||
[npm][npm-install]: | ||
@@ -14,5 +16,2 @@ ```bash | ||
**comma-separated-tokens** is also available as an AMD, CommonJS, and | ||
globals module, [uncompressed and compressed][releases]. | ||
## Usage | ||
@@ -54,8 +53,13 @@ | ||
Parse comma-separated tokens to an array of strings, according to the [spec][]. | ||
Parse comma-separated tokens to an array of strings, according to the | ||
[spec][]. | ||
###### Parameters | ||
* `value` (`string`) — Comma-separated tokens. | ||
**Returns**: `Array.<string>` — List of tokens. | ||
###### Returns | ||
`Array.<string>` — List of tokens. | ||
### `commaSeparated.stringify(values[, options])` | ||
@@ -68,4 +72,5 @@ | ||
###### Parameters | ||
* `values` (`Array.<string>`) — List of tokens; | ||
* `options` (`Object`, optional): | ||
@@ -75,8 +80,9 @@ | ||
— Whether to pad a space before a token; | ||
* `padRight` (`boolean`, default: `false`) | ||
— Whether to pad a space after a token. | ||
**Returns**: `string` — Comma-separated tokens. | ||
###### Returns | ||
`string` — Comma-separated tokens. | ||
## License | ||
@@ -86,16 +92,14 @@ | ||
<!-- Definition --> | ||
<!-- Definitions --> | ||
[build-badge]: https://img.shields.io/travis/wooorm/comma-separated-tokens.svg | ||
[travis-badge]: https://img.shields.io/travis/wooorm/comma-separated-tokens.svg | ||
[build-page]: https://travis-ci.org/wooorm/comma-separated-tokens | ||
[travis]: https://travis-ci.org/wooorm/comma-separated-tokens | ||
[coverage-badge]: https://img.shields.io/codecov/c/github/wooorm/comma-separated-tokens.svg | ||
[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/comma-separated-tokens.svg | ||
[coverage-page]: https://codecov.io/github/wooorm/comma-separated-tokens?branch=master | ||
[codecov]: https://codecov.io/github/wooorm/comma-separated-tokens | ||
[npm]: https://docs.npmjs.com/cli/install | ||
[npm-install]: https://docs.npmjs.com/cli/install | ||
[releases]: https://github.com/wooorm/comma-separated-tokens/releases | ||
[license]: LICENSE | ||
@@ -102,0 +106,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
No repository
Supply chain riskPackage does not have a linked source code repository. Without this field, a package will have no reference to the location of the source code use to generate the package.
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
7166
10
104
77
1