Skip to content

Commit a845917

Browse files
realitykingtmcw
authored andcommitted
Use native String.prototype.trim instead of a custom implementation. (eslint#201)
1 parent 3bd5919 commit a845917

File tree

1 file changed

+11
-15
lines changed

1 file changed

+11
-15
lines changed

lib/doctrine.js

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@
9090
title === 'public' || title === 'private' || title === 'protected';
9191
}
9292

93-
function trim(str) {
94-
return str.replace(/^\s+/, '').replace(/\s+$/, '');
95-
}
96-
9793
function unwrapComment(doc) {
9894
// JSDoc comment is following form
9995
// /**
@@ -544,7 +540,7 @@
544540
};
545541

546542
TagParser.prototype.parseDescription = function parseDescription() {
547-
var description = trim(sliceSource(source, index, this._last));
543+
var description = sliceSource(source, index, this._last).trim();
548544
if (description) {
549545
if ((/^-\s+/).test(description)) {
550546
description = description.substring(2);
@@ -555,15 +551,15 @@
555551
};
556552

557553
TagParser.prototype.parseCaption = function parseDescription() {
558-
var description = trim(sliceSource(source, index, this._last));
554+
var description = sliceSource(source, index, this._last).trim();
559555
var captionStartTag = '<caption>';
560556
var captionEndTag = '</caption>';
561557
var captionStart = description.indexOf(captionStartTag);
562558
var captionEnd = description.indexOf(captionEndTag);
563559
if (captionStart >= 0 && captionEnd >= 0) {
564-
this._tag.caption = trim(description.substring(
565-
captionStart + captionStartTag.length, captionEnd));
566-
this._tag.description = trim(description.substring(captionEnd + captionEndTag.length));
560+
this._tag.caption = description.substring(
561+
captionStart + captionStartTag.length, captionEnd).trim();
562+
this._tag.description = description.substring(captionEnd + captionEndTag.length).trim();
567563
} else {
568564
this._tag.description = description;
569565
}
@@ -585,7 +581,7 @@
585581
'namespace': true,
586582
'typedef': true
587583
};
588-
kind = trim(sliceSource(source, index, this._last));
584+
kind = sliceSource(source, index, this._last).trim();
589585
this._tag.kind = kind;
590586
if (!hasOwnProperty(kinds, kind)) {
591587
if (!this.addError('Invalid kind name \'%0\'', kind)) {
@@ -597,7 +593,7 @@
597593

598594
TagParser.prototype.parseAccess = function parseAccess() {
599595
var access;
600-
access = trim(sliceSource(source, index, this._last));
596+
access = sliceSource(source, index, this._last).trim();
601597
this._tag.access = access;
602598
if (access !== 'private' && access !== 'protected' && access !== 'public') {
603599
if (!this.addError('Invalid access name \'%0\'', access)) {
@@ -610,7 +606,7 @@
610606
TagParser.prototype.parseThis = function parseThis() {
611607
// this name may be a name expression (e.g. {foo.bar}),
612608
// an union (e.g. {foo.bar|foo.baz}) or a name path (e.g. foo.bar)
613-
var value = trim(sliceSource(source, index, this._last));
609+
var value = sliceSource(source, index, this._last).trim();
614610
if (value && value.charAt(0) === '{') {
615611
var gotType = this.parseType();
616612
if (gotType && this._tag.type.type === 'NameExpression' || this._tag.type.type === 'UnionType') {
@@ -626,7 +622,7 @@
626622

627623
TagParser.prototype.parseVariation = function parseVariation() {
628624
var variation, text;
629-
text = trim(sliceSource(source, index, this._last));
625+
text = sliceSource(source, index, this._last).trim();
630626
variation = parseFloat(text, 10);
631627
this._tag.variation = variation;
632628
if (isNaN(variation)) {
@@ -638,7 +634,7 @@
638634
};
639635

640636
TagParser.prototype.ensureEnd = function () {
641-
var shouldBeEmpty = trim(sliceSource(source, index, this._last));
637+
var shouldBeEmpty = sliceSource(source, index, this._last).trim();
642638
if (shouldBeEmpty) {
643639
if (!this.addError('Unknown content \'%0\'', shouldBeEmpty)) {
644640
return false;
@@ -819,7 +815,7 @@
819815
description += advance();
820816
}
821817

822-
return preserveWhitespace ? description : trim(description);
818+
return preserveWhitespace ? description : description.trim();
823819
}
824820

825821
function parse(comment, options) {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy