Skip to content

Commit

Permalink
move to eslint
Browse files Browse the repository at this point in the history
  • Loading branch information
williambelle committed Jun 7, 2018
1 parent 0bd405c commit 33ea1d1
Show file tree
Hide file tree
Showing 7 changed files with 34 additions and 37 deletions.
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
coverage/**/*.js
11 changes: 11 additions & 0 deletions .eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"extends": "standard",
"env": {
"mocha": true,
"node": true
},
"rules": {
"max-len": [2, 80],
"semi": [2, "always"]
}
}
2 changes: 0 additions & 2 deletions .jshintignore

This file was deleted.

17 changes: 0 additions & 17 deletions .jshintrc

This file was deleted.

9 changes: 7 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,19 @@
"node": ">= 4.0.0"
},
"scripts": {
"test": "jshint . && mocha",
"test": "eslint . && mocha",
"coverage": "istanbul cover _mocha",
"coveralls": "npm run coverage -- --report lcovonly && cat ./coverage/lcov.info | coveralls"
},
"devDependencies": {
"chai": "^4.1.2",
"eslint": "^4.19.1",
"eslint-config-standard": "^11.0.0",
"eslint-plugin-import": "^2.12.0",
"eslint-plugin-node": "^6.0.1",
"eslint-plugin-promise": "^3.8.0",
"eslint-plugin-standard": "^3.1.0",
"istanbul": "^0.4.5",
"jshint": "~2.9.5",
"mocha": "^5.2.0"
}
}
11 changes: 5 additions & 6 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict';

module.exports = function(url, length) {

module.exports = function (url, length) {
if (typeof url !== 'string') {
throw new TypeError('Expected url to be a string');
}
Expand All @@ -23,7 +22,7 @@ module.exports = function(url, length) {
// Replace /foo/bar/foo/ with /…/…/…/
var urlLength = url.length;
while (urlLength > length) {
url = url.replace(/(.*[^\/])\/[^\/…]+\/([^\/])/, '$1/…/$2');
url = url.replace(/(.*[^/])\/[^/…]+\/([^/])/, '$1/…/$2');
if (url.length === urlLength) {
break;
} else {
Expand All @@ -40,14 +39,14 @@ module.exports = function(url, length) {
if (idx === -1) {
break;
}
url = url.substring(0,idx) + '…';
url = url.substring(0, idx) + '…';
}

// Replace first param
if (url.length > length) {
idx = url.lastIndexOf('?');
if (idx !== -1) {
url = url.substring(0,idx) + '?…';
url = url.substring(0, idx) + '?…';
}
}

Expand All @@ -57,7 +56,7 @@ module.exports = function(url, length) {
if (idx === -1) {
break;
}
url = url.substring(0,idx) + '…';
url = url.substring(0, idx) + '…';
}

return url;
Expand Down
20 changes: 10 additions & 10 deletions test/test-crop-url.js
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
'use strict';

var should = require('chai').should();
require('chai').should();
var cropUrl = require('../src/index.js');

describe('cropUrl', function(){
it('should check input type', function(){
(function(){
cropUrl(51,69);
describe('cropUrl', function () {
it('should check input type', function () {
(function () {
cropUrl(51, 69);
}).should.throw(TypeError, 'Expected url to be a string');
(function(){
cropUrl('foobar',69);
(function () {
cropUrl('foobar', 69);
}).should.not.throw(TypeError, 'Expected url to be a string');

(function(){
(function () {
cropUrl('foobar', undefined);
}).should.throw(TypeError, 'Expected length to be a number');
(function(){
(function () {
cropUrl('foobar', 69);
}).should.not.throw(TypeError, 'Expected length to be a number');
});

it('should crop url', function(){
it('should crop url', function () {
cropUrl('http://www.foobar.com/abc/def/ghi/index.html', 99).should.equal(
'http://www.foobar.com/abc/def/ghi/index.html'
);
Expand Down

0 comments on commit 33ea1d1

Please sign in to comment.