diff --git a/.eslintrc.json b/.eslintrc.json index 81fcd29..e5edcfc 100644 --- a/.eslintrc.json +++ b/.eslintrc.json @@ -1,11 +1,6 @@ { "root": true, "extends": "@nwoltman/eslint-config", - "rules": { - "object-shorthand": 0, - "padded-blocks": 0, - "prefer-arrow-callback": 0 - }, "overrides": [ { "files": ["test/*.js"], @@ -15,7 +10,9 @@ "rules": { "brace-style": 0, "max-len": 0, - "max-nested-callbacks": 0 + "max-nested-callbacks": 0, + "padded-blocks": 0, + "prefer-arrow-callback": 0 } } ] diff --git a/benchmark/run.js b/benchmark/run.js index 57d9d2b..d2b8793 100644 --- a/benchmark/run.js +++ b/benchmark/run.js @@ -1,24 +1,24 @@ /* eslint-disable no-console */ 'use strict'; -var Benchmark = require('benchmark'); +const Benchmark = require('benchmark'); -var naturalCompareMaster = require('string-natural-compare'); -var naturalCompareLocal = require('../'); +const naturalCompareMaster = require('string-natural-compare'); +const naturalCompareLocal = require('../'); -var config = new Set( +const config = new Set( process.argv.length > 2 ? process.argv[2].split(',') : '1234567' ); -var suite = new Benchmark.Suite(); +const suite = new Benchmark.Suite(); if (config.has('1')) { suite - .add('1) no numbers master', function() { + .add('1) no numbers master', () => { naturalCompareMaster('fileA.txt', 'fileB.txt'); naturalCompareMaster('fileB.txt', 'fileA.txt'); }) - .add('1) no numbers local', function() { + .add('1) no numbers local', () => { naturalCompareLocal('fileA.txt', 'fileB.txt'); naturalCompareLocal('fileB.txt', 'fileA.txt'); }); @@ -26,11 +26,11 @@ if (config.has('1')) { if (config.has('2')) { suite - .add('2) common numbers different lengths master', function() { + .add('2) common numbers different lengths master', () => { naturalCompareMaster('2.txt', '10.txt'); naturalCompareMaster('10.txt', '2.txt'); }) - .add('2) common numbers different lengths local', function() { + .add('2) common numbers different lengths local', () => { naturalCompareLocal('2.txt', '10.txt'); naturalCompareLocal('10.txt', '2.txt'); }); @@ -38,11 +38,11 @@ if (config.has('2')) { if (config.has('3')) { suite - .add('3) common numbers same length master', function() { + .add('3) common numbers same length master', () => { naturalCompareMaster('01.txt', '05.txt'); naturalCompareMaster('05.txt', '01.txt'); }) - .add('3) common numbers same length local', function() { + .add('3) common numbers same length local', () => { naturalCompareLocal('01.txt', '05.txt'); naturalCompareLocal('05.txt', '01.txt'); }); @@ -50,7 +50,7 @@ if (config.has('3')) { if (config.has('4')) { suite - .add('4) big numbers different lengths master', function() { + .add('4) big numbers different lengths master', () => { naturalCompareMaster( '1165874568735487968325787328996865', '265812277985321589735871687040841' @@ -60,7 +60,7 @@ if (config.has('4')) { '1165874568735487968325787328996865' ); }) - .add('4) big numbers different lengths local', function() { + .add('4) big numbers different lengths local', () => { naturalCompareLocal( '1165874568735487968325787328996865', '265812277985321589735871687040841' @@ -74,7 +74,7 @@ if (config.has('4')) { if (config.has('5')) { suite - .add('5) big numbers same length master', function() { + .add('5) big numbers same length master', () => { naturalCompareMaster( '1165874568735487968325787328996865', '1165874568735487989735871687040841' @@ -84,7 +84,7 @@ if (config.has('5')) { '1165874568735487968325787328996865' ); }) - .add('5) big numbers same length local', function() { + .add('5) big numbers same length local', () => { naturalCompareLocal( '1165874568735487968325787328996865', '1165874568735487989735871687040841' @@ -98,7 +98,7 @@ if (config.has('5')) { if (suite.length) { suite - .on('cycle', function(event) { + .on('cycle', (event) => { console.log(String(event.target)); }) .run(); @@ -107,35 +107,35 @@ if (suite.length) { naturalCompareMaster.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; naturalCompareLocal.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; -suite = new Benchmark.Suite(); +const alphabetSuite = new Benchmark.Suite(); if (config.has('6')) { - suite - .add('6) custom alphabet included characters master', function() { + alphabetSuite + .add('6) custom alphabet included characters master', () => { naturalCompareMaster('š.txt', 'z.txt'); naturalCompareMaster('z.txt', 'š.txt'); }) - .add('6) custom alphabet included characters local', function() { + .add('6) custom alphabet included characters local', () => { naturalCompareLocal('š.txt', 'z.txt'); naturalCompareLocal('z.txt', 'š.txt'); }); } if (config.has('7')) { - suite - .add('7) custom alphabet missing characters master', function() { + alphabetSuite + .add('7) custom alphabet missing characters master', () => { naturalCompareMaster('é.txt', 'à.txt'); naturalCompareMaster('à.txt', 'é.txt'); }) - .add('7) custom alphabet missing characters local', function() { + .add('7) custom alphabet missing characters local', () => { naturalCompareLocal('é.txt', 'à.txt'); naturalCompareLocal('à.txt', 'é.txt'); }); } -if (suite.length) { - suite - .on('cycle', function(event) { +if (alphabetSuite.length) { + alphabetSuite + .on('cycle', (event) => { console.log(String(event.target)); }) .run(); diff --git a/natural-compare.js b/natural-compare.js index db90b75..cffa7e9 100644 --- a/natural-compare.js +++ b/natural-compare.js @@ -94,11 +94,11 @@ naturalCompare.caseInsensitive = naturalCompare.i = function(a, b) { Object.defineProperties(naturalCompare, { alphabet: { - get: function() { + get() { return alphabet; }, - set: function(value) { + set(value) { alphabet = value; alphabetIndexMap = []; diff --git a/test/test.js b/test/test.js index ce83ab9..9d9afbb 100644 --- a/test/test.js +++ b/test/test.js @@ -2,12 +2,12 @@ require('should'); -var naturalCompare = require('../'); +const naturalCompare = require('../'); function verify(testData) { - var a = testData[0]; - var b = testData[2]; - var failMessage = 'failure on input: [' + testData.join(' ') + ']'; + const a = testData[0]; + const b = testData[2]; + const failMessage = 'failure on input: [' + testData.join(' ') + ']'; switch (testData[1]) { case '=': @@ -27,9 +27,9 @@ function verify(testData) { } } -describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { +describe('naturalCompare() and naturalCompare.caseInsensitive()', () => { - it('should compare strings that do not contain numbers', function() { + it('should compare strings that do not contain numbers', () => { [ ['a', '=', 'a'], ['a', '<', 'b'], @@ -45,7 +45,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should compare integer substrings by their numeric value', function() { + it('should compare integer substrings by their numeric value', () => { [ ['1', '=', '1'], ['50', '=', '50'], @@ -74,7 +74,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should work with 0 in the string', function() { + it('should work with 0 in the string', () => { [ ['a00', '<', 'a000'], ['a 0 a', '<', 'a 0 b'], @@ -88,7 +88,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should compare integer substrings with leading 0s by their numeric value', function() { + it('should compare integer substrings with leading 0s by their numeric value', () => { [ ['000', '=', '000'], ['001', '=', '001'], @@ -99,7 +99,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should not consider a decimal point surrounded by integers as a floating point number', function() { + it('should not consider a decimal point surrounded by integers as a floating point number', () => { [ ['0.01', '<', '0.001'], ['0.001', '>', '0.01'], @@ -108,7 +108,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should not consider an integer preceeded by a minus sign as a negative number', function() { + it('should not consider an integer preceeded by a minus sign as a negative number', () => { [ ['-1', '<', '-2'], ['-2', '<', '-10'], @@ -118,7 +118,7 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { ].forEach(verify); }); - it('should compare non-string inputs as strings', function() { + it('should compare non-string inputs as strings', () => { [ [1, '<', 2], [2, '>', 1], @@ -127,14 +127,14 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { [null, '<', undefined], [{}, '=', {}], [ - {toString: function() { return 'a'; }}, + {toString: () => 'a'}, '<', - {toString: function() { return 'b'; }}, + {toString: () => 'b'}, ], ].forEach(verify); }); - it('should correctly compare strings containing very large numbers', function() { + it('should correctly compare strings containing very large numbers', () => { [ [ '1165874568735487968325787328996864', @@ -157,14 +157,14 @@ describe('naturalCompare() and naturalCompare.caseInsensitive()', function() { }); -describe('naturalCompare()', function() { +describe('naturalCompare()', () => { - it('should perform case-sensitive comparisons', function() { + it('should perform case-sensitive comparisons', () => { naturalCompare('a', 'A').should.be.greaterThan(0); naturalCompare('b', 'C').should.be.greaterThan(0); }); - it('should function correctly as the callback to array.sort()', function() { + it('should function correctly as the callback to array.sort()', () => { ['a', 'c', 'b', 'd'] .sort(naturalCompare) .should.deepEqual(['a', 'b', 'c', 'd']); @@ -202,7 +202,7 @@ describe('naturalCompare()', function() { ]); }); - it('should compare strings using the provided alphabet', function() { + it('should compare strings using the provided alphabet', () => { naturalCompare.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; ['Д', 'a', 'ä', 'B', 'Š', 'X', 'A', 'õ', 'u', 'z', '1', '2', '9', '10'] @@ -215,20 +215,20 @@ describe('naturalCompare()', function() { }); -describe('naturalCompare.caseInsensitive()', function() { +describe('naturalCompare.caseInsensitive()', () => { - it('should perform case-insensitive comparisons', function() { + it('should perform case-insensitive comparisons', () => { naturalCompare.caseInsensitive('a', 'A').should.equal(0); naturalCompare.caseInsensitive('b', 'C').should.be.lessThan(0); }); - it('should function correctly as the callback to array.sort()', function() { + it('should function correctly as the callback to array.sort()', () => { ['C', 'B', 'a', 'd'] .sort(naturalCompare.caseInsensitive) .should.deepEqual(['a', 'B', 'C', 'd']); }); - it('should compare strings using the provided alphabet', function() { + it('should compare strings using the provided alphabet', () => { naturalCompare.alphabet = 'ABDEFGHIJKLMNOPRSŠZŽTUVÕÄÖÜXYabdefghijklmnoprsšzžtuvõäöüxy'; ['Д', 'a', 'ä', 'B', 'Š', 'X', 'Ü', 'õ', 'u', 'z', '1', '2', '9', '10'] @@ -239,23 +239,23 @@ describe('naturalCompare.caseInsensitive()', function() { }); -describe('naturalCompare.i', function() { +describe('naturalCompare.i', () => { - it('is an alias for naturalCompare.caseInsensitive', function() { + it('is an alias for naturalCompare.caseInsensitive', () => { naturalCompare.i.should.equal(naturalCompare.caseInsensitive); }); }); -describe('naturalCompare.alphabet', function() { +describe('naturalCompare.alphabet', () => { - it('can be set and retrieved', function() { + it('can be set and retrieved', () => { naturalCompare.alphabet = 'cba'; naturalCompare.alphabet.should.equal('cba'); }); - it('can be set to null', function() { + it('can be set to null', () => { naturalCompare.alphabet = null; });