Skip to content

Commit

Permalink
Removed String#paragraphs. Will become available as a plugin if needed.
Browse files Browse the repository at this point in the history
Former-commit-id: 3c25262
Former-commit-id: 3ca407c8333f85e0a4c55af8158423d9a449c6c6
  • Loading branch information
andrewplummer committed Jul 10, 2016
1 parent 2acfde1 commit 3652997
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 57 deletions.
3 changes: 3 additions & 0 deletions CAUTION.md
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,9 @@ Drop it in before upgrading to get a general idea of what needs to change, or up
- Level: Major
- `Array#all`, `Array#any`, `Object.all`, and `Object.any` aliases were removed to align Sugar more with native methods. If needed, these can still easily be aliased with `Sugar.Array.alias('all', 'every');`.

- Level: Major
- `String#paragraphs` was removed.

- Level: Moderate
- `Object.keys` and `Object.values` no longer have callbacks as second arguments. Use `Object.forEach` for iteration over an object's properties.

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ v2.0.0
- Changed object iteration callbacks to be value first.
- Renamed `String#each` to `String#forEach`.
- Changed `min/max/least/most` args to put the callback at the end.
- Removed `String#paragraphs`.


v1.4.2
Expand Down
6 changes: 6 additions & 0 deletions lib/extras/upgrade.js
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,12 @@
message: 'String#add was removed and now only exists as String#insert, which was previously an alias.',
docs: 'String/insert'
},
{
type: 'String',
iName: 'paragraphs',
message: 'String#paragraphs was removed.',
docs: 'String'
},
{
type: 'Function',
iName: 'after',
Expand Down
32 changes: 0 additions & 32 deletions lib/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -756,38 +756,6 @@ defineInstance(sugarString, {
return stringEach(trim(str), /^.*$/gm, fn);
},

/***
* @method paragraphs([fn])
* @returns Array
* @short Runs [fn] against each paragraph in the string, and returns an array.
* @extra A paragraph is defined as a block of text bounded by two or more
* line breaks.
*
* @callback fn
*
* p The current paragraph.
* i The current index.
* arr An array of all paragraphs.
*
* @example
*
* longText.paragraphs() -> array of paragraphs
* longText.paragraphs(function(p) {
* // Called once per paragraph
* });
*
***/
'paragraphs': function(str, fn) {
var paragraphs = trim(str).split(/[\r\n]{2,}/);
paragraphs = map(paragraphs, function(p, i) {
if (fn) {
var s = fn.call(p, p, i, paragraphs);
}
return s ? s : p;
});
return paragraphs;
},

/***
* @method codes([fn])
* @returns Array
Expand Down
25 changes: 0 additions & 25 deletions test/tests/string.js
Original file line number Diff line number Diff line change
Expand Up @@ -458,31 +458,6 @@ namespace('String', function () {

});

method('paragraphs', function() {

var counter = 0;
var essay = 'the history of the united states\n\n';
essay += 'it all began back in 1776 when someone declared something from someone.\n';
essay += 'it was at this point that we had to get our rears in gear\n\n';
essay += 'The British got their revenge in the late 60s with the British Invasion,\n';
essay += 'which claimed the lives of over 32,352 young women across the nation.\n\n\n\n\n';
essay += 'The End\n\n\n\n\n\n\n';
var paragraphs = ['the history of the united states', 'it all began back in 1776 when someone declared something from someone.\nit was at this point that we had to get our rears in gear', 'The British got their revenge in the late 60s with the British Invasion,\nwhich claimed the lives of over 32,352 young women across the nation.', 'The End'];
var indexes = [0,1,2,3];
var callback = function(p, i, a) {
equal(p, paragraphs[i], 'First argument should be the paragraph.');
equal(i, indexes[i], 'Second argument should be the index.');
equal(a, paragraphs, 'Third argument the array of paragraphs.');
counter ++;
};
var result = run(essay, 'paragraphs', [callback]);
equal(counter, 4, 'should have run 4 times');
equal(result, paragraphs, 'result should be an array of matches');

test('', [''], 'empty string');

});

method('codes', function() {

test('jumpy', [106,117,109,112,121], 'jumpy');
Expand Down

0 comments on commit 3652997

Please sign in to comment.