From fbb3392b399c5c8bae64000a63e15928d337eeab Mon Sep 17 00:00:00 2001 From: Dimitri Benin Date: Tue, 9 Apr 2019 05:37:00 +0000 Subject: [PATCH] Require Node.js 8, add TypeScript definition (#3) --- .editorconfig | 5 +--- .gitattributes | 2 +- .gitignore | 1 + .jshintrc | 13 --------- .npmrc | 1 + .travis.yml | 6 ++-- index.d.ts | 14 ++++++++++ index.js | 6 ++-- index.test-d.ts | 4 +++ license | 20 +++----------- package.json | 73 +++++++++++++++++++++++++------------------------ readme.md | 6 ++-- test.js | 6 ++-- 13 files changed, 75 insertions(+), 82 deletions(-) delete mode 100644 .jshintrc create mode 100644 .npmrc create mode 100644 index.d.ts create mode 100644 index.test-d.ts diff --git a/.editorconfig b/.editorconfig index 86c8f59..1c6314a 100644 --- a/.editorconfig +++ b/.editorconfig @@ -7,9 +7,6 @@ charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true -[package.json] +[*.yml] indent_style = space indent_size = 2 - -[*.md] -trim_trailing_whitespace = false diff --git a/.gitattributes b/.gitattributes index 176a458..6313b56 100644 --- a/.gitattributes +++ b/.gitattributes @@ -1 +1 @@ -* text=auto +* text=auto eol=lf diff --git a/.gitignore b/.gitignore index 3c3629e..239ecff 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +yarn.lock diff --git a/.jshintrc b/.jshintrc deleted file mode 100644 index 804f8af..0000000 --- a/.jshintrc +++ /dev/null @@ -1,13 +0,0 @@ -{ - "node": true, - "esnext": true, - "bitwise": true, - "camelcase": true, - "curly": true, - "immed": true, - "newcap": true, - "noarg": true, - "undef": true, - "unused": "vars", - "strict": true -} diff --git a/.npmrc b/.npmrc new file mode 100644 index 0000000..43c97e7 --- /dev/null +++ b/.npmrc @@ -0,0 +1 @@ +package-lock=false diff --git a/.travis.yml b/.travis.yml index dedfc07..f3fa8cd 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,6 +1,4 @@ -sudo: false language: node_js node_js: - - 'iojs' - - '0.12' - - '0.10' + - '10' + - '8' diff --git a/index.d.ts b/index.d.ts new file mode 100644 index 0000000..1cc4889 --- /dev/null +++ b/index.d.ts @@ -0,0 +1,14 @@ +/** +Remove leading, trailing and repeated whitespace from a string. + +@example +``` +import condenseWhitespace = require('condense-whitespace'); + +condenseWhitespace(' foo bar baz '); +//=> 'foo bar baz' +``` +*/ +declare function condenseWhitespace(str: string): string; + +export = condenseWhitespace; diff --git a/index.js b/index.js index dc65523..631d750 100644 --- a/index.js +++ b/index.js @@ -1,8 +1,8 @@ 'use strict'; -module.exports = function (str, opts) { - if (typeof str !== 'string') { +module.exports = string => { + if (typeof string !== 'string') { throw new TypeError('Expected a string'); } - return str.trim().replace(/\s{2,}/g, ' '); + return string.trim().replace(/\s{2,}/g, ' '); }; diff --git a/index.test-d.ts b/index.test-d.ts new file mode 100644 index 0000000..0d64a7f --- /dev/null +++ b/index.test-d.ts @@ -0,0 +1,4 @@ +import {expectType} from 'tsd'; +import condense = require('.'); + +expectType(condense(' \n\n\t Hello World \t\n')); diff --git a/license b/license index 654d0bf..e7af2f7 100644 --- a/license +++ b/license @@ -1,21 +1,9 @@ -The MIT License (MIT) +MIT License Copyright (c) Sindre Sorhus (sindresorhus.com) -Permission is hereby granted, free of charge, to any person obtaining a copy -of this software and associated documentation files (the "Software"), to deal -in the Software without restriction, including without limitation the rights -to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -copies of the Software, and to permit persons to whom the Software is -furnished to do so, subject to the following conditions: +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: -The above copyright notice and this permission notice shall be included in -all copies or substantial portions of the Software. +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. -THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -THE SOFTWARE. +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. diff --git a/package.json b/package.json index cacbd8a..49041a7 100644 --- a/package.json +++ b/package.json @@ -1,37 +1,40 @@ { - "name": "condense-whitespace", - "version": "1.0.0", - "description": "Remove leading, trailing and repeated whitespace from a string", - "license": "MIT", - "repository": "sindresorhus/condense-whitespace", - "author": { - "name": "Sindre Sorhus", - "email": "sindresorhus@gmail.com", - "url": "sindresorhus.com" - }, - "engines": { - "node": ">=0.10.0" - }, - "scripts": { - "test": "ava" - }, - "files": [ - "index.js" - ], - "keywords": [ - "whitespace", - "space", - "condense", - "collapse", - "compact", - "repeated", - "string", - "str", - "trim", - "remove", - "strip" - ], - "devDependencies": { - "ava": "*" - } + "name": "condense-whitespace", + "version": "1.0.0", + "description": "Remove leading, trailing and repeated whitespace from a string", + "license": "MIT", + "repository": "sindresorhus/condense-whitespace", + "author": { + "name": "Sindre Sorhus", + "email": "sindresorhus@gmail.com", + "url": "sindresorhus.com" + }, + "engines": { + "node": ">=8" + }, + "scripts": { + "test": "xo && ava && tsd" + }, + "files": [ + "index.js", + "index.d.ts" + ], + "keywords": [ + "whitespace", + "space", + "condense", + "collapse", + "compact", + "repeated", + "string", + "str", + "trim", + "remove", + "strip" + ], + "devDependencies": { + "ava": "^1.4.1", + "tsd": "^0.7.2", + "xo": "^0.24.0" + } } diff --git a/readme.md b/readme.md index 2a63899..658d981 100644 --- a/readme.md +++ b/readme.md @@ -6,14 +6,14 @@ ## Install ``` -$ npm install --save condense-whitespace +$ npm install condense-whitespace ``` ## Usage ```js -var condenseWhitespace = require('condense-whitespace'); +const condenseWhitespace = require('condense-whitespace'); condenseWhitespace(' foo bar baz '); //=> 'foo bar baz' @@ -27,4 +27,4 @@ condenseWhitespace(' foo bar baz '); ## License -MIT © [Sindre Sorhus](http://sindresorhus.com) +MIT © [Sindre Sorhus](https://sindresorhus.com) diff --git a/test.js b/test.js index 1df1a79..370711e 100644 --- a/test.js +++ b/test.js @@ -1,6 +1,6 @@ import test from 'ava'; -import m from './'; +import condenseWhitespace from '.'; -test(t => { - t.is(m(' foo bar baz '), 'foo bar baz'); +test('main', t => { + t.is(condenseWhitespace(' foo bar baz '), 'foo bar baz'); });