Skip to content

Commit

Permalink
sentencecase
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpilott committed Dec 27, 2020
1 parent 9d7532c commit f9ac114
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 6 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@neuekit/utilities",
"version": "1.7.1",
"version": "1.8.0",
"license": "MIT",
"description": "Tree-shakeable JavaScript utilities, add yours today!",
"main": "dist/bundle.js",
Expand All @@ -25,8 +25,8 @@
"@babel/core": "^7.12.3",
"@babel/preset-env": "^7.12.1",
"@rollup/plugin-babel": "^5.2.1",
"@rollup/plugin-commonjs": "^16.0.0",
"@rollup/plugin-node-resolve": "^10.0.0",
"@rollup/plugin-commonjs": "^17.0.0",
"@rollup/plugin-node-resolve": "^11.0.1",
"@rollup/plugin-replace": "^2.3.4",
"documentation": "^13.1.0",
"dotenv": "^8.2.0",
Expand Down
2 changes: 2 additions & 0 deletions src/vanilla/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import leadZero from './leadZero';
import netCheck from './netCheck';
import niceDate from './niceDate';
import niceTime from './niceTime';
import sentenceCase from './sentenceCase';
import titleCase from './titleCase';

/**
Expand All @@ -28,5 +29,6 @@ export {
netCheck,
niceDate,
niceTime,
sentenceCase,
titleCase,
};
15 changes: 15 additions & 0 deletions src/vanilla/sentenceCase.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/**
* Takes a string and converts it to sentence case
* @memberof Vanilla
* @version 1.0.0
* @param {string} str string to convert
* @returns {string} converted string
*/

export default function (str) {
str = str.toLowerCase();
str = str.replace(/(\n)|(\f)/g, ' ');
str = str.replace(/^.|(\. .)/g, char => char.toUpperCase());

return str;
}
4 changes: 1 addition & 3 deletions src/vanilla/titleCase.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@
*/

export default function (str) {
str = str.replace(/(^\w{1}|\.\s*\w{1})/gi, (toReplace) => {
return toReplace.toUpperCase();
});
str = str.replace(/(^\w{1}|\.\s*\w{1})/gi, char => char.toUpperCase());

return str;
}

0 comments on commit f9ac114

Please sign in to comment.