Skip to content
This repository has been archived by the owner on Feb 2, 2022. It is now read-only.

Commit

Permalink
Merge pull request #6 from vindecodex/v1.0.x
Browse files Browse the repository at this point in the history
V1.0.x
  • Loading branch information
vindecodex committed Jul 18, 2020
2 parents f5a6c47 + 0ed8ec0 commit 2ceb9e2
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 20 deletions.
26 changes: 20 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ countWords("Hello World");

Count Characters
```JavaScript
const { countCharacters } require('counting-str');
const { countCharacters } = require('counting-str');
countCharacters("Hello World");
```

Expand All @@ -32,11 +32,25 @@ Count Characters without including spaces
countCharacters("Hello World", { withSpaces: false });
```

|Name | Arguments | Info |
|---------------|-------------------------------|---------------------------------------------------------|
|countWords | String | returns # of words in a string |
|countSpaces | String | returns # of spaces in a string |
|countCharacters| Object { withSpaces: boolean }| withSpaces: true returns # of characters included space |
Count Vowels
```JavaScript
const { countVowels } = require('counting-str');
countVowels("Hello World");
```

Count Spaces
```JavaScript
const { countSpaces } = require('counting-str');
countSpaces("Hello World");
```

|Name | Arguments | Info |
|----------------|-------------------------------|---------------------------------------------------------|
|countWords | String | returns # of words in a string
|countSpaces | String | returns # of spaces in a string
|countCharacters | Object { withSpaces: boolean }| withSpaces: true returns # of characters included space
|countVowels | String | returns # of vowels in a string
|countSpaces | String | returns # of spaces in a string


#### Feel free to open a pull request to add more features.
Expand Down
19 changes: 8 additions & 11 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
"use strict";
exports.__esModule = true;
exports.countCharacters = exports.countSpaces = exports.countWords = exports.countingStr = void 0;
exports.countingStr = {
byWordsLength: 0,
bySpacesLength: 0,
countWords: function (inputString) {
return 0;
},
countSpaces: function (inputString) {
return 0;
}
};
exports.countVowels = exports.countCharacters = exports.countSpaces = exports.countWords = void 0;
function countWords(inputString) {
if (!inputString)
return 0;
Expand All @@ -26,6 +16,7 @@ function countSpaces(inputString) {
}
exports.countSpaces = countSpaces;
function countCharacters(inputString, options) {
if (options === void 0) { options = { withSpaces: true }; }
if (!inputString)
return 0;
var inputCharacterSize = inputString.length;
Expand All @@ -36,3 +27,9 @@ function countCharacters(inputString, options) {
return inputCharacterSizeWithoutSpaces;
}
exports.countCharacters = countCharacters;
function countVowels(inputString) {
if (!inputString)
return 0;
return (inputString.match(/[aeiou]/gi) || []).length;
}
exports.countVowels = countVowels;
6 changes: 5 additions & 1 deletion index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,15 @@ export function countSpaces(inputString: string) {
let splitWords = inputString.split(" ");
return splitWords.length - 1;
}
export function countCharacters(inputString: string, options: CountCharactersOption) {
export function countCharacters(inputString: string, options: CountCharactersOption = { withSpaces: true }) {
if (!inputString) return 0;
let inputCharacterSize = inputString.length;
let inputSpaceCharacterSize = inputString.split(" ").length - 1;
let inputCharacterSizeWithoutSpaces = inputCharacterSize - inputSpaceCharacterSize;
if (options.withSpaces) return inputCharacterSize;
return inputCharacterSizeWithoutSpaces;
}
export function countVowels(inputString: string) {
if (!inputString) return 0;
return (inputString.match(/[aeiou]/gi) || []).length;
}
10 changes: 8 additions & 2 deletions test/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ const {
countWords,
countSpaces,
countCharacters,
countVowels
} = require('../index.js');


const input = "Hello, World!, This is a test";

describe(`Input: ${input}`, null);
Expand All @@ -24,7 +24,7 @@ describe('Count Spaces', function() {

describe('Count Characters with spaces', function() {
it('Should return 29', function() {
assert.equal(countCharacters(input, { withSpaces: true }), 29);
assert.equal(countCharacters(input), 29);
});
});

Expand All @@ -33,3 +33,9 @@ describe('Count Characters without spaces', function() {
assert.equal(countCharacters(input, { withSpaces: false}), 24);
});
});

describe('Count Vowels', function () {
it('Should return 7', function () {
assert.equal(countVowels(input), 7);
});
});

0 comments on commit 2ceb9e2

Please sign in to comment.