diff --git a/.npmignore b/.npmignore index 5a1fa5a..684868f 100644 --- a/.npmignore +++ b/.npmignore @@ -14,4 +14,11 @@ coverage #editor settings .idea -.editorconfig \ No newline at end of file +.editorconfig + +#core +src +docs +node_modules +test +tools \ No newline at end of file diff --git a/.travis.yml b/.travis.yml index 8ff5525..0c146d0 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,5 +7,4 @@ script: - npm run lint - npm run test:cover after_success: - - npm run coveralls - - bump --minor --commit --tag + - npm run coveralls \ No newline at end of file diff --git a/README.md b/README.md index 10a630b..f661801 100644 --- a/README.md +++ b/README.md @@ -5,6 +5,7 @@ [![Build Status](https://travis-ci.org/NeeleshRoy/sorting-js.svg?branch=develop)](https://travis-ci.org/NeeleshRoy/sorting-js) [![Coverage Status](https://coveralls.io/repos/github/NeeleshRoy/sorting-js/badge.svg?style=flat-square)](https://coveralls.io/github/NeeleshRoy/sorting-js) [![dependencies Status](https://david-dm.org/neeleshroy/sorting-js/status.svg?style=flat-square)](https://david-dm.org/neeleshroy/sorting-js) +[![NPM](https://nodei.co/npm/sorting-javascript.png)](https://nodei.co/npm/sorting-javascript/) > Sorting algorithms implemented in JS @@ -16,7 +17,33 @@ $ npm install sorting-javascript ### Getting Started +ES6 - Use named imports +```javascript + import { insertionSort } from 'sorting-javascript' + insertionSort([7, 2, 5]) // Output - [2, 5, 7] +``` + +Node.JS require +```javascript + var sort = require('sorting-javascript') + sort.insertionSort([7, 2, 5]) // Output - [2, 5, 7] +``` + +There is an extra utility function called ArrayTestBed which generates random numbers +to test the sorting algorithms. +```javascript + import { ArrayTestBed } from 'sorting-javascript' + const test = new ArrayTestBed(1000); + test.setData() // test variable will have 1000 randomly generated numbers between 0-1000 +``` +By default, it will contain unique elements. If you pass random = false to the setData function, then the result will contain duplicates. +eg: +```javascript + test.setData(false) // [5, 6, 6, 8, 3, 2, 2] + test.setData() // [1, 7, 6, 8, 3, 2, 5] +``` +## For Geeks :P ### How to Test Run one, or a combination of the following commands to lint and test your code: diff --git a/package.json b/package.json index 4996026..88117f3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "sorting-javascript", - "version": "0.0.5", + "version": "1.0.1", "description": "Sorting algorithms implemented in JS", "repository": "neeleshroy/sorting-js", "author": "Neelesh Roy", @@ -30,7 +30,7 @@ "babel-eslint": "^6.0.4", "babel-plugin-transform-runtime": "^6.8.0", "babel-preset-es2015": "^6.6.0", - "babel-preset-es2015-rollup": "^1.1.1", + "babel-preset-es2015-rollup": "^3.0.0", "babel-preset-stage-0": "^6.5.0", "babel-register": "^6.8.0", "bs-html-injector": "^3.0.3", diff --git a/src/bubble-sort/index.js b/src/bubble-sort/index.js index a1460f2..fccf28e 100644 --- a/src/bubble-sort/index.js +++ b/src/bubble-sort/index.js @@ -1,6 +1,6 @@ import swap from '../utils/swap'; -export function bubbleSort(unsorted, type = 'a') { +export default function (unsorted, type = 'a') { if (unsorted.length === 0) return unsorted; const r = unsorted; let p = r.length; diff --git a/src/index.js b/src/index.js index d872446..a52fa97 100644 --- a/src/index.js +++ b/src/index.js @@ -1,4 +1,11 @@ import { ArrayTestBed } from './utils/ArrayTestBed'; -import { bubbleSort } from './bubble-sort'; +import bubbleSort from './bubble-sort/index'; +import insertionSort from './insertion-sort/index'; +import selectionSort from './selection-sort/index'; -export default { ArrayTestBed, bubbleSort }; +module.exports = { + ArrayTestBed, + bubbleSort, + insertionSort, + selectionSort, +}; diff --git a/src/insertion-sort/index.js b/src/insertion-sort/index.js index 68092bc..adedbcc 100644 --- a/src/insertion-sort/index.js +++ b/src/insertion-sort/index.js @@ -1,4 +1,4 @@ -export function insertionSort(arr) { +export default function (arr) { const unsorted = arr; for (let i = 1; i < unsorted.length; i++) { diff --git a/src/selection-sort/index.js b/src/selection-sort/index.js index de48ee3..fdde898 100644 --- a/src/selection-sort/index.js +++ b/src/selection-sort/index.js @@ -1,6 +1,6 @@ import { getMin, getMax } from '../utils/maxMin'; -export function selectionSort(unsorted, type = 'a') { +export default function (unsorted, type = 'a') { if (unsorted.length === 0) return unsorted; const arr = unsorted; const sorted = []; diff --git a/test/bubble-sort.test.js b/test/bubble-sort.test.js index e752074..16a420d 100644 --- a/test/bubble-sort.test.js +++ b/test/bubble-sort.test.js @@ -8,7 +8,7 @@ */ import { expect } from 'chai'; -import { bubbleSort } from '../src/bubble-sort'; +import bubbleSort from '../src/bubble-sort'; describe('Bubble Sort', () => { diff --git a/test/insertion-sort.test.js b/test/insertion-sort.test.js index bef22ef..83b6c1e 100644 --- a/test/insertion-sort.test.js +++ b/test/insertion-sort.test.js @@ -8,7 +8,7 @@ */ import { expect } from 'chai'; -import { insertionSort } from '../src/insertion-sort'; +import insertionSort from '../src/insertion-sort'; describe('Insertion Sort', () => { diff --git a/test/selection-sort.test.js b/test/selection-sort.test.js index 5824e3c..43fb204 100644 --- a/test/selection-sort.test.js +++ b/test/selection-sort.test.js @@ -8,7 +8,7 @@ */ import { expect } from 'chai'; -import { selectionSort } from '../src/selection-sort'; +import selectionSort from '../src/selection-sort'; describe('Selection Sort', () => {