This implementation extends the functionality of the String
class by adding more utility methods.
The tests are run using jasmine
on the command line
To run the tests, use the following steps:
-
Clone the repo locally and navigate to the newly created folder
$ git clone [email protected]:andela-ekupara/StringClass.git
$ cd StringClass
-
Open the
index.html
file in your browser to see the tests run.
This library consist of nine custom methods:
hasVowels()
toUpper()
toLower()
isQuestion()
words()
wordCount()
toCurrency()
fromCurrency
-
Method
hasVowels()
This method can be used to check if a string contains vowels. It will return a boolean datatype of
true
if vowels exist andfalse
if they don't."edwin".hasVowels(); // returns true "hymn".hasVowels(); // returns false
-
Method
toUpper()
Calling this method on a string returns the string, but with all characters in uppercase as applicable
"edwin".toUpper(); // returns "EDWIN"
-
Method
toLower()
Calling this method on a string returns the string, but with all characters in lowercase as applicable
var myVar = "WE ALL LOVE JAVASCRIPT"; myVar.toLower(); // returns "we all love javascript"
-
Method
ucFirst()
Calling this method on a string returns the string, but with the first character converted to uppercase.
var sentence = "welcome to the Dojo"; sentence.ucFirst(); // returns "Welcome to the Dojo"
-
Method
isQuestion()
This method returns
true
if the string is a question andfalse
otherwisevar questioon = "Is this a question?", answer = "yes it is."; question.isQuestion(); // returns true answer.isQuestion(); // returns false
-
Method
words()
This method returns the all the words in sentence in form of an array e.g
['me', 'and', 'myself']
var sentence = "me and myself"; sentence.words(); // returns ['me', 'and', 'myself']
-
Method
WordCount()
This method returns the number of words words in a sentence.
It utilizes the methodwords
abovevar sentence = "me, myself and I"; sentence.wordCount(); // returns 4
-
Method
toCurrency()
This method can be used to format a string to currency.
var money = "234456789.123" money.toCurrency(); // returns 234,456,789.123
-
Method
fromCurrency()
This method can be used to convert a currency format back to nummber. Its return type is a number.
var currency = "12,345,678.12"; currency.fromCurrency(); // returns 12345678.12