Skip to content

Commit

Permalink
style(eslint): fix max-line-length issues & jsDoc
Browse files Browse the repository at this point in the history
fix maximum line length issues and rewrite jsDoc comments
  • Loading branch information
victor nwaiwu committed Jan 9, 2017
1 parent dfc87d4 commit b5d3f0b
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 33 deletions.
5 changes: 3 additions & 2 deletions public/js/app.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
angular.module('StringExtension', [])
.controller('StringExtensionController', ['$scope', '$timeout', ($scope, $timeout) => {
.controller('StringExtensionController', ['$scope', '$timeout',
($scope, $timeout) => {
$scope.options = [
'hasVowels',
'toUpper',
Expand All @@ -21,7 +22,7 @@ angular.module('StringExtension', [])
$scope.result = '';
$scope.error = '';
$scope.getResult = (input, selected) => {
if (input === '' || input === undefined){
if (input === '' || input === undefined) {
$scope.result = '';
$scope.error = 'You did not enter any text';
return;
Expand Down
61 changes: 40 additions & 21 deletions src/string.js
Original file line number Diff line number Diff line change
@@ -1,68 +1,79 @@
const stringClassExtensions = {

/**
* Returns true if the string contains vowels.
* @returns {Boolean}
* hasVowels
* Returns true if the string contains vowels or false if it does not
* @returns {Boolean} true or false
*/
hasVowels() {
const vowelRegex = /[aeiou]/i;
return vowelRegex.test(this);
},

/**
* Returns the String in question but with all characters in upper cases as applicable.
* @returns {String}
* toUpper
* Returns the String in question but with
* all characters in upper cases as applicable
* @returns {String} string with all characters in upper case
*/
toUpper() {
return this.replace(/[a-z]/g, match => String
.fromCharCode(match.charCodeAt(0) - 32));
},

/**
* Returns the String in question but with all characters in their lower cases as applicable.
* @returns {String}
* toLower
* Returns the string in question but with all
* characters in their lower cases as applicable
* @returns {String} string with all characters to lower case
*/
toLower() {
return this.replace(/[A-Z]/g, match => String
.fromCharCode(match.charCodeAt(0) + 32));
},

/**
* Returns the String in question but changes the First Character to an Upper case.
* @returns {String}
* ucFirst
* Returns the string in question but changes the first character
* to an Upper case.
* @returns {String} string with capitalized first letter
*/
ucFirst() {
return this.replace(this[0], this[0].toUpper());
},

/**
* isQuestion
* Returns true if the string is a question (ending with a question mark)
* @returns {Boolean}
* @returns {Boolean} true or false
*/
isQuestion() {
const regexType = /\?$/g;
return regexType.test(this);
},

/**
* Returns a list of the words in the string, as an Array.
* @returns {Array}
* words
* Returns a list of the words in the string, as an Array
* @returns {Array} array of words in the string
*/
words() {
return this.replace(/[^a-z0-9A-Z\s]/g, '').split(/\s+/);
},

/**
* wordCount
* Returns the number of words in the string
* @returns {Number}
* @returns {Number} number of words in the string
*/
wordCount() {
return this.words().length;
},

/**
* toCurrency
* Returns a currency representation of the String
* @returns {String}
* @returns {String} string of numbers
*/
toCurrency() {
if (!Number(this)) {
Expand All @@ -79,8 +90,9 @@ const stringClassExtensions = {
},

/**
* fromCurrency
* Returns a number representation of the Currency String
* @returns {String}
* @returns {String} string of numbers
*/
fromCurrency() {
let [number, decimal] = this.split(/\./g);
Expand All @@ -94,26 +106,29 @@ const stringClassExtensions = {
},

/**
* inverseCase
* Returns each letter in the string as an inverse of its current case
* @returns {String}
* @returns {String} inverted form of the string
*/
inverseCase() {
return this.replace(/\w/g, character => (/[a-z]/
.test(character) ? character.toUpper() : character.toLower()));
},

/**
* alternatingCase
* Returns the letters in alternating cases. It must start with a lower case
* @returns {String}
* @returns {String} string in alternating cases starting with lower case
*/
alternatingCase() {
return this.replace(/\w/g, (match, count) =>
(count % 2 === 0 ? match.toLower() : match.toUpper()));
},

/**
* getMiddle
* Returns the character(s) in the middle of the string
* @returns {String}
* @returns {String} character(s) in the middle of the string
*/
getMiddle() {
const middlePosition = this.length / 2;
Expand All @@ -122,24 +137,28 @@ const stringClassExtensions = {
},

/**
* Returns true if a string contains double characters(including whitespace character)
* @return {Boolean}
* doubleCheck
* Returns true if a string contains double characters
* (including whitespace character)
* @return {Boolean} true or false
*/
doubleCheck() {
return /(.)\1{1}/.test(this);
},

/**
* isDigit
* Test if string is single digit
* @return {Boolean}
* @return {Boolean} true or false
*/
isDigit() {
return /^\d{1}$/g.test(this);
},

/**
* numberWords
* Returns the numbers in words e.g 325 should return three two five.
* @returns {String}
* @returns {String} string form of numbers
*/
numberWords() {
if (!Number(this)) {
Expand Down
29 changes: 19 additions & 10 deletions test/string.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,23 +17,26 @@ describe('String Class', () => {
});

describe('toUpper', () => {
it('returns the String in question but with all characters in upper cases as applicable', () => {
it(`returns the String in question but with all characters in upper cases
as applicable`, () => {
expect('andela'.toUpper()).to.equal('ANDELA');
expect('Andela'.toUpper()).to.equal('ANDELA');
expect('EXCELLENCE'.toUpper()).to.equal('EXCELLENCE');
});
});

describe('toLower', () => {
it('returns the String in question but with all characters in their lower cases as applicable', () => {
it(`returns the String in question but with all characters in their lower
cases as applicable`, () => {
expect('BRILLIANCE'.toLower()).to.equal('brilliance');
expect('MAnnequiN'.toLower()).to.equal('mannequin');
expect('andela'.toLower()).to.equal('andela');
});
});

describe('ucFirst', () => {
it('returns the String in question but changes the first character to an upper case', () => {
it(`returns the String in question but changes the first character to an
upper case`, () => {
expect('mama'.ucFirst()).to.equal('Mama');
expect('nigeria'.ucFirst()).to.equal('Nigeria');
expect('mONDAY'.ucFirst()).to.equal('MONDAY');
Expand All @@ -42,12 +45,14 @@ describe('String Class', () => {
});

describe('isQuestion', () => {
it('returns true if the string is a question (ending with a question mark)', () => {
it(`returns true if the string is a question
(ending with a question mark)`, () => {
expect('Who are you?'.isQuestion()).to.be.true;
expect('Are you there?'.isQuestion()).to.be.true;
expect('what?'.isQuestion()).to.be.true;
});
it('returns false if the string is not a question (ending with a question mark)', () => {
it(`returns false if the string is not a question
(ending with a question mark)`, () => {
expect('where are you'.isQuestion()).to.be.false;
expect('welcome home'.isQuestion()).to.be.false;
});
Expand All @@ -72,7 +77,7 @@ describe('String Class', () => {
expect('11111.11'.toCurrency()).to.equal('11,111.11');
expect('2535678'.toCurrency()).to.equal('2,535,678.00');
});
it('returns an error message if the string is not of type "number"', () => {
it('returns an error message if the string is not of a "number"', () => {
expect('Mother'.toCurrency()).to.deep.equal('This is not a Number');
expect('Andela'.toCurrency()).to.deep.equal('This is not a Number');
});
Expand All @@ -87,15 +92,17 @@ describe('String Class', () => {
});

describe('inverseCase', () => {
it('returns each letter in the string as an inverse of its current case', () => {
it(`returns each letter in the string as an inverse of
its current case`, () => {
expect('Mr. Ben'.inverseCase()).to.equal('mR. bEN');
expect('Good Morning'.inverseCase()).to.equal('gOOD mORNING');
expect('john'.inverseCase()).to.equal('JOHN');
});
});

describe('alternatingCase', () => {
it('returns the letters in alternating cases. It must start with a lower case', () => {
it(`returns the letters in alternating cases.
It must start with a lower case`, () => {
expect('Onomatopoeia'.alternatingCase()).to.equal('oNoMaToPoEiA');
expect('blessing'.alternatingCase()).to.equal('bLeSsInG');
});
Expand Down Expand Up @@ -132,12 +139,14 @@ describe('String Class', () => {
});

describe('doubleCheck', () => {
it('returns true if a string contains double characters(including whitespace character)', () => {
it(`returns true if a string contains double characters
(including whitespace character)`, () => {
expect('egg Head'.doubleCheck()).to.be.true;
expect('greed'.doubleCheck()).to.be.true;
expect('cool Aid'.doubleCheck()).to.be.true;
});
it('returns false if a string does not contains double characters(including whitespace character)', () => {
it(`returns false if a string does not contains double
characters(including whitespace character)`, () => {
expect('bread'.doubleCheck()).to.be.false;
expect('dragon'.doubleCheck()).to.be.false;
});
Expand Down

0 comments on commit b5d3f0b

Please sign in to comment.