diff --git a/.editorconfig b/.editorconfig index 8fbfd8a..c6c8b36 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,14 +2,8 @@ root = true [*] indent_style = space -indent_size = 4 +indent_size = 2 end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true - -[*.{json,mdastrc,eslintrc,sh}] -indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.eslintignore b/.eslintignore deleted file mode 100644 index 4c5648a..0000000 --- a/.eslintignore +++ /dev/null @@ -1,6 +0,0 @@ -build/ -components/ -coverage/ -build.js -collapse-white-space.js -collapse-white-space.min.js diff --git a/.eslintrc b/.eslintrc deleted file mode 100644 index 7586723..0000000 --- a/.eslintrc +++ /dev/null @@ -1,9 +0,0 @@ -{ - "env": { - "node": true, - "browser": true - }, - "rules": { - "quotes": [2, "single"] - } -} diff --git a/.gitignore b/.gitignore index e214cf2..628a4b4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,8 +1,7 @@ .DS_Store *.log -build/ -bower_components/ -components/ +.nyc_output/ coverage/ node_modules/ -build.js +collapse-white-space.js +collapse-white-space.min.js diff --git a/.jscs.json b/.jscs.json deleted file mode 100644 index 432aed4..0000000 --- a/.jscs.json +++ /dev/null @@ -1,152 +0,0 @@ -{ - "excludeFiles": [ - "build/", - "components/", - "coverage/", - "node_modules/", - "build.js", - "lib/expression.js", - "collapse-white-space.js", - "collapse-white-space.min.js" - ], - "plugins": [ - "jscs-jsdoc" - ], - "jsDoc": { - "checkAnnotations": "jsdoc3", - "checkParamNames": true, - "requireParamTypes": true, - "checkRedundantParams": true, - "checkReturnTypes": true, - "checkRedundantReturns": true, - "requireReturnTypes": true, - "checkTypes": "strictNativeCase", - "checkRedundantAccess": true, - "enforceExistence": true, - "requireHyphenBeforeDescription": true - }, - "requireCurlyBraces": [ - "if", - "else", - "for", - "while", - "do", - "try", - "catch" - ], - "requireSpaceAfterKeywords": [ - "if", - "else", - "for", - "while", - "do", - "switch", - "return", - "try", - "catch" - ], - "requireSpaceBeforeBlockStatements": true, - "requireParenthesesAroundIIFE": true, - "requireSpacesInConditionalExpression": true, - "requireSpacesInFunctionExpression": { - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInAnonymousFunctionExpression": { - "beforeOpeningRoundBrace": true, - "beforeOpeningCurlyBrace": true - }, - "requireSpacesInNamedFunctionExpression": { - "beforeOpeningRoundBrace": true, - "beforeOpeningCurlyBrace": true - }, - "requireBlocksOnNewline": true, - "disallowEmptyBlocks": true, - "disallowSpacesInsideObjectBrackets": true, - "disallowSpacesInsideArrayBrackets": true, - "disallowSpacesInsideParentheses": true, - "requireSpacesInsideObjectBrackets": "all", - "disallowDanglingUnderscores": true, - "disallowSpaceAfterObjectKeys": true, - "requireCommaBeforeLineBreak": true, - "requireOperatorBeforeLineBreak": [ - "?", - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==", - ">", - ">=", - "<", - "<=" - ], - "requireSpaceBeforeBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "requireSpaceAfterBinaryOperators": [ - "+", - "-", - "/", - "*", - "=", - "==", - "===", - "!=", - "!==" - ], - "disallowSpaceAfterPrefixUnaryOperators": [ - "++", - "--", - "+", - "-", - "~", - "!" - ], - "disallowSpaceBeforePostfixUnaryOperators": [ - "++", - "--" - ], - "disallowImplicitTypeConversion": [ - "numeric", - "boolean", - "binary", - "string" - ], - "requireCamelCaseOrUpperCaseIdentifiers": true, - "disallowKeywords": [ - "with" - ], - "disallowMultipleLineStrings": true, - "disallowMultipleLineBreaks": true, - "validateLineBreaks": "LF", - "validateQuoteMarks": "'", - "disallowMixedSpacesAndTabs": true, - "disallowTrailingWhitespace": true, - "disallowTrailingComma": true, - "disallowKeywordsOnNewLine": [ - "else" - ], - "requireLineFeedAtFileEnd": true, - "maximumLineLength": 78, - "requireCapitalizedConstructors": true, - "safeContextKeyword": "self", - "requireDotNotation": true, - "disallowYodaConditions": true, - "validateJSDoc": { - "checkParamNames": true, - "checkRedundantParams": true, - "requireParamTypes": true - } -} diff --git a/.mdastignore b/.mdastignore deleted file mode 100644 index 44be31f..0000000 --- a/.mdastignore +++ /dev/null @@ -1 +0,0 @@ -components diff --git a/.mdastrc b/.mdastrc deleted file mode 100644 index d3baf7e..0000000 --- a/.mdastrc +++ /dev/null @@ -1,11 +0,0 @@ -{ - "plugins": [ - "lint", - "github", - "usage", - "yaml-config" - ], - "settings": { - "bullet": "*" - } -} diff --git a/.travis.yml b/.travis.yml index 5a4bbc0..5eaac42 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,25 @@ language: node_js -script: npm run-script test-travis node_js: -- '0.10' - '0.11' - '0.12' -- iojs -sudo: false -after_script: npm install coveralls@2.10.0 && cat ./coverage/lcov.info | coveralls +- '4.0' +- '5.0' +- '6.0' +after_success: bash <(curl -s https://codecov.io/bash) +deploy: + - provider: npm + email: tituswormer@gmail.com + api_key: + secure: ccTzkZGbrgJs0IAAtlZ0WjhM5wdW4sAXA5dL17iOboQyNheuu23y9Dgmd1OwMYxDHsMSXk33nOaXeA+rSPg7QKwyTcNEfKOJmvdSIbZeFtRjawAMgdZFRrhOB0k0Nqdk87iDzOcNXk6o0V0FlAc7LR8SSFUhkDOreOMbXkdwTYZkVBs/Y/GGJBUa/MwKnYD8H4d0AULOy1NFc1IRqQg2UkBEFWvDB0uFFwpAZcM+cS74+c3VlzrNLGfwLLTEt+dW7XnjsTs10CvLKT1VixgnqZi5D+Y2BOjKO0YJaNG3Xb5KupPBT5fsMKDxIk9a82YD96tsVm36LrN+wNP3vvuanQY3An4yWNqWXZ/uz9XpMxtoQhbaApdwJkG5niMHuKI77ya7LG1w27wDzdieP91P/mdZTQ5lExoBnvtuUa4E5xUSXAPmN9z2QFgkjz1w+aa0SHmepCmzKOiKNmFSjrJgwkttbjqJae5Y/IOn1ngKOwcaUo0jsD0Pn6HXD/Ow6neRC0v0DBS6+i+y5zxyKIpppNj0xmth0xFWny3osR8SissWXVCEh1H1k9ufcGAHDXppNh+5kAze/dCKdVrdniJ9mg229X/fNoAeBlbztHlWqsRuN57bXugI4mYecG77zUGnTkelU9TEWZ8f80rZPB95SyM6tzM8NSzgp1WBO2HbkR8= + on: + tags: true + node: '5.0' + - provider: releases + api_key: + secure: ksLoQGm0zwXg/giTCPpGfEOn9wT7AGgGJr4CUt+6OCo3+GdNOTcvi47cmNMGLhhiKP4rS0VPquZQ1pNVjXzmKjq+6Mg6BWqMpUQMsHAwHGrVCxaGMW3YdkUOhgMkeEmcl2ckJdsH5NtYv5pfpn78FgD6dqP4gy1DGLk4fmWq1BK11jAYFDMtWqnV2sX5fCbG6shRLeRQH2BWGVXUt8/5LFEtQkWItNDt8KYw685jur44Y10nrT67e3YTrMeQlxHYH3yjN9qg1s8s1SGs35bWIfB7dR+mpwTkf1P6f7VaA1zXpYu9eQys2yhHObm31wwSLBgMML5PTftbP5+y3bVMXafYLddAVJevweVBafXkmPmIK+mVuz5KdvcPuGOIc59lkV9qCC+vo9eAilo8z1YjHsdMe1gBYZEf339BSZd+eEsHF6D6ArQl3FzafGB588p1oX0BeVnb2Qi+eDJsuENUTfBZingPWD9OOj+VzFPzB9G/MqVn/eafZQ+fDtTWER9vDOsuosVxFKvf3QxCNdnAVm4ZhGyuGdhvHyIq5YYDPbMW4UViO6e7pVbIFMP9yci+dW2kVv8vHLaaWyL64LxOQ28CIo7MTayk2nWdEXKEiZ0zv1eHPV/Tf5bbVrLCsevNzj2zyMlStswQ4X8adv+d5y6ypGLPCI68gi94gZWcDEc= + file: + - "collapse-white-space.js" + - "collapse-white-space.min.js" + on: + tags: true + node: '6.0' diff --git a/LICENSE b/LICENSE index 611b675..32e7a3d 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ (The MIT License) -Copyright (c) 2015 Titus Wormer +Copyright (c) 2015 Titus Wormer Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the diff --git a/bower.json b/bower.json deleted file mode 100644 index 8976af6..0000000 --- a/bower.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "name": "collapse-white-space", - "main": "collapse-white-space.js", - "description": "Replace multiple white-space characters with a single space", - "license": "MIT", - "keywords": [ - "collapse", - "white", - "space" - ], - "repository": { - "type": "git", - "url": "https://github.com/wooorm/collapse-white-space.git" - }, - "authors": [ - "Titus Wormer " - ], - "ignore": [ - ".*", - "*.log", - "*.md", - "build/", - "components/", - "coverage/", - "node_modules/", - "build.js", - "example.js", - "index.js", - "test.js", - "component.json", - "package.json" - ] -} diff --git a/collapse-white-space.js b/collapse-white-space.js deleted file mode 100644 index b03a26c..0000000 --- a/collapse-white-space.js +++ /dev/null @@ -1,32 +0,0 @@ -(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.collapseWhiteSpace = f()}})(function(){var define,module,exports;return (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o - + 1.0.0 / 2015-07-12 ================== diff --git a/index.js b/index.js index b0a5e17..337c107 100644 --- a/index.js +++ b/index.js @@ -1,11 +1,16 @@ -'use strict'; - -/* - * Constants. +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module collapse-white-space + * @fileoverview Replace multiple white-space characters + * with a single space. */ -var WHITE_SPACE_COLLAPSABLE = /\s+/g; -var SPACE = ' '; +'use strict'; + +/* Expose. */ +module.exports = collapse; /** * Replace multiple white-space characters with a single space. @@ -18,11 +23,5 @@ var SPACE = ' '; * @return {string} - Value with collapsed white-space. */ function collapse(value) { - return String(value).replace(WHITE_SPACE_COLLAPSABLE, SPACE); + return String(value).replace(/\s+/g, ' '); } - -/* - * Expose. - */ - -module.exports = collapse; diff --git a/package.json b/package.json index 84216a0..dc9fa61 100644 --- a/package.json +++ b/package.json @@ -9,41 +9,54 @@ "space" ], "files": [ - "index.js", - "LICENSE" + "index.js" ], - "repository": { - "type": "git", - "url": "https://github.com/wooorm/collapse-white-space.git" - }, - "author": "Titus Wormer ", + "repository": "https://github.com/wooorm/collapse-white-space", + "bugs": "https://github.com/wooorm/collapse-white-space/issues", + "author": "Titus Wormer (http://wooorm.com)", + "contributors": [ + "Titus Wormer (http://wooorm.com)" + ], + "dependencies": {}, "devDependencies": { - "browserify": "^10.0.0", - "eslint": "^0.24.0", - "esmangle": "^1.0.0", - "istanbul": "^0.3.0", - "jscs": "^1.0.0", - "jscs-jsdoc": "^1.0.0", - "mdast": "^0.26.0", - "mdast-github": "^0.3.1", - "mdast-lint": "^0.4.1", - "mdast-usage": "^0.3.0", - "mdast-yaml-config": "^0.2.0", - "mocha": "^2.0.0" + "browserify": "^13.0.1", + "esmangle": "^1.0.1", + "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" }, "scripts": { - "test-api": "mocha --check-leaks test.js", - "test-coveralls": "istanbul cover _mocha --report lcovonly -- --check-leaks test.js", - "test-coverage": "istanbul cover _mocha -- --check-leaks test.js", - "test-travis": "npm run test-coveralls", - "test": "npm run test-api", - "lint-api": "eslint .", - "lint-style": "jscs --reporter inline .", - "lint": "npm run lint-api && npm run lint-style", - "make": "npm run lint && npm run test-coverage", - "build-md": "mdast . LICENSE --output --quiet", + "build-md": "remark . --quiet --frail", "build-bundle": "browserify index.js --bare -s collapseWhiteSpace > collapse-white-space.js", - "postbuild-bundle": "esmangle collapse-white-space.js > collapse-white-space.min.js", - "build": "npm run build-md && npm run build-bundle" + "build-mangle": "esmangle collapse-white-space.js > collapse-white-space.min.js", + "build": "npm run build-md && npm run build-bundle && npm run build-mangle", + "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": [ + "collapse-white-space.js", + "collapse-white-space.min.js" + ] + }, + "remarkConfig": { + "output": true, + "plugins": [ + "comment-config", + "github", + "lint", + "validate-links" + ], + "settings": { + "bullet": "*" + } } } diff --git a/readme.md b/readme.md index d926c88..3af05c4 100644 --- a/readme.md +++ b/readme.md @@ -1,20 +1,17 @@ -# collapse-white-space [![Build Status](https://img.shields.io/travis/wooorm/collapse-white-space.svg?style=flat)](https://travis-ci.org/wooorm/collapse-white-space) [![Coverage Status](https://img.shields.io/coveralls/wooorm/collapse-white-space.svg?style=flat)](https://coveralls.io/r/wooorm/collapse-white-space?branch=master) +# collapse-white-space [![Build Status][travis-badge]][travis] [![Coverage Status][codecov-badge]][codecov] + + Replace multiple white-space characters with a single space. ## Installation -[npm](https://docs.npmjs.com/cli/install): +[npm][npm-install]: ```bash npm install collapse-white-space ``` -**collapse-white-space** is also available for [bower](http://bower.io/#install-packages), -[component](https://github.com/componentjs/component), [duo](http://duojs.org/#getting-started), -and for AMD, CommonJS, and globals ([uncompressed](collapse-white-space.js) and -[compressed](collapse-white-space.min.js)). - ## Usage Dependencies. @@ -37,16 +34,55 @@ Yields: ## API -### collapse(value) +### `collapse(value)` Replace multiple white-space characters with a single space. -Parameters: +###### Parameters * `value` (`string`) — Value with uncollapsed white-space, coerced to string. -Returns: `string` — Value with collapsed white-space. +###### Returns + +`string` — Value with collapsed white-space. + +### `commaSeparated.stringify(values[, options])` + +Compile an array of strings to comma-separated tokens. +Handles empty items at start or end correctly. +Note that it’s not possible to specify initial or final +white-space per value. + +###### Parameters + +* `values` (`Array.`) — List of tokens; +* `options` (`Object`, optional): + + * `padLeft` (`boolean`, default: `true`) + — 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. ## License -[MIT](LICENSE) @ [Titus Wormer](http://wooorm.com) +[MIT][license] © [Titus Wormer][author] + + + +[travis-badge]: https://img.shields.io/travis/wooorm/collapse-white-space.svg + +[travis]: https://travis-ci.org/wooorm/collapse-white-space + +[codecov-badge]: https://img.shields.io/codecov/c/github/wooorm/collapse-white-space.svg + +[codecov]: https://codecov.io/github/wooorm/collapse-white-space + +[npm-install]: https://docs.npmjs.com/cli/install + +[license]: LICENSE + +[author]: http://wooorm.com diff --git a/test.js b/test.js index 57f7eed..5953ce7 100644 --- a/test.js +++ b/test.js @@ -1,26 +1,24 @@ -'use strict'; - -/* eslint-env mocha */ - -/* - * Dependencies. +/** + * @author Titus Wormer + * @copyright 2015 Titus Wormer + * @license MIT + * @module collapse-white-space + * @fileoverview Test suite for `collapse-white-space`. */ -var collapse = require('./'); -var assert = require('assert'); +'use strict'; -/* - * Tests. - */ +/* Dependencies. */ +var test = require('tape'); +var collapse = require('./index.js'); + +/* Tests. */ +test('collapseWhiteSpace(value)', function (t) { + t.equal(collapse(true), 'true', 'should coerce to string'); -describe('collapse(value)', function () { - it('should coerce to string', function () { - assert.equal(collapse(true), 'true'); - }); + t.equal(collapse(' \t\nbar \nbaz\t'), ' bar baz '); + t.equal(collapse(' bar\t\t\tbaz\n\n\n'), ' bar baz '); + t.equal(collapse(' \n bar\t\n\tbaz\r\n'), ' bar baz '); - it('should work', function () { - assert.equal(collapse(' \t\nbar \nbaz\t'), ' bar baz '); - assert.equal(collapse(' bar\t\t\tbaz\n\n\n'), ' bar baz '); - assert.equal(collapse(' \n bar\t\n\tbaz\r\n'), ' bar baz '); - }); + t.end(); });