Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
shinnn committed Nov 1, 2015
0 parents commit aa89cb2
Show file tree
Hide file tree
Showing 10 changed files with 304 additions and 0 deletions.
12 changes: 12 additions & 0 deletions .editorconfig
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
root = true

[*]
charset = utf-8
end_of_line = lf
indent_style = space
indent_size = 2
insert_final_newline = true
trim_trailing_whitespace = true

[*.md]
trim_trailing_whitespace = false
1 change: 1 addition & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
* text=auto
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.nyc_output
node_modules
11 changes: 11 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
git:
depth: 1
branches:
except: /^v\d/
language: node_js
node_js: stable
after_script:
- npm install coveralls
- ./node_modules/.bin/nyc report --reporter=text-lcov | ./node_modules/.bin/coveralls
notifications:
email: false
20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
The MIT License (MIT)

Copyright (c) 2015 Shinnosuke Watanabe

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 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.
81 changes: 81 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
# filter-changelog-paths

[![NPM version](https://img.shields.io/npm/v/filter-changelog-paths.svg)](https://www.npmjs.com/package/filter-changelog-paths)
[![Build Status](https://travis-ci.org/shinnn/filter-changelog-paths.svg?branch=master)](https://travis-ci.org/shinnn/filter-changelog-paths)
[![Build status](https://ci.appveyor.com/api/projects/status/7yw5cmfmry41iu9m/branch/master?svg=true)](https://ci.appveyor.com/project/ShinnosukeWatanabe/filter-changelog-paths/branch/master)
[![Coverage Status](https://img.shields.io/coveralls/shinnn/filter-changelog-paths.svg)](https://coveralls.io/github/shinnn/filter-changelog-paths)
[![Dependency Status](https://david-dm.org/shinnn/filter-changelog-paths.svg)](https://david-dm.org/shinnn/filter-changelog-paths)
[![devDependency Status](https://david-dm.org/shinnn/filter-changelog-paths/dev-status.svg)](https://david-dm.org/shinnn/filter-changelog-paths#info=devDependencies)

A [Node](https://nodejs.org/) module to extract CHANGELOG-like paths from multiple file paths

```javascript
const filterChangelogPaths = require('filter-changelog-paths');

filterChangelogPaths([
'CHANGELOG.txt',
'CONTRIBUTING',
'project/docs/release_notes.md',
'lib/index.js'
]);
//=> ['CHANGELOG.txt', 'project/docs/release_notes.md']
```

## Installation

[Use npm.](https://docs.npmjs.com/cli/install)

```
npm install filter-changelog-paths
```

## API

```javascript
const filterChangelogPaths = require('filter-changelog-paths');
```

### filterChangelogPaths(*filePaths*)

*filePaths*: `Array` of strings (file [path](http://www.linfo.org/path.html)s)
Return: `Array` of strings

It [filters](https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Array/filter) a given array by using [is-changelog-path](https://github.com/shinnn/is-changelog-path) as a filter function.

```javascript
const filterChangelogPaths = require('filter-changelog-paths');

filterChangelogPaths([]); //=> []

filterChangelogPaths('changelog'); // throws a type error
filterChangelogPaths(['changelog', 1, 'history', true]); // throws a type error
filterChangelogPaths(); // throws a type error
```

### filterChangelogPaths.posix(*filePaths*)

*filePaths*: `Array` of strings (file paths)
Return: `Array` of strings

Always interact in a [posix](https://www.opengroup.org/austin/papers/posix_faq.html) compatible way.

```javascript
filterChangelogPaths.posix(['dir\\releases']); //=> []
```

### filterChangelogPaths.win32(*filePaths*)

*filePaths*: `Array` of strings (file paths)
Return: `Array` of strings

```javascript
filterChangelogPaths.win32(['dir\\releases']); //=> ['dir\\releases']
```

Always interact in a [win32](https://msdn.microsoft.com/library/cc433218) compatible way.

## License

Copyright (c) 2015 [Shinnosuke Watanabe](https://github.com/shinnn)

Licensed under [the MIT License](./LICENSE).
9 changes: 9 additions & 0 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
shallow_clone: true
version: '{build}'
skip_tags: true
install:
- ps: Install-Product node 5
- npm install
build: off
test_script: npm run-script test-only
cache: node_modules -> package.json
40 changes: 40 additions & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*!
* filter-changelog-paths | MIT (c) Shinnosuke Watanabe
* https://github.com/shinnn/filter-changelog-paths
*/
'use strict';

const isChangelogPath = require('is-changelog-path');
const filteredArrayToSentence = require('filtered-array-to-sentence');

const isNotString = v => typeof v !== 'string';

function filterChangelogPathsCore(filePaths, filterFn) {
if (!Array.isArray(filePaths)) {
throw new TypeError(`${filePaths} is not an array. Expected an array of file paths.`);
}

const nonStringValues = filteredArrayToSentence(filePaths, isNotString);

if (nonStringValues !== '') {
throw new TypeError(
'The array includes non-string value(s): ' +
nonStringValues +
'. Expected every item in the array to be a file path.'
);
}

return filePaths.filter(filterFn);
}

module.exports = function filterChangelogPaths(filePaths) {
return filterChangelogPathsCore(filePaths, isChangelogPath);
};

module.exports.posix = function filterChangelogPathsPosix(filePaths) {
return filterChangelogPathsCore(filePaths, isChangelogPath.posix);
};

module.exports.win32 = function filterChangelogPathsWin32(filePaths) {
return filterChangelogPathsCore(filePaths, isChangelogPath.win32);
};
49 changes: 49 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
{
"name": "filter-changelog-paths",
"version": "1.0.0",
"description": "Extract CHANGELOG-like paths from multiple file paths",
"repository": "shinnn/filter-changelog-paths",
"author": "Shinnosuke Watanabe (https://github.com/shinnn)",
"scripts": {
"pretest": "eslint --fix --config @shinnn/node index.js test.js",
"test": "tap --coverage --reporter=spec test.js",
"test-only": "tap --reporter=spec test.js"
},
"license": "MIT",
"files": [
"index.js"
],
"keywords": [
"arr",
"ary",
"array",
"filter",
"filtering",
"extract",
"extraction",
"filename",
"filenames",
"name",
"path",
"paths",
"log",
"changelog",
"change-log",
"updates",
"releases",
"release-history",
"history",
"releasenote",
"match"
],
"dependencies": {
"filtered-array-to-sentence": "^1.0.0",
"is-changelog-path": "^1.1.0"
},
"devDependencies": {
"@shinnn/eslint-config-node": "^1.0.1",
"eslint": "^1.10.2",
"nyc": "^4.0.1",
"tap": "^2.3.1"
}
}
79 changes: 79 additions & 0 deletions test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
'use strong';

const path = require('path');

const filterChangelogPaths = require('.');
const tap = require('tap');

tap.test('filterChangelogPaths', t => {
t.plan(6);

t.strictEqual(filterChangelogPaths.name, 'filterChangelogPaths', 'should have a function name.');

const expected = path.join('1/2/3', 'changelog.txt');

t.same(
filterChangelogPaths([expected, 'foo']),
[expected],
'should filter changelog-like paths.'
);

t.same(
filterChangelogPaths(['foo', 'bar']),
[],
'should return an empty array when the array contains no changelog-like paths.'
);

t.throws(
() => filterChangelogPaths(1),
new TypeError('1 is not an array. Expected an array of file paths.'),
'should throw a type error when it takes a non-string argument.'
);

t.throws(
() => filterChangelogPaths(['foo', 1, 'bar', true]),
new TypeError(
'The array includes non-string value(s): 1 (index: 1) and true (index: 3). ' +
'Expected every item in the array to be a file path.'
),
'should throw a type error when it takes a non-string argument.'
);

t.throws(
() => filterChangelogPaths(),
new TypeError('undefined is not an array. Expected an array of file paths.'),
'should throw a type error when it takes no arguments.'
);
});

tap.test('filterChangelogPaths.posix', t => {
t.plan(2);

t.strictEqual(
filterChangelogPaths.posix.name,
'filterChangelogPathsPosix',
'should have a function name.'
);

t.same(
filterChangelogPaths.posix(['dir\\History']),
[],
'should always treat paths in a posix compatible way.'
);
});

tap.test('filterChangelogPaths.win32', t => {
t.plan(2);

t.strictEqual(
filterChangelogPaths.win32.name,
'filterChangelogPathsWin32',
'should have a function name.'
);

t.same(
filterChangelogPaths.win32(['dir\\History']),
['dir\\History'],
'should always treat paths in a win32 compatible way.'
);
});

0 comments on commit aa89cb2

Please sign in to comment.