kni 4.0.2 → 5.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/excerpt.js CHANGED
@@ -1,197 +1,199 @@
1
1
  // An interface for building excerpts and writing them to a stream.
2
2
  // The stream must have the interface of the line wrapper.
3
- 'use strict';
4
3
 
5
- module.exports = Excerpt;
6
-
7
- function Excerpt() {
4
+ export default class Excerpt {
5
+ constructor() {
8
6
  this.children = [];
9
7
  this.flag = false;
10
- }
8
+ }
11
9
 
12
- Excerpt.prototype.Child = Paragraph;
13
- Excerpt.prototype.paragraph = flag;
14
- Excerpt.prototype.break = breakChild;
10
+ Child = Paragraph;
11
+
12
+ paragraph() {
13
+ this.flag = true;
14
+ }
15
+
16
+ break() {
17
+ if (this.children.length === 0) {
18
+ return;
19
+ }
20
+ const last = this.children[this.children.length - 1];
21
+ last.break();
22
+ }
15
23
 
16
- // istanbul ignore next
17
- Excerpt.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
24
+ startJoin(lift, delimiter, conjunction) {
18
25
  if (this.children.length === 0) {
19
- return;
26
+ return;
20
27
  }
21
- var last = this.children[this.children.length - 1];
28
+ const last = this.children[this.children.length - 1];
22
29
  last.startJoin(lift, delimiter, conjunction);
23
- };
30
+ }
24
31
 
25
- // istanbul ignore next
26
- Excerpt.prototype.delimit = function delimit(delimiter) {
32
+ delimit(delimiter) {
27
33
  if (this.children.length === 0) {
28
- return;
34
+ return;
29
35
  }
30
- var last = this.children[this.children.length - 1];
36
+ const last = this.children[this.children.length - 1];
31
37
  last.delimit(delimiter);
32
- };
38
+ }
33
39
 
34
- // istanbul ignore next
35
- Excerpt.prototype.stopJoin = function stopJoin() {
40
+ stopJoin() {
36
41
  if (this.children.length === 0) {
37
- return;
42
+ return;
38
43
  }
39
- var last = this.children[this.children.length - 1];
44
+ const last = this.children[this.children.length - 1];
40
45
  last.stopJoin();
41
- };
46
+ }
42
47
 
43
- Excerpt.prototype.digest = function digest(lift, words, drop) {
48
+ digest(lift, words, drop) {
44
49
  if (typeof words === 'string') {
45
- words = words.split(' ');
50
+ words = words.split(' ');
46
51
  }
47
52
  if (this.children.length === 0 || this.flag) {
48
- this.children.push(new this.Child());
49
- this.flag = false;
53
+ this.children.push(new this.Child());
54
+ this.flag = false;
50
55
  }
51
- var last = this.children[this.children.length - 1];
56
+ const last = this.children[this.children.length - 1];
52
57
  last.digest(lift, words, drop);
53
- };
54
-
55
- Excerpt.prototype.write = function write(wrapper) {
56
- for (var i = 0; i < this.children.length; i++) {
57
- if (i > 0) {
58
- wrapper.break();
59
- }
60
- this.children[i].write(wrapper);
58
+ }
59
+
60
+ write(wrapper) {
61
+ for (let i = 0; i < this.children.length; i++) {
62
+ if (i > 0) {
63
+ wrapper.break();
64
+ }
65
+ this.children[i].write(wrapper);
61
66
  }
62
- };
67
+ }
68
+ }
63
69
 
64
- function Paragraph() {
70
+ class Paragraph {
71
+ constructor() {
65
72
  this.children = [];
66
73
  this.flag = false;
67
- }
74
+ }
68
75
 
69
- Paragraph.prototype.Child = Stanza;
70
- Paragraph.prototype.break = flag;
71
- Paragraph.prototype.startJoin = Excerpt.prototype.startJoin;
72
- Paragraph.prototype.delimit = Excerpt.prototype.delimit;
73
- Paragraph.prototype.stopJoin = Excerpt.prototype.stopJoin;
74
- Paragraph.prototype.digest = Excerpt.prototype.digest;
76
+ Child = Stanza;
75
77
 
76
- Paragraph.prototype.write = function write(wrapper) {
77
- for (var i = 0; i < this.children.length; i++) {
78
- this.children[i].write(wrapper);
78
+ break() {
79
+ this.flag = true;
80
+ }
81
+
82
+ startJoin = Excerpt.prototype.startJoin;
83
+ delimit = Excerpt.prototype.delimit;
84
+ stopJoin = Excerpt.prototype.stopJoin;
85
+ digest = Excerpt.prototype.digest;
86
+
87
+ write(wrapper) {
88
+ for (let i = 0; i < this.children.length; i++) {
89
+ this.children[i].write(wrapper);
79
90
  }
80
- };
91
+ }
92
+ }
81
93
 
82
- function Stanza() {
94
+ class Stanza {
95
+ constructor() {
83
96
  this.children = [];
84
97
  this.lift = false;
85
98
  this.empty = true;
86
99
  this.cursor = new StanzaProxy(this);
87
- }
100
+ }
88
101
 
89
- // istanbul ignore next
90
- Stanza.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
102
+ startJoin(lift, delimiter, conjunction) {
91
103
  this.cursor = this.cursor.startJoin(lift, delimiter, conjunction);
92
- };
104
+ }
93
105
 
94
- // istanbul ignore next
95
- Stanza.prototype.delimit = function delimit(delimiter) {
106
+ delimit(delimiter) {
96
107
  this.cursor.delimit(delimiter);
97
- };
108
+ }
98
109
 
99
- // istanbul ignore next
100
- Stanza.prototype.stopJoin = function stopJoin() {
110
+ stopJoin() {
101
111
  this.cursor = this.cursor.stopJoin();
102
- };
112
+ }
103
113
 
104
- Stanza.prototype.digest = function digest(lift, words, drop) {
114
+ digest(lift, words, drop) {
105
115
  this.cursor.digest(lift, words, drop);
106
- };
116
+ }
107
117
 
108
- Stanza.prototype.write = function write(wrapper) {
109
- for (var i = 0; i < this.children.length; i++) {
110
- wrapper.word(this.children[i]);
118
+ write(wrapper) {
119
+ for (let i = 0; i < this.children.length; i++) {
120
+ wrapper.word(this.children[i]);
111
121
  }
112
122
  wrapper.break();
113
- };
123
+ }
114
124
 
115
- Stanza.prototype.proxyDigest = function proxyDigest(lift, words, drop) {
125
+ proxyDigest(lift, words, drop) {
116
126
  lift = this.lift || lift;
117
- var i = 0;
127
+ let i = 0;
118
128
  if (!lift && words.length && this.children.length) {
119
- this.children[this.children.length - 1] += words[i++];
129
+ this.children[this.children.length - 1] += words[i++];
120
130
  }
121
131
  for (; i < words.length; i++) {
122
- this.children.push(words[i]);
132
+ this.children.push(words[i]);
123
133
  }
124
134
  this.lift = drop;
125
135
  this.empty = false;
126
- };
136
+ }
137
+ }
127
138
 
128
- function StanzaProxy(parent) {
139
+ class StanzaProxy {
140
+ constructor(parent) {
129
141
  this.parent = parent;
130
- }
142
+ }
131
143
 
132
- // istanbul ignore next
133
- StanzaProxy.prototype.startJoin = function startJoin(lift, delimiter, conjunction) {
144
+ startJoin(lift, delimiter, conjunction) {
134
145
  return new Conjunction(this, lift, delimiter, conjunction);
135
- };
146
+ }
136
147
 
137
- // istanbul ignore next
138
- StanzaProxy.prototype.delimit = function delimit(delimiter) {
148
+ delimit(delimiter) {
139
149
  this.parent.digest('', [delimiter], ' ');
140
- };
150
+ }
141
151
 
142
- // istanbul ignore next
143
- StanzaProxy.prototype.stopJoin = function stopJoin() {
152
+ stopJoin() {
144
153
  throw new Error('cannot stop without starting conjunction');
145
- };
154
+ }
146
155
 
147
- StanzaProxy.prototype.digest = function digest(lift, words, drop) {
156
+ digest(lift, words, drop) {
148
157
  this.parent.proxyDigest(lift, words, drop);
149
- };
158
+ }
159
+ }
150
160
 
151
- // istanbul ignore next
152
- function Conjunction(parent, lift, delimiter, conjunction) {
161
+ class Conjunction {
162
+ constructor(parent, lift, delimiter, conjunction) {
153
163
  this.children = [];
154
164
  this.parent = parent;
155
165
  this.lift = lift;
156
166
  this.delimiter = delimiter;
157
167
  this.conjunction = conjunction;
158
- }
168
+ }
169
+
170
+ Child = Stanza;
171
+
172
+ delimit() {
173
+ this.flag = true;
174
+ }
159
175
 
160
- Conjunction.prototype.Child = Stanza;
161
- Conjunction.prototype.delimit = flag;
162
- Conjunction.prototype.digest = Excerpt.prototype.digest;
176
+ digest = Excerpt.prototype.digest;
163
177
 
164
- Conjunction.prototype.startJoin = StanzaProxy.prototype.startJoin;
178
+ startJoin = StanzaProxy.prototype.startJoin;
165
179
 
166
- // istanbul ignore next
167
- Conjunction.prototype.stopJoin = function stopJoin(drop) {
180
+ stopJoin(drop) {
168
181
  if (this.children.length === 0) {
182
+ // noop
169
183
  } else if (this.children.length === 1) {
170
- this.parent.digest(this.lift, this.children[0].children, drop);
184
+ this.parent.digest(this.lift, this.children[0].children, drop);
171
185
  } else if (this.children.length === 2) {
172
- this.parent.digest(this.lift, this.children[0].children, '');
173
- this.parent.digest(' ', [this.conjunction], ' ');
174
- this.parent.digest(' ', this.children[1].children, drop);
186
+ this.parent.digest(this.lift, this.children[0].children, '');
187
+ this.parent.digest(' ', [this.conjunction], ' ');
188
+ this.parent.digest(' ', this.children[1].children, drop);
175
189
  } else {
176
- for (var i = 0; i < this.children.length - 1; i++) {
177
- this.parent.digest('', this.children[i].children, '');
178
- this.parent.digest('', [this.delimiter], ' ');
179
- }
180
- this.parent.digest('', [this.conjunction], ' ');
190
+ for (let i = 0; i < this.children.length - 1; i++) {
181
191
  this.parent.digest('', this.children[i].children, '');
192
+ this.parent.digest('', [this.delimiter], ' ');
193
+ }
194
+ this.parent.digest('', [this.conjunction], ' ');
195
+ this.parent.digest('', this.children[this.children.length - 1].children, '');
182
196
  }
183
197
  return this.parent;
184
- };
185
-
186
- function flag() {
187
- this.flag = true;
198
+ }
188
199
  }
189
-
190
- function breakChild() {
191
- // istanbul ignore next
192
- if (this.children.length === 0) {
193
- return;
194
- }
195
- var last = this.children[this.children.length - 1];
196
- last.break();
197
- };