Skip to content

Commit 3652997

Browse files
committed
Removed String#paragraphs. Will become available as a plugin if needed.
Former-commit-id: 3c25262 Former-commit-id: 3ca407c8333f85e0a4c55af8158423d9a449c6c6
1 parent 2acfde1 commit 3652997

File tree

5 files changed

+10
-57
lines changed

5 files changed

+10
-57
lines changed

CAUTION.md

+3
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,9 @@ Drop it in before upgrading to get a general idea of what needs to change, or up
109109
- Level: Major
110110
- `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');`.
111111

112+
- Level: Major
113+
- `String#paragraphs` was removed.
114+
112115
- Level: Moderate
113116
- `Object.keys` and `Object.values` no longer have callbacks as second arguments. Use `Object.forEach` for iteration over an object's properties.
114117

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ v2.0.0
9797
- Changed object iteration callbacks to be value first.
9898
- Renamed `String#each` to `String#forEach`.
9999
- Changed `min/max/least/most` args to put the callback at the end.
100+
- Removed `String#paragraphs`.
100101

101102

102103
v1.4.2

lib/extras/upgrade.js

+6
Original file line numberDiff line numberDiff line change
@@ -281,6 +281,12 @@
281281
message: 'String#add was removed and now only exists as String#insert, which was previously an alias.',
282282
docs: 'String/insert'
283283
},
284+
{
285+
type: 'String',
286+
iName: 'paragraphs',
287+
message: 'String#paragraphs was removed.',
288+
docs: 'String'
289+
},
284290
{
285291
type: 'Function',
286292
iName: 'after',

lib/string.js

-32
Original file line numberDiff line numberDiff line change
@@ -756,38 +756,6 @@ defineInstance(sugarString, {
756756
return stringEach(trim(str), /^.*$/gm, fn);
757757
},
758758

759-
/***
760-
* @method paragraphs([fn])
761-
* @returns Array
762-
* @short Runs [fn] against each paragraph in the string, and returns an array.
763-
* @extra A paragraph is defined as a block of text bounded by two or more
764-
* line breaks.
765-
*
766-
* @callback fn
767-
*
768-
* p The current paragraph.
769-
* i The current index.
770-
* arr An array of all paragraphs.
771-
*
772-
* @example
773-
*
774-
* longText.paragraphs() -> array of paragraphs
775-
* longText.paragraphs(function(p) {
776-
* // Called once per paragraph
777-
* });
778-
*
779-
***/
780-
'paragraphs': function(str, fn) {
781-
var paragraphs = trim(str).split(/[\r\n]{2,}/);
782-
paragraphs = map(paragraphs, function(p, i) {
783-
if (fn) {
784-
var s = fn.call(p, p, i, paragraphs);
785-
}
786-
return s ? s : p;
787-
});
788-
return paragraphs;
789-
},
790-
791759
/***
792760
* @method codes([fn])
793761
* @returns Array

test/tests/string.js

-25
Original file line numberDiff line numberDiff line change
@@ -458,31 +458,6 @@ namespace('String', function () {
458458

459459
});
460460

461-
method('paragraphs', function() {
462-
463-
var counter = 0;
464-
var essay = 'the history of the united states\n\n';
465-
essay += 'it all began back in 1776 when someone declared something from someone.\n';
466-
essay += 'it was at this point that we had to get our rears in gear\n\n';
467-
essay += 'The British got their revenge in the late 60s with the British Invasion,\n';
468-
essay += 'which claimed the lives of over 32,352 young women across the nation.\n\n\n\n\n';
469-
essay += 'The End\n\n\n\n\n\n\n';
470-
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'];
471-
var indexes = [0,1,2,3];
472-
var callback = function(p, i, a) {
473-
equal(p, paragraphs[i], 'First argument should be the paragraph.');
474-
equal(i, indexes[i], 'Second argument should be the index.');
475-
equal(a, paragraphs, 'Third argument the array of paragraphs.');
476-
counter ++;
477-
};
478-
var result = run(essay, 'paragraphs', [callback]);
479-
equal(counter, 4, 'should have run 4 times');
480-
equal(result, paragraphs, 'result should be an array of matches');
481-
482-
test('', [''], 'empty string');
483-
484-
});
485-
486461
method('codes', function() {
487462

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

0 commit comments

Comments
 (0)