diff --git a/.babelrc b/.babelrc index 3cc3bb2..a1d3b7a 100644 --- a/.babelrc +++ b/.babelrc @@ -1,8 +1,8 @@ { "plugins": [ + "add-module-exports", "transform-object-assign", "transform-es2015-block-scoping", - "add-module-exports", "transform-es2015-modules-commonjs", "transform-es2015-parameters", "transform-es2015-shorthand-properties", diff --git a/.github/CONTRIBUTING.md b/.github/CONTRIBUTING.md index ec3f3ca..2a4ae81 100644 --- a/.github/CONTRIBUTING.md +++ b/.github/CONTRIBUTING.md @@ -24,7 +24,7 @@ brings and possible use cases. ### Creating pull requests Pull requests are great :+1:. -When contributing to this repository, please **first discuss the change** you wish to make via issue, email to [dmitri@rainsoft.io](email), +When contributing to this repository, please **first discuss the change** you wish to make via issue, email to [dmitri@rainsoft.io][email], or any other method with the owners of this repository before making a change. When submitting the request please be sure: diff --git a/package.json b/package.json index ca0cd91..b5ca481 100644 --- a/package.json +++ b/package.json @@ -66,7 +66,7 @@ "babel-root-import": "4.1.5", "chai": "3.5.0", "codecov.io": "0.1.6", - "eslint": "3.12.2", + "eslint": "3.13.0", "glob": "7.1.1", "grunt": "1.0.1", "grunt-contrib-connect": "1.0.2", @@ -76,10 +76,10 @@ "jsdoc": "3.4.3", "mkdirp": "0.5.1", "mocha": "3.2.0", - "rollup": "0.38.0", + "rollup": "0.41.1", "rollup-plugin-babel": "2.7.1", "rollup-plugin-uglify": "1.0.1", "source-map-support": "0.4.8" }, "dependencies": {} -} \ No newline at end of file +} diff --git a/src/case/title_case.js b/src/case/title_case.js index dfc107e..803729a 100644 --- a/src/case/title_case.js +++ b/src/case/title_case.js @@ -1,23 +1,31 @@ +import { REGEXP_EXTENDED_ASCII, REGEXP_LATIN_WORD, REGEXP_WORD } from 'helper/reg_exp/const_extended'; +import capitalize from 'case/capitalize'; +import coerceToString from 'helper/string/coerce_to_string'; + /** * Converts the subject to title case. * - * @function snakeCase + * @function titleCase * @static - * @since 1.0.0 + * @since 1.1.0 * @memberOf Case * @param {string} [subject=''] The string to convert to title case. - * @param {string} [ignoreWords] The list of words that should not be changed. - * @return {string} Returns the title case string. + * @param {Array} [ignoreWords] The words that should not be capitalized. + * @return {string} Returns the title cased string. * @example - * v.snakeCase('learning to fly'); - * // => 'learning_to_fly' + * v.titleCase('learning to fly'); + * // => 'Learning To Fly' * - * v.snakeCase('LearningToFly'); - * // => 'learning_to_fly' + * v.titleCase('another brick in the wall', ['in', 'the']); + * // => 'Another Brick in the Wall' * - * v.snakeCase('-Learning-To-Fly-'); - * // => 'learning_to_fly' */ -export default function titleCase(subject) { - return subject; +export default function titleCase(subject, ignoreWords) { + const subjectString = coerceToString(subject); + const ignoreWordsArray = Array.isArray(ignoreWords) ? ignoreWords : []; + const wordsRegExp = REGEXP_EXTENDED_ASCII.test(subjectString) ? REGEXP_LATIN_WORD : REGEXP_WORD; + return subjectString.replace(wordsRegExp, function(word) { + const lowerCaseWord = word.toLowerCase(); + return ignoreWordsArray.indexOf(lowerCaseWord) !== -1 ? lowerCaseWord : capitalize(lowerCaseWord, true); + }); } \ No newline at end of file diff --git a/src/functions.js b/src/functions.js index d27ddc4..61dc41e 100644 --- a/src/functions.js +++ b/src/functions.js @@ -11,6 +11,7 @@ import kebabCase from './case/kebab_case'; import lowerCase from './case/lower_case'; import snakeCase from './case/snake_case'; import upperCase from './case/upper_case'; +import titleCase from './case/title_case'; import truncate from './chop/truncate'; /** @@ -134,6 +135,7 @@ export default { kebabCase, lowerCase, snakeCase, + titleCase, upperCase, count, diff --git a/test/case/snake_case.js b/test/case/snake_case.js index 55db97e..535f110 100644 --- a/test/case/snake_case.js +++ b/test/case/snake_case.js @@ -18,7 +18,6 @@ describe('snakeCase', function() { expect(v.snakeCase('/home/dmitri/projects/voca')).to.be.equal('home_dmitri_projects_voca'); expect(v.snakeCase(PRINTABLE_ASCII)).to.be.equal('0123456789_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz'); expect(v.snakeCase('****')).to.be.equal(''); - expect(v.snakeCase('****')).to.be.equal(''); expect(v.snakeCase('-----')).to.be.equal(''); expect(v.snakeCase(' ')).to.be.equal(''); expect(v.snakeCase('\n\n\n\n ***\t\t')).to.be.equal(''); diff --git a/test/case/title_case.js b/test/case/title_case.js new file mode 100644 index 0000000..c3b00cb --- /dev/null +++ b/test/case/title_case.js @@ -0,0 +1,67 @@ +import { expect } from 'chai'; +import v from '../voca'; + +describe('titleCase', function() { + + it('should return the title case of a string', function() { + expect(v.titleCase('hello world')).to.be.equal('Hello World'); + expect(v.titleCase('Hello world')).to.be.equal('Hello World'); + expect(v.titleCase('hello World')).to.be.equal('Hello World'); + expect(v.titleCase('Hello World')).to.be.equal('Hello World'); + expect(v.titleCase('HELLO WORLD')).to.be.equal('Hello World'); + expect(v.titleCase('bird')).to.be.equal('Bird'); + expect(v.titleCase('BIRD')).to.be.equal('Bird'); + expect(v.titleCase('bird-flight')).to.be.equal('Bird-Flight'); + expect(v.titleCase('bird flight')).to.be.equal('Bird Flight'); + expect(v.titleCase('san diego zoo safari park')).to.be.equal('San Diego Zoo Safari Park'); + expect(v.titleCase('Who wants to try next?')).to.be.equal('Who Wants To Try Next?'); + expect(v.titleCase('WHO WANTS TO TRY NEXT?')).to.be.equal('Who Wants To Try Next?'); + expect(v.titleCase('-BIRD-FLIGHT-')).to.be.equal('-Bird-Flight-'); + expect(v.titleCase('__BIRD___FLIGHT___')).to.be.equal('__Bird___Flight___'); + expect(v.titleCase('Restless flycatcher')).to.be.equal('Restless Flycatcher'); + expect(v.titleCase('XMLHttpRequest')).to.be.equal('XmlHttpRequest'); + expect(v.titleCase('weight of up to 12 kg')).to.be.equal('Weight Of Up To 12 Kg'); + expect(v.titleCase('/home/dmitri/projects/voca')).to.be.equal('/Home/Dmitri/Projects/Voca'); + expect(v.titleCase('****')).to.be.equal('****'); + expect(v.titleCase('-----')).to.be.equal('-----'); + expect(v.titleCase(' ')).to.be.equal(' '); + expect(v.titleCase('\n\n\n\n ***\t\t')).to.be.equal('\n\n\n\n ***\t\t'); + expect(v.titleCase('')).to.be.equal(''); + }); + + it('should return the title case of a non-latin string', function() { + expect(v.titleCase('zborul păsării')).to.be.equal('Zborul Păsării'); + expect(v.titleCase('полет птицы')).to.be.equal('Полет Птицы'); + expect(v.titleCase('fuerza de sustentación')).to.be.equal('Fuerza De Sustentación'); + expect(v.titleCase('skrzydło ptaka składa się')).to.be.equal('Skrzydło Ptaka Składa Się'); + }); + + it('should return the title case and not capitalize specific words', function() { + expect(v.titleCase('Who wants to try next?', ['to'])).to.be.equal('Who Wants to Try Next?'); + expect(v.titleCase('WHO WANTS TO TRY NEXT?', ['to'])).to.be.equal('Who Wants to Try Next?'); + expect(v.titleCase('Well, congratulations! You got yourself caught! Now what\'s the next step in your master plan?', ["s", 'the', 'in'])) + .to.be.equal('Well, Congratulations! You Got Yourself Caught! Now What\'s the Next Step in Your Master Plan?'); + }); + + it('should not modify numbers', function() { + expect(v.titleCase(0)).to.be.equal('0'); + expect(v.titleCase(1200)).to.be.equal('1200'); + expect(v.titleCase('8965')).to.be.equal('8965'); + }); + + it('should return the title case of a string representation of an object', function() { + expect(v.titleCase(['bird flight'])).to.be.equal('Bird Flight'); + expect(v.titleCase({ + toString: function() { + return 'bird flight'; + } + })).to.be.equal('Bird Flight'); + }); + + it('should return empty string for null or undefined', function() { + expect(v.titleCase()).to.be.equal(''); + expect(v.titleCase(undefined)).to.be.equal(''); + expect(v.titleCase(null)).to.be.equal(''); + }); + +}); \ No newline at end of file diff --git a/test/index.js b/test/index.js index a367a53..4d0b2ba 100644 --- a/test/index.js +++ b/test/index.js @@ -5,6 +5,7 @@ import './case/decapitalize'; import './case/kebab_case'; import './case/lower_case'; import './case/snake_case'; +import './case/title_case'; import './case/upper_case'; //chain diff --git a/test/modules_common.js b/test/modules_common.js index 9c33ab6..0fec397 100644 --- a/test/modules_common.js +++ b/test/modules_common.js @@ -34,6 +34,12 @@ describe('CommonJS modules', function() { expect(snakeCase('-BIRD-FLIGHT-')).to.be.equal('bird_flight'); }); + it('should require titleCase()', function() { + const titleCase = require('../dist_mod/title_case'); + expect(titleCase('BIRD FLIGHT')).to.be.equal('Bird Flight'); + }); + + it('should require upperCase()', function() { const upperCase = require('../dist_mod/upper_case'); expect(upperCase('Earth')).to.be.equal('EARTH'); diff --git a/test/modules_es2015.js b/test/modules_es2015.js index 5fa62e1..e8f1ce8 100644 --- a/test/modules_es2015.js +++ b/test/modules_es2015.js @@ -8,6 +8,7 @@ import capitalize from '../dist_mod/capitalize'; import decapitalize from '../dist_mod/decapitalize'; import kebabCase from '../dist_mod/kebab_case'; import lowerCase from '../dist_mod/lower_case'; +import titleCase from '../dist_mod/title_case'; import snakeCase from '../dist_mod/snake_case'; // Chop @@ -132,6 +133,10 @@ describe('CommonJS modules', function() { expect(snakeCase('-BIRD-FLIGHT-')).to.be.equal('bird_flight'); }); + it('should require titleCase()', function() { + expect(titleCase('BIRD FLIGHT')).to.be.equal('Bird Flight'); + }); + it('should require upperCase()', function() { expect(upperCase('Earth')).to.be.equal('EARTH'); }); diff --git a/test_runner/test_bundle.js b/test_runner/test_bundle.js index 155398b..ec3190a 100644 --- a/test_runner/test_bundle.js +++ b/test_runner/test_bundle.js @@ -606,6 +606,34 @@ function upperCase(subject) { return subjectString.toUpperCase(); } +/** + * Converts the subject to title case. + * + * @function titleCase + * @static + * @since 1.1.0 + * @memberOf Case + * @param {string} [subject=''] The string to convert to title case. + * @param {Array} [ignoreWords] The words that should not be capitalized. + * @return {string} Returns the title cased string. + * @example + * v.titleCase('learning to fly'); + * // => 'Learning To Fly' + * + * v.titleCase('another brick in the wall', ['in', 'the']); + * // => 'Another Brick in the Wall' + * + */ +function titleCase(subject, ignoreWords) { + var subjectString = coerceToString(subject); + var ignoreWordsArray = Array.isArray(ignoreWords) ? ignoreWords : []; + var wordsRegExp = REGEXP_EXTENDED_ASCII.test(subjectString) ? REGEXP_LATIN_WORD : REGEXP_WORD; + return subjectString.replace(wordsRegExp, function (word) { + var lowerCaseWord = word.toLowerCase(); + return ignoreWordsArray.indexOf(lowerCaseWord) !== -1 ? lowerCaseWord : capitalize(lowerCaseWord, true); + }); +} + /** * Clip the number to interval `downLimit` to `upLimit`. * @@ -2584,6 +2612,8 @@ function splice(subject, start, deleteCount, toAdd) { return subjectString.slice(0, startPosition) + toAddString + subjectString.slice(startPosition + deleteCountNumber); } +var reduce$1 = Array.prototype.reduce; + /** * Removes whitespaces from the left side of the `subject`. * @@ -2592,7 +2622,7 @@ function splice(subject, start, deleteCount, toAdd) { * @since 1.0.0 * @memberOf Manipulate * @param {string} [subject=''] The string to trim. - * @param {string} [whitespace=whitespace] The whitespace characters to trim. + * @param {string} [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped. * @return {string} Returns the trimmed string. * @example * v.trimLeft(' Starship Troopers'); @@ -2610,19 +2640,18 @@ function trimLeft(subject, whitespace$$1) { if (isNil(whitespaceString)) { return subjectString.replace(REGEXP_TRIM_LEFT, ''); } - var whitespaceLength = whitespaceString.length; var matchWhitespace = true; - var totalWhitespaceLength = 0; - while (matchWhitespace) { - if (subjectString.indexOf(whitespaceString, totalWhitespaceLength) === totalWhitespaceLength) { - totalWhitespaceLength += whitespaceLength; - } else { - matchWhitespace = false; + return reduce$1.call(subjectString, function (trimmed, character) { + if (matchWhitespace && includes(whitespaceString, character)) { + return trimmed; } - } - return subjectString.substring(totalWhitespaceLength); + matchWhitespace = false; + return trimmed + character; + }, ''); } +var reduceRight = Array.prototype.reduceRight; + /** * Removes whitespaces from the right side of the `subject`. * @@ -2631,7 +2660,7 @@ function trimLeft(subject, whitespace$$1) { * @since 1.0.0 * @memberOf Manipulate * @param {string} [subject=''] The string to trim. - * @param {string} [whitespace=whitespace] The whitespace characters to trim. + * @param {string} [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped. * @return {string} Returns the trimmed string. * @example * v.trimRight('the fire rises '); @@ -2649,20 +2678,14 @@ function trimRight(subject, whitespace$$1) { if (isNil(whitespaceString)) { return subjectString.replace(REGEXP_TRIM_RIGHT, ''); } - var whitespaceLength = whitespaceString.length; - var subjectLength = subjectString.length; var matchWhitespace = true; - var totalWhitespaceLength = 0; - var position = void 0; - while (matchWhitespace) { - position = subjectLength - totalWhitespaceLength - whitespaceLength; - if (subjectString.indexOf(whitespaceString, position) === position) { - totalWhitespaceLength += whitespaceLength; - } else { - matchWhitespace = false; + return reduceRight.call(subjectString, function (trimmed, character) { + if (matchWhitespace && includes(whitespaceString, character)) { + return trimmed; } - } - return subjectString.substring(0, subjectLength - totalWhitespaceLength); + matchWhitespace = false; + return character + trimmed; + }, ''); } /** @@ -2673,7 +2696,7 @@ function trimRight(subject, whitespace$$1) { * @since 1.0.0 * @memberOf Manipulate * @param {string} [subject=''] The string to trim. - * @param {string} [whitespace=whitespace] The whitespace characters to trim. + * @param {string} [whitespace=whitespace] The whitespace characters to trim. List all characters that you want to be stripped. * @return {string} Returns the trimmed string. * @example * v.trim(' Mother nature '); @@ -3424,7 +3447,6 @@ function trim$1(subject, allowableTags, replacement) { } } } - return output; } @@ -3543,6 +3565,7 @@ var functions = { kebabCase: kebabCase, lowerCase: lowerCase, snakeCase: snakeCase, + titleCase: titleCase, upperCase: upperCase, count: count, @@ -4051,7 +4074,6 @@ describe('snakeCase', function () { chai.expect(Voca.snakeCase('/home/dmitri/projects/voca')).to.be.equal('home_dmitri_projects_voca'); chai.expect(Voca.snakeCase(PRINTABLE_ASCII)).to.be.equal('0123456789_abcdefghijklmnopqrstuvwxyz_abcdefghijklmnopqrstuvwxyz'); chai.expect(Voca.snakeCase('****')).to.be.equal(''); - chai.expect(Voca.snakeCase('****')).to.be.equal(''); chai.expect(Voca.snakeCase('-----')).to.be.equal(''); chai.expect(Voca.snakeCase(' ')).to.be.equal(''); chai.expect(Voca.snakeCase('\n\n\n\n ***\t\t')).to.be.equal(''); @@ -4087,6 +4109,69 @@ describe('snakeCase', function () { }); }); +describe('titleCase', function () { + + it('should return the title case of a string', function () { + chai.expect(Voca.titleCase('hello world')).to.be.equal('Hello World'); + chai.expect(Voca.titleCase('Hello world')).to.be.equal('Hello World'); + chai.expect(Voca.titleCase('hello World')).to.be.equal('Hello World'); + chai.expect(Voca.titleCase('Hello World')).to.be.equal('Hello World'); + chai.expect(Voca.titleCase('HELLO WORLD')).to.be.equal('Hello World'); + chai.expect(Voca.titleCase('bird')).to.be.equal('Bird'); + chai.expect(Voca.titleCase('BIRD')).to.be.equal('Bird'); + chai.expect(Voca.titleCase('bird-flight')).to.be.equal('Bird-Flight'); + chai.expect(Voca.titleCase('bird flight')).to.be.equal('Bird Flight'); + chai.expect(Voca.titleCase('san diego zoo safari park')).to.be.equal('San Diego Zoo Safari Park'); + chai.expect(Voca.titleCase('Who wants to try next?')).to.be.equal('Who Wants To Try Next?'); + chai.expect(Voca.titleCase('WHO WANTS TO TRY NEXT?')).to.be.equal('Who Wants To Try Next?'); + chai.expect(Voca.titleCase('-BIRD-FLIGHT-')).to.be.equal('-Bird-Flight-'); + chai.expect(Voca.titleCase('__BIRD___FLIGHT___')).to.be.equal('__Bird___Flight___'); + chai.expect(Voca.titleCase('Restless flycatcher')).to.be.equal('Restless Flycatcher'); + chai.expect(Voca.titleCase('XMLHttpRequest')).to.be.equal('XmlHttpRequest'); + chai.expect(Voca.titleCase('weight of up to 12 kg')).to.be.equal('Weight Of Up To 12 Kg'); + chai.expect(Voca.titleCase('/home/dmitri/projects/voca')).to.be.equal('/Home/Dmitri/Projects/Voca'); + chai.expect(Voca.titleCase('****')).to.be.equal('****'); + chai.expect(Voca.titleCase('-----')).to.be.equal('-----'); + chai.expect(Voca.titleCase(' ')).to.be.equal(' '); + chai.expect(Voca.titleCase('\n\n\n\n ***\t\t')).to.be.equal('\n\n\n\n ***\t\t'); + chai.expect(Voca.titleCase('')).to.be.equal(''); + }); + + it('should return the title case of a non-latin string', function () { + chai.expect(Voca.titleCase('zborul păsării')).to.be.equal('Zborul Păsării'); + chai.expect(Voca.titleCase('полет птицы')).to.be.equal('Полет Птицы'); + chai.expect(Voca.titleCase('fuerza de sustentación')).to.be.equal('Fuerza De Sustentación'); + chai.expect(Voca.titleCase('skrzydło ptaka składa się')).to.be.equal('Skrzydło Ptaka Składa Się'); + }); + + it('should return the title case and not capitalize specific words', function () { + chai.expect(Voca.titleCase('Who wants to try next?', ['to'])).to.be.equal('Who Wants to Try Next?'); + chai.expect(Voca.titleCase('WHO WANTS TO TRY NEXT?', ['to'])).to.be.equal('Who Wants to Try Next?'); + chai.expect(Voca.titleCase('Well, congratulations! You got yourself caught! Now what\'s the next step in your master plan?', ["s", 'the', 'in'])).to.be.equal('Well, Congratulations! You Got Yourself Caught! Now What\'s the Next Step in Your Master Plan?'); + }); + + it('should not modify numbers', function () { + chai.expect(Voca.titleCase(0)).to.be.equal('0'); + chai.expect(Voca.titleCase(1200)).to.be.equal('1200'); + chai.expect(Voca.titleCase('8965')).to.be.equal('8965'); + }); + + it('should return the title case of a string representation of an object', function () { + chai.expect(Voca.titleCase(['bird flight'])).to.be.equal('Bird Flight'); + chai.expect(Voca.titleCase({ + toString: function () { + return 'bird flight'; + } + })).to.be.equal('Bird Flight'); + }); + + it('should return empty string for null or undefined', function () { + chai.expect(Voca.titleCase()).to.be.equal(''); + chai.expect(Voca.titleCase(undefined)).to.be.equal(''); + chai.expect(Voca.titleCase(null)).to.be.equal(''); + }); +}); + describe('upperCase', function () { it('should return the upper case of a string', function () { @@ -5870,8 +5955,8 @@ describe('trim', function () { chai.expect(Voca.trim('---Do-you-*feel*-in-charge?---', '-')).to.be.equal('Do-you-*feel*-in-charge?'); chai.expect(Voca.trim('Do you *feel* in charge?___', '_')).to.be.equal('Do you *feel* in charge?'); chai.expect(Voca.trim('<-Do you *feel* in charge?', '<-')).to.be.equal('Do you *feel* in charge?'); - chai.expect(Voca.trim('***Do you *feel* in charge?***', '**')).to.be.equal('*Do you *feel* in charge?*'); - chai.expect(Voca.trim('Do you *feel* in charge?', 'Do you *feel* in charge?')).to.be.equal(''); + chai.expect(Voca.trim('***Do you *feel* in charge?***', '*-')).to.be.equal('Do you *feel* in charge?'); + chai.expect(Voca.trim('Do you *feel* in charge?', 'Doe?')).to.be.equal(' you *feel* in charg'); chai.expect(Voca.trim('\n\nDo you *feel* in charge?', '\n')).to.be.equal('Do you *feel* in charge?'); }); @@ -5893,7 +5978,7 @@ describe('trim', function () { it('should return the trimmed string for numbers', function () { chai.expect(Voca.trim(100, 1)).to.be.equal('00'); chai.expect(Voca.trim(6780, 6780)).to.be.equal(''); - chai.expect(Voca.trim(-115, -1)).to.be.equal('15'); + chai.expect(Voca.trim(-115, -1)).to.be.equal('5'); chai.expect(Voca.trim(1111, 1)).to.be.equal(''); chai.expect(Voca.trim(8998, 8)).to.be.equal('99'); }); @@ -5927,8 +6012,8 @@ describe('trimLeft', function () { chai.expect(Voca.trimLeft('Do you *feel* in charge?___', '_')).to.be.equal('Do you *feel* in charge?___'); chai.expect(Voca.trimLeft('___Do you *feel* in charge?', '_')).to.be.equal('Do you *feel* in charge?'); chai.expect(Voca.trimLeft('<-Do you *feel* in charge?', '<-')).to.be.equal('Do you *feel* in charge?'); - chai.expect(Voca.trimLeft('***Do you *feel* in charge?***', '**')).to.be.equal('*Do you *feel* in charge?***'); - chai.expect(Voca.trimLeft('Do you *feel* in charge?', 'Do you *feel* in charge?')).to.be.equal(''); + chai.expect(Voca.trimLeft('***Do you *feel* in charge?***', '*')).to.be.equal('Do you *feel* in charge?***'); + chai.expect(Voca.trimLeft('Do you *feel* in charge?', 'Doy')).to.be.equal(' you *feel* in charge?'); chai.expect(Voca.trimLeft('\n\nDo you *feel* in charge?', '\n')).to.be.equal('Do you *feel* in charge?'); }); @@ -5950,7 +6035,7 @@ describe('trimLeft', function () { it('should return the left trimmed string for numbers', function () { chai.expect(Voca.trimLeft(100, 1)).to.be.equal('00'); chai.expect(Voca.trimLeft(6780, 6780)).to.be.equal(''); - chai.expect(Voca.trimLeft(-115, -1)).to.be.equal('15'); + chai.expect(Voca.trimLeft(-115, -1)).to.be.equal('5'); }); it('should return empty string for null or undefined', function () { @@ -5982,8 +6067,8 @@ describe('trimRight', function () { chai.expect(Voca.trimRight('___Do you *feel* in charge?', '_')).to.be.equal('___Do you *feel* in charge?'); chai.expect(Voca.trimRight('Do you *feel* in charge?___', '_')).to.be.equal('Do you *feel* in charge?'); chai.expect(Voca.trimRight('Do you *feel* in charge?<-', '<-')).to.be.equal('Do you *feel* in charge?'); - chai.expect(Voca.trimRight('***Do you *feel* in charge?***', '**')).to.be.equal('***Do you *feel* in charge?*'); - chai.expect(Voca.trimRight('Do you *feel* in charge?', 'Do you *feel* in charge?')).to.be.equal(''); + chai.expect(Voca.trimRight('***Do you *feel* in charge?***', '**')).to.be.equal('***Do you *feel* in charge?'); + chai.expect(Voca.trimRight('Do you *feel* in charge?', 'charge?')).to.be.equal('Do you *feel* in '); chai.expect(Voca.trimRight('Do you *feel* in charge?\n\n', '\n')).to.be.equal('Do you *feel* in charge?'); }); @@ -6005,7 +6090,7 @@ describe('trimRight', function () { it('should return the right trimmed string for numbers', function () { chai.expect(Voca.trimRight(100, 0)).to.be.equal('1'); chai.expect(Voca.trimRight(6780, 6780)).to.be.equal(''); - chai.expect(Voca.trimRight(-115, 15)).to.be.equal('-1'); + chai.expect(Voca.trimRight(-115, 15)).to.be.equal('-'); }); it('should return empty string for null or undefined', function () {