Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/rtf.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ module.exports = RTF = function () {
RTF.prototype.writeText = function (text, format, groupName) {
element = new TextElement(text, format);
if(groupName !== undefined && this._groupIndex(groupName) >= 0) {
this.elements[this._groupIndex(groupName)].push(element);
} else {
this.elements[this._groupIndex(groupName)].addElement(element);
} else {
this.elements.push(element);
}
};
Expand Down Expand Up @@ -92,12 +92,15 @@ RTF.prototype.addPar = function (groupName) {
//gets the index of a group
//TODO: make this more private by removing it from prototype and passing elements
RTF.prototype._groupIndex = function (name) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using findIndex instead of forEach to find the index of a group. It is more efficient and concise.

Suggested change
RTF.prototype._groupIndex = function (name) {
return this.elements.findIndex(el => el instanceof GroupElement && el.name === name);

this.elements.forEach(function(el, i){
var index = -1;

this.elements.forEach(function(el, i) {
if(el instanceof GroupElement && el.name===name) {
return i;
index = i;
}
});
return -1;

return index;
};

RTF.prototype.createDocument = function (callback) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name" : "@happy-doc/rtf",
"version" : "0.0.1",
"version" : "0.0.2",
"description" : "Assists with creating rich text documents.",
"main" : "./lib/rtf.js",
"author" : "HappyDoc",
Expand Down