string-utilz
Advanced tools
Comparing version 1.3.0 to 1.4.0
@@ -21,5 +21,5 @@ /** | ||
describe('String Utilz (Integration)', function () { | ||
describe('TBD', function () { | ||
it('no integration tests needed yet', function () { | ||
describe('String Utilz (Integration)', () => { | ||
describe('TBD', () => { | ||
it('no integration tests needed yet', () => { | ||
expect(true).toBe(true); | ||
@@ -26,0 +26,0 @@ }); |
@@ -22,6 +22,6 @@ /** | ||
describe('String Utilz (Unit)', function () { | ||
describe('String Utilz (Unit)', () => { | ||
describe('#replace() => built-in', function () { | ||
it('should exist', function () { | ||
describe('#replace() => built-in', () => { | ||
it('should exist', () => { | ||
expect(typeof String.prototype.replace).toBe('function'); | ||
@@ -32,15 +32,34 @@ }); | ||
/** | ||
* check string#combineStr(tmpStr1, tmpStr2) | ||
*/ | ||
describe('#combineStr(tmpStr1, tmpStr)', () => { | ||
it('should return true when the string starts with the given value', () => { | ||
expect('Hello '.combineStr('Monday')).toBe('Hello Monday'); | ||
}); | ||
it('should be case sensitive', () => { | ||
expect('hello '.combineStr('Monday')).toBe('hello Monday'); | ||
}); | ||
it('should be able to handle spaces', () => { | ||
expect('Hello '.combineStr('Monday')).toBe('Hello Monday'); | ||
}); | ||
it('should be able to handle spaces', () => { | ||
expect('Hello '.combineStr(' Monday')).toBe('Hello Monday'); | ||
}); | ||
}); | ||
/** | ||
* Check string#startsWith(val); | ||
*/ | ||
describe('#startsWith(str)', function () { | ||
it('should return true when the string starts with the given value', function () { | ||
describe('#startsWith(str)', () => { | ||
it('should return true when the string starts with the given value', () => { | ||
expect('Bob'.startsWith('B')).toBe(true); | ||
}); | ||
it('should be case sensitive', function () { | ||
it('should be case sensitive', () => { | ||
expect('Bob'.startsWith('b')).toBe(false); | ||
}); | ||
it('should respect many characters', function () { | ||
it('should respect many characters', () => { | ||
expect('Franklin'.startsWith('Frank')).toBe(true); | ||
}); | ||
it('should be able to handle spaces', function () { | ||
it('should be able to handle spaces', () => { | ||
expect('The quick brown fox'.startsWith('The quick')).toBe(true); | ||
@@ -53,4 +72,4 @@ }); | ||
*/ | ||
describe('stringz#startsWith(tmpStr, matchStr)', function () { | ||
it('should return true when the string starts with the given value', function () { | ||
describe('stringz#startsWith(tmpStr, matchStr)', () => { | ||
it('should return true when the string starts with the given value', () => { | ||
expect(stringz.startsWith('Bob', 'B')).toBe(true); | ||
@@ -63,13 +82,13 @@ }); | ||
*/ | ||
describe('#endsWith(str)', function () { | ||
it('should return true when the string ends with the given value', function () { | ||
describe('#endsWith(str)', () => { | ||
it('should return true when the string ends with the given value', () => { | ||
expect('Bob'.endsWith('b')).toBe(true); | ||
}); | ||
it('should be case sensitive', function () { | ||
it('should be case sensitive', () => { | ||
expect('Bob'.endsWith('B')).toBe(false); | ||
}); | ||
it('should respect many characters', function () { | ||
it('should respect many characters', () => { | ||
expect('Franklin'.endsWith('lin')).toBe(true); | ||
}); | ||
it('should be able to handle spaces', function () { | ||
it('should be able to handle spaces', () => { | ||
expect('The quick brown fox'.endsWith('brown fox')).toBe(true); | ||
@@ -82,4 +101,4 @@ }); | ||
*/ | ||
describe('stringz#endsWith(tmpStr, matchStr)', function () { | ||
it('should return true when the string ends with the given value', function () { | ||
describe('stringz#endsWith(tmpStr, matchStr)', () => { | ||
it('should return true when the string ends with the given value', () => { | ||
expect(stringz.endsWith('Bob', 'b')).toBe(true); | ||
@@ -92,16 +111,16 @@ }); | ||
*/ | ||
describe('#containsIgnoreCase(str)', function () { | ||
it('should return true when the string contains the given value', function () { | ||
describe('#containsIgnoreCase(str)', () => { | ||
it('should return true when the string contains the given value', () => { | ||
expect('Bob'.containsIgnoreCase('b')).toBe(true); | ||
}); | ||
it('should be case insensitive', function () { | ||
it('should be case insensitive', () => { | ||
expect('BOB'.containsIgnoreCase('b')).toBe(true); | ||
}); | ||
it('should have no false positives', function () { | ||
it('should have no false positives', () => { | ||
expect('The quick brown'.containsIgnoreCase('x')).toBe(false); | ||
}); | ||
it('should respect many characters', function () { | ||
it('should respect many characters', () => { | ||
expect('Franklin'.containsIgnoreCase('ankl')).toBe(true); | ||
}); | ||
it('should be able to handle spaces', function () { | ||
it('should be able to handle spaces', () => { | ||
expect('The quick brown fox'.containsIgnoreCase('ck bro')).toBe(true); | ||
@@ -114,4 +133,4 @@ }); | ||
*/ | ||
describe('stringz#containsIgnoreCase(tmpStr, matchStr)', function () { | ||
it('should return true when the string contains the given value', function () { | ||
describe('stringz#containsIgnoreCase(tmpStr, matchStr)', () => { | ||
it('should return true when the string contains the given value', () => { | ||
expect(stringz.containsIgnoreCase('Bob', 'o')).toBe(true); | ||
@@ -124,22 +143,25 @@ }); | ||
*/ | ||
describe('#replaceAll(oldStr,newStr)', function () { | ||
it('should return the same string when the replace value does not match anything', function () { | ||
describe('#replaceAll(oldStr,newStr)', () => { | ||
it('should return the same string when the replace value does not match anything', () => { | ||
expect('The quick brown fox'.replaceAll('bob', 'frank')).toBe('The quick brown fox'); | ||
}); | ||
it('should replace one character', function () { | ||
it('should replace one character', () => { | ||
expect('Bob'.replaceAll('o', 'i')).toBe('Bib'); | ||
}); | ||
it('should replace all instances of a character', function () { | ||
it('should replace all instances of a character', () => { | ||
expect('Bobby'.replaceAll('b', 'd')).toBe('Boddy'); | ||
}); | ||
it('should be case sensitive', function () { | ||
it('should be case sensitive', () => { | ||
expect('Box'.replaceAll('b', 'd')).toBe('Box'); | ||
}); | ||
it('should respect spaces', function () { | ||
expect('Thequickbrownfox', 'The quick brown fox'.replaceAll(' ', '')).toBe('Thequickbrownfox'); | ||
it('should respect spaces', () => { | ||
expect('The quick brown fox'.replaceAll('\ ', '')).toBe('Thequickbrownfox'); | ||
}); | ||
it('should be able to change the first character', function () { | ||
it('should replace spaces', () => { | ||
expect('The quick brown fox'.replaceAll(' ', '_')).toBe('The_quick_brown_fox'); | ||
}); | ||
it('should be able to change the first character', () => { | ||
expect('mitten'.replaceAll('m', 'k')).toBe('kitten'); | ||
}); | ||
it('should respect words', function () { | ||
it('should respect words', () => { | ||
expect('baa baa black sheep'.replaceAll('baa', 'meow')).toBe('meow meow black sheep'); | ||
@@ -152,4 +174,4 @@ }); | ||
*/ | ||
describe('stringz#replaceAll(tmpStr, oldStr, newStr)', function () { | ||
it('should replace one character', function () { | ||
describe('stringz#replaceAll(tmpStr, oldStr, newStr)', () => { | ||
it('should replace one character', () => { | ||
expect(stringz.replaceAll('Bob', 'o', 'i')).toBe('Bib'); | ||
@@ -162,22 +184,25 @@ }); | ||
*/ | ||
describe('#replaceAll(oldStr,newStr)', function () { | ||
it('should return the same string when the replace value does not match anything', function () { | ||
describe('#replaceAll(oldStr,newStr)', () => { | ||
it('should return the same string when the replace value does not match anything', () => { | ||
expect('The quick brown fox'.replaceAllIgnoreCase('bob', 'frank')).toBe('The quick brown fox'); | ||
}); | ||
it('should replace one character', function () { | ||
it('should replace one character', () => { | ||
expect('Bob'.replaceAllIgnoreCase('o', 'i')).toBe('Bib'); | ||
}); | ||
it('should replace all instances of a character', function () { | ||
it('should replace all instances of a character', () => { | ||
expect('Bobby'.replaceAllIgnoreCase('b', 'd')).toBe('doddy'); | ||
}); | ||
it('should be case sensitive', function () { | ||
it('should be case sensitive', () => { | ||
expect('Box'.replaceAllIgnoreCase('b', 'd')).toBe('dox'); | ||
}); | ||
it('should respect spaces', function () { | ||
expect('Thequickbrownfox', 'The quick brown fox'.replaceAllIgnoreCase(' ', '')).toBe('Thequickbrownfox'); | ||
it('should respect spaces', () => { | ||
expect('The quick brown fox'.replaceAllIgnoreCase(' ', '')).toBe('Thequickbrownfox'); | ||
}); | ||
it('should be able to change the first character', function () { | ||
it('should replace spaces', () => { | ||
expect('The quick brown fox'.replaceAllIgnoreCase(' ', '_')).toBe('The_quick_brown_fox'); | ||
}); | ||
it('should be able to change the first character', () => { | ||
expect('mitten'.replaceAllIgnoreCase('m', 'k')).toBe('kitten'); | ||
}); | ||
it('should respect words', function () { | ||
it('should respect words', () => { | ||
expect('Baa baa black sheep'.replaceAllIgnoreCase('baa', 'meow')).toBe('meow meow black sheep'); | ||
@@ -190,4 +215,4 @@ }); | ||
*/ | ||
describe('stringz#replaceAllIgnoreCase(tmpStr, oldStr, newStr)', function () { | ||
it('should replace all instances of a character, regardless of case', function () { | ||
describe('stringz#replaceAllIgnoreCase(tmpStr, oldStr, newStr)', () => { | ||
it('should replace all instances of a character, regardless of case', () => { | ||
expect(stringz.replaceAllIgnoreCase('Bob', 'b', 'm')).toBe('mom'); | ||
@@ -200,49 +225,49 @@ }); | ||
*/ | ||
describe('#escapeRegEx() using indicies', function () { | ||
it('should escape -', function () { | ||
describe('#escapeRegEx() using indicies', () => { | ||
it('should escape -', () => { | ||
expect('-'.escapeRegEx()).toBe('\\-'); | ||
}); | ||
it('should escape [', function () { | ||
it('should escape [', () => { | ||
expect('['.escapeRegEx()).toBe('\\['); | ||
}); | ||
it('should escape ]', function () { | ||
it('should escape ]', () => { | ||
expect(']'.escapeRegEx()).toBe('\\]'); | ||
}); | ||
it('should escape /', function () { | ||
it('should escape /', () => { | ||
expect('/'.escapeRegEx()).toBe('\\/'); | ||
}); | ||
it('should escape {', function () { | ||
it('should escape {', () => { | ||
expect('{'.escapeRegEx()).toBe('\\{'); | ||
}); | ||
it('should escape }', function () { | ||
it('should escape }', () => { | ||
expect('}'.escapeRegEx()).toBe('\\}'); | ||
}); | ||
it('should escape (', function () { | ||
it('should escape (', () => { | ||
expect('('.escapeRegEx()).toBe('\\('); | ||
}); | ||
it('should escape )', function () { | ||
it('should escape )', () => { | ||
expect(')'.escapeRegEx()).toBe('\\)'); | ||
}); | ||
it('should escape *', function () { | ||
it('should escape *', () => { | ||
expect('*'.escapeRegEx()).toBe('\\*'); | ||
}); | ||
it('should escape +', function () { | ||
it('should escape +', () => { | ||
expect('+'.escapeRegEx()).toBe('\\+'); | ||
}); | ||
it('should escape ?', function () { | ||
it('should escape ?', () => { | ||
expect('?'.escapeRegEx()).toBe('\\?'); | ||
}); | ||
it('should escape .', function () { | ||
it('should escape .', () => { | ||
expect('.'.escapeRegEx()).toBe('\\.'); | ||
}); | ||
it('should escape \\ ', function () { | ||
it('should escape \\ ', () => { | ||
expect('\ '.escapeRegEx()).toBe(' '); | ||
}); | ||
it('should escape ^', function () { | ||
it('should escape ^', () => { | ||
expect('^'.escapeRegEx()).toBe('\\^'); | ||
}); | ||
it('should escape $', function () { | ||
it('should escape $', () => { | ||
expect('$'.escapeRegEx()).toBe('\\$'); | ||
}); | ||
it('should escape |', function () { | ||
it('should escape |', () => { | ||
expect('|'.escapeRegEx()).toBe('\\|'); | ||
@@ -255,4 +280,4 @@ }); | ||
*/ | ||
describe('stringz#escapeRegEx(tmpStr)', function () { | ||
it('should escape -', function () { | ||
describe('stringz#escapeRegEx(tmpStr)', () => { | ||
it('should escape -', () => { | ||
expect(stringz.escapeRegEx('-')).toBe('\\-'); | ||
@@ -265,19 +290,19 @@ }); | ||
*/ | ||
describe('#times(size)', function () { | ||
it('should return the string when multiplied by 1', function () { | ||
describe('#times(size)', () => { | ||
it('should return the string when multiplied by 1', () => { | ||
expect('*'.times(1)).toBe('*'); | ||
}); | ||
it('should return double the string when multiplied by 2', function () { | ||
it('should return double the string when multiplied by 2', () => { | ||
expect('*'.times(2)).toBe('**'); | ||
}); | ||
it('should return multiples of the string when multiplied', function () { | ||
it('should return multiples of the string when multiplied', () => { | ||
expect('*'.times(10)).toBe('**********'); | ||
}); | ||
it('should return multiples of a complex string', function () { | ||
it('should return multiples of a complex string', () => { | ||
expect('quick brown'.times(2)).toBe('quick brownquick brown'); | ||
}); | ||
it('should return null when multipled by 0', function () { | ||
it('should return null when multipled by 0', () => { | ||
expect('*'.times(0)).toBe(null); | ||
}); | ||
it('should return itself when multipled by a negative number', function () { | ||
it('should return itself when multipled by a negative number', () => { | ||
expect('*'.times(-2)).toBe('*'); | ||
@@ -290,4 +315,4 @@ }); | ||
*/ | ||
describe('stringz#times(tmpStr, size)', function () { | ||
it('should return the string when multiplied by 1', function () { | ||
describe('stringz#times(tmpStr, size)', () => { | ||
it('should return the string when multiplied by 1', () => { | ||
expect(stringz.times('*', 1)).toBe('*'); | ||
@@ -300,17 +325,17 @@ }); | ||
*/ | ||
describe('#pad(size, char)', function () { | ||
it('should use a space when no char is provided', function () { | ||
describe('#pad(size, char)', () => { | ||
it('should use a space when no char is provided', () => { | ||
expect('*'.pad(1)).toBe('* '); | ||
}); | ||
it('should return the given string when size is 0', function () { | ||
it('should return the given string when size is 0', () => { | ||
expect('*'.pad(0)).toBe('*'); | ||
expect('*'.pad(0, '-')).toBe('*'); | ||
}); | ||
it('should pad multiple times', function () { | ||
it('should pad multiple times', () => { | ||
expect('*'.pad(5, '-')).toBe('*-----'); | ||
}); | ||
it('should pad to the left when negative', function () { | ||
it('should pad to the left when negative', () => { | ||
expect('*'.pad(-5, '-')).toBe('-----*'); | ||
}); | ||
it('should handle multiple chars', function () { | ||
it('should handle multiple chars', () => { | ||
expect('*'.pad(-2, 'bob')).toBe('bobbob*'); | ||
@@ -325,4 +350,4 @@ expect('*'.pad(2, 'bob')).toBe('*bobbob'); | ||
*/ | ||
describe('stringz#pad(tmpStr, size, char)', function () { | ||
it('should return the string when multiplied by 1', function () { | ||
describe('stringz#pad(tmpStr, size, char)', () => { | ||
it('should return the string when multiplied by 1', () => { | ||
expect(stringz.pad('*', 1)).toBe('* '); | ||
@@ -335,14 +360,14 @@ }); | ||
*/ | ||
describe('#chop(size)', function () { | ||
it('should use a positive number to start at the end', function () { | ||
describe('#chop(size)', () => { | ||
it('should use a positive number to start at the end', () => { | ||
expect('testing'.chop(1)).toBe('testin'); | ||
}); | ||
it('should use a negative number to start at the beginning', function () { | ||
it('should use a negative number to start at the beginning', () => { | ||
expect('testing'.chop(-1)).toBe('esting'); | ||
}); | ||
it('should remove the required characters', function () { | ||
it('should remove the required characters', () => { | ||
expect('testing'.chop(3)).toBe('test'); | ||
expect('testing'.chop(-4)).toBe('ing'); | ||
}); | ||
it('should return null when size >= tmpStr.length', function () { | ||
it('should return null when size >= tmpStr.length', () => { | ||
expect('*'.chop(1)).toBe(null); | ||
@@ -357,4 +382,4 @@ expect('***'.chop(3)).toBe(null); | ||
*/ | ||
describe('stringz#chop(tmpStr, size)', function () { | ||
it('should be able to remove characters', function () { | ||
describe('stringz#chop(tmpStr, size)', () => { | ||
it('should be able to remove characters', () => { | ||
expect(stringz.chop('testing', 3)).toBe('test'); | ||
@@ -367,23 +392,23 @@ }); | ||
*/ | ||
describe('#fixSize(size, char)', function () { | ||
it('should return null when size = 0', function () { | ||
describe('#fixSize(size, char)', () => { | ||
it('should return null when size = 0', () => { | ||
expect('testing'.fixSize(0)).toBe(null); | ||
}); | ||
it('should use a space as a default char', function () { | ||
it('should use a space as a default char', () => { | ||
expect('testing'.fixSize(10)).toBe('testing '); | ||
}); | ||
it('should use a positive number to start at the end', function () { | ||
it('should use a positive number to start at the end', () => { | ||
expect('testing'.fixSize(4)).toBe('test'); | ||
expect('testing'.fixSize(10, '-')).toBe('testing---'); | ||
}); | ||
it('should use a negative number to start at the beginning', function () { | ||
it('should use a negative number to start at the beginning', () => { | ||
expect('testing'.fixSize(-3)).toBe('ing'); | ||
expect('testing'.fixSize(-10, '-')).toBe('---testing'); | ||
}); | ||
it('should be able to chop', function () { | ||
it('should be able to chop', () => { | ||
expect('testing'.fixSize(4)).toBe('test'); | ||
expect('testing'.fixSize(-3)).toBe('ing'); | ||
}); | ||
it('should be able to pad', function () { | ||
expect('testing'.fixSize(10,'$')).toBe('testing$$$'); | ||
it('should be able to pad', () => { | ||
expect('testing'.fixSize(10, '$')).toBe('testing$$$'); | ||
expect('testing'.fixSize(-10, '$')).toBe('$$$testing'); | ||
@@ -396,4 +421,4 @@ }); | ||
*/ | ||
describe('stringz#fixSize(tmpStr, size, char)', function () { | ||
it('should return null when size = 0', function () { | ||
describe('stringz#fixSize(tmpStr, size, char)', () => { | ||
it('should return null when size = 0', () => { | ||
expect(stringz.fixSize('testing', 0)).toBe(null); | ||
@@ -406,27 +431,33 @@ }); | ||
*/ | ||
describe('#fmt(args...) using indicies', function () { | ||
it('should return the same string when there are no fmt args', function () { | ||
describe('#fmt(args...) using indicies', () => { | ||
it('should return the same string when there are no fmt args', () => { | ||
expect('The quick brown fox'.fmt('bob', 'frank')).toBe('The quick brown fox'); | ||
}); | ||
it('should not replace open "{" at the beginning', function () { | ||
it('should not replace open "{" at the beginning', () => { | ||
expect('The %{s %{s} %{2}'.fmt('quick', 'brown', 'fox')).toBe('The %{s quick fox'); | ||
}); | ||
it('should not replace open "{" all over the place', function () { | ||
it('should not replace open "{" all over the place', () => { | ||
expect('The %{s %{0} %{1 %{s} %{2} %{1'.fmt('quick', 'brown', 'fox')).toBe('The %{s quick %{1 quick fox %{1'); | ||
}); | ||
it('should support indicies in the "{}"', function () { | ||
it('should support indicies in the "{}"', () => { | ||
expect('The %{0} %{1} %{2}'.fmt('quick', 'brown', 'fox')).toBe('The quick brown fox'); | ||
}); | ||
it('should support indicies out of order in the "{}"', function () { | ||
it('should support indicies out of order in the "{}"', () => { | ||
expect('The %{2} %{0} %{1}'.fmt('quick', 'brown', 'fox')).toBe('The fox quick brown'); | ||
}); | ||
it('should support indicies and the "s" mixed in the "{}"', function () { | ||
it('should support indicies and the "s" mixed in the "{}"', () => { | ||
expect('The %{0} %{s} %{2}'.fmt('quick', 'brown', 'fox')).toBe('The quick quick fox'); | ||
}); | ||
it('should support indicies out of order and the "s" mixed in the "{}"', function () { | ||
it('should support indicies out of order and the "s" mixed in the "{}"', () => { | ||
expect('The %{2} %{s} %{0}'.fmt('quick', 'brown', 'fox')).toBe('The fox quick quick'); | ||
}); | ||
it('should support repeated indicies', function () { | ||
it('should support repeated indicies', () => { | ||
expect('The %{0} %{0} %{0}'.fmt('quick', 'brown', 'fox')).toBe('The quick quick quick'); | ||
}); | ||
it('should support repeated "s" in the “{}" in order', () => { | ||
expect('The %{s} %{s} %{s}'.fmt('quick', 'brown', 'fox')).toBe('The quick brown fox'); | ||
}); | ||
it('should support indicies in the "{}"', () => { | ||
expect('The %{0} %{1} %{3}'.fmt('quick', 'brown', 'fox')).toBe('The quick brown undefined'); | ||
}); | ||
}); | ||
@@ -437,28 +468,28 @@ | ||
*/ | ||
describe('#fmt(args...) with simple string replacement', function () { | ||
it('should return the same string when there are no fmt args', function () { | ||
describe('#fmt(args...) with simple string replacement', () => { | ||
it('should return the same string when there are no fmt args', () => { | ||
expect('The quick brown fox'.fmt('bob', 'frank')).toBe('The quick brown fox'); | ||
}); | ||
it('should replace strings in order', function () { | ||
it('should replace strings in order', () => { | ||
expect('The %{s} %{s} %{s}'.fmt('quick', 'brown', 'fox')).toBe('The quick brown fox'); | ||
}); | ||
it('should respect the "%%" as an escape strings in order', function () { | ||
it('should respect the "%%" as an escape strings in order', () => { | ||
expect('The %%{s} %%{s} %%{s}'.fmt('quick', 'brown', 'fox')).toBe('The %%{s} %%{s} %%{s}'); | ||
}); | ||
it('should respect the "%%" as an escape string, mixed with replacements', function () { | ||
it('should respect the "%%" as an escape string, mixed with replacements', () => { | ||
expect('The %{s} %{s} %%{s}'.fmt('quick', 'brown', 'fox')).toBe('The quick brown %%{s}'); | ||
}); | ||
it('should not replace open "{" at the end', function () { | ||
it('should not replace open "{" at the end', () => { | ||
expect('The %{s} %{s} %{2'.fmt('quick', 'brown', 'fox')).toBe('The quick brown %{2'); | ||
}); | ||
it('should not replace open "{" at the beginning', function () { | ||
it('should not replace open "{" at the beginning', () => { | ||
expect('The %{s %{s} %{2}'.fmt('quick', 'brown', 'fox')).toBe('The %{s quick fox'); | ||
}); | ||
it('should not replace open "{" all over the place', function () { | ||
it('should not replace open "{" all over the place', () => { | ||
expect('The %{s %{0} %{1 %{s} %{2} %{1'.fmt('quick', 'brown', 'fox')).toBe('The %{s quick %{1 quick fox %{1'); | ||
}); | ||
it('should support indicies and the "s" mixed in the "{}"', function () { | ||
it('should support indicies and the "s" mixed in the "{}"', () => { | ||
expect('The %{0} %{s} %{2}'.fmt('quick', 'brown', 'fox')).toBe('The quick quick fox'); | ||
}); | ||
it('should support indicies out of order and the "s" mixed in the "{}"', function () { | ||
it('should support indicies out of order and the "s" mixed in the "{}"', () => { | ||
expect('The %{2} %{s} %{0}'.fmt('quick', 'brown', 'fox')).toBe('The fox quick quick'); | ||
@@ -471,4 +502,4 @@ }); | ||
*/ | ||
describe('stringz#fmt(tmpStr, args...)', function () { | ||
it('should support indicies out of order and the "s" mixed in the "{}"', function () { | ||
describe('stringz#fmt(tmpStr, args...)', () => { | ||
it('should support indicies out of order and the "s" mixed in the "{}"', () => { | ||
expect(stringz.fmt('The %{2} %{s} %{0}', 'quick', 'brown', 'fox')).toBe('The fox quick quick'); | ||
@@ -475,0 +506,0 @@ }); |
@@ -0,1 +1,4 @@ | ||
# 2020-03-10 - v1.4.0 | ||
- Update dependencies and `.travis.yml` config | ||
# 2017-04-02 - v1.3.0 | ||
@@ -2,0 +5,0 @@ - Support `#fixSize` method to chop or pad a string as needed |
@@ -40,4 +40,5 @@ /** | ||
* @returns {string} with all special values escaped | ||
* $& means the whole matched string | ||
*/ | ||
const escapeRegEx = (tmpStr) => { return tmpStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } | ||
const escapeRegEx = (tmpStr) => { return tmpStr.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"); } | ||
@@ -72,2 +73,25 @@ /** | ||
/** | ||
* Combine 2 strings together | ||
* with limited maximum 1 space between strings or words | ||
* | ||
* @param {string} tmpStr1 string 1 to combine | ||
* @param {string} tmpStr2 string 2 to combine | ||
* @returns {string} combined string | ||
* | ||
* @usage 'Hello '.combineStr('Monday'); => 'Hello Monday' | ||
* @usage 'Hello ‘。combineStr('Mondau); => 'Hello Monday' | ||
* @usage 'String1 '.combineStr('String2') => 'String1 String2' | ||
* @usage 'I want a '.scombineStr('hotdog') => 'I want a hotdog' | ||
* | ||
* @see https://www.w3schools.com/jsref/jsref_concat_string.asp | ||
*/ | ||
const combineStr = (tmpStr1, tmpStr2) => { //return tmpStr1.concat(tmpStr2); } | ||
var tmp1 = tmpStr1.replace(/\s+/g, ' '); | ||
var tmp2 = tmpStr2.replace(/\s+/g, ' '); | ||
var newStr = tmp1.concat(tmp2); | ||
var wantedStr = newStr.replace(/\s+/g, ' '); | ||
return wantedStr; | ||
}; | ||
/** | ||
* starts with functionality | ||
@@ -207,2 +231,3 @@ * | ||
* @param {string} char | ||
* @return {string} chopped or padded string, or `null` if `size` = 0 | ||
* | ||
@@ -245,2 +270,5 @@ * @see #chop(tmpStr, size) | ||
tmpStr = tmpStr.replace(/%\{(\d+)\}/g, function (match, group1) { | ||
if (/\d/g > args.length) { | ||
return 'undefined' | ||
} | ||
return args[group1]; | ||
@@ -260,2 +288,3 @@ }); | ||
* Adds the following to the `String.prototype` if it's not already a function: | ||
* - combineStr | ||
* - startsWith | ||
@@ -278,2 +307,5 @@ * - endsWith | ||
const addPrototypes = () => { | ||
if (typeof String.prototype.combineStr != 'function') | ||
String.prototype.combineStr = function(tmpStr2) {return combineStr.call(null, this, tmpStr2); } | ||
if (typeof String.prototype.startsWith != 'function') | ||
@@ -318,2 +350,3 @@ String.prototype.startsWith = function (matchStr) { return startsWith.call(null, this, matchStr); } | ||
module.exports = { | ||
combineStr: combineStr, | ||
startsWith: startsWith, | ||
@@ -320,0 +353,0 @@ endsWith: endsWith, |
{ | ||
"name": "string-utilz", | ||
"version": "1.3.0", | ||
"version": "1.4.0", | ||
"description": "String utilities for JavaScript.", | ||
"main": "lib/string-utilz.js", | ||
"scripts": { | ||
"test": "jest --coverage" | ||
"test": "jest --coverage --colors" | ||
}, | ||
@@ -27,8 +27,16 @@ "repository": { | ||
], | ||
"author": "MaddHacker <hacker@maddhacker.com> (http://www.maddhacker.com)", | ||
"author": "MaddHacker <hacker@maddhacker.com> (https://www.maddhacker.com)", | ||
"contributors": [ | ||
"MaddHacker <hacker@maddhacker.com> (https://www.maddhacker.com)", | ||
"theFieryDev <thefierydev@gmail.com> (https://www.thefierydev.com)" | ||
], | ||
"license": "Apache-2.0", | ||
"homepage": "https://github.com/MaddHacker/string-utilz#readme", | ||
"engines": { | ||
"node": ">=10.0.0", | ||
"npm": ">=5.0.0" | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": { | ||
"jest": "^19.0.2" | ||
"jest": "^25.1.0" | ||
}, | ||
@@ -35,0 +43,0 @@ "jest": { |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
53998
804
9