Skip to content

Commit

Permalink
Release: #1 options parameter and ignore_stages options
Browse files Browse the repository at this point in the history
Add also CHANGELOG.md, CONTRIBUTING.md and update README.md. Also update .gitignore to not track .tmp/ directory.
  • Loading branch information
q2s2t committed Jul 31, 2014
1 parent 6dff938 commit e4bfa01
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 6 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,3 +17,6 @@ build/Release
# Deployed apps should consider commenting this line out:
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

# Temporary files
.tmp
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Changelog [^1]
==============

### `v0.1.0` 2014-07-31

* API change: Add a optional `options` parameter to the function.
* New feature: Use `{ ignore_stages: true }` to only return stables versions.

[^1]: Date in *ISO 8601* format (year-month-day)
13 changes: 13 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
Contributing :heart:
====================

Thanks for your interest! In order to keep the code coherent there are some
easy-to-follow rules.

* Use [JSHint](http://www.jshint.com) and respect the `.jshintrc` file.
* Use [EditorConfig](http://www.editorconfig.com) and respect the
`.editorconfig` file.
* Write test for your modifications (use `mocha` and `chai` modules).
* Keep the code coverage as high as possible (100% is awesome!). Install
`istanbul` module and run `npm run coverage` to check it.
* Proudly add yourself to the authors in `package.json`! :+1:
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
[![version-sort logo](https://raw.githubusercontent.com/quentinrossetti/version-sort/master/logo.png)](https://github.com/quentinrossetti/version-sort)
version-sort
============

[![Dependencies Status][gemnasium-image]][gemnasium-url] [![Build Status][travis-image]][travis-url] [![Code quality][codeclimate-image]][codeclimate-url] [![Code coverage][coveralls-image]][coveralls-url] [![Release][npm-image]][npm-url]

Expand All @@ -18,17 +19,26 @@ This module sort an array of versions. Here some exemples of valid versions:
2.4.20alpha
2.4.20beta
2.4.20rc1
2.4.20rc
2.4.20rc2
```

To use it just call the module as a function.

```js
var sort = require('version-sort');
data = [ '2.4.20', '2.4.20rc1', '1.1', '2.4.20beta1' ];
sort(data); // '1.1', '2.4.20', '2.4.20beta1', '2.4.20rc1'
sort(data); // '1.1', '2.4.20beta1', '2.4.20rc1', '2.4.20'
```

### Options

```js
var results = sort(data, options);
```

* `ignore_stages`: *(default: `false`)* Only return stables versions and ignore
staged versions. `[ '1.1', '1.1alpha' ]` will return `[ '1.1' ]`.

## Installation

```bat
Expand Down
13 changes: 12 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,18 @@ var _ = require('underscore');
* @module version-sort
* @function index
* @param {array} versions An array of versions to sort.
* @param {object} opts An object of options.
* @return {array} The same version array but sorted.*
* @license http://git.io/bHDfwQ ISC License
*/
module.exports = function (versions) {
module.exports = function (versions, opts) {

var options = {
ignore_stages: false
};
if (opts) {
options.ignore_stages = opts.ignore_stages || options.ignore_stages
}

var regex = /^([\d+\.]+)(([a-z]*)(\d*))$/;

Expand Down Expand Up @@ -97,6 +105,9 @@ module.exports = function (versions) {
var versionsSort = [];

v.forEach(function (_version, _i) {
if (options.ignore_stages && _version.stageName) {
return;
}
var calc = '';
// number
var split = _version.number.split('.');
Expand Down
Binary file removed logo.png
Binary file not shown.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "version-sort",
"version": "0.0.1",
"version": "0.1.0",
"description": "Sort an array of versions.",
"main": "index.js",
"scripts": {
Expand Down
8 changes: 7 additions & 1 deletion test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ var expect = chai.expect;

describe('version-sorter module', function () {

it('should sort softwares by version properly', function () {
it('should sort versions properly', function () {
var data = [
'1.1.0',
'1.1.4.5687',
Expand Down Expand Up @@ -36,4 +36,10 @@ describe('version-sorter module', function () {
}
});

it('should return only stables version with `ignore_stages`', function () {
var data = [ '1.1alpha', '1.1', '1.2beta', '1.2', '1.3alpha' ];
var r = sorter(data, { ignore_stages: true });
expect(r).to.eql([ '1.1', '1.2' ]);
});

});

0 comments on commit e4bfa01

Please sign in to comment.