kni 4.0.3 → 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/wrapper.js CHANGED
@@ -1,72 +1,68 @@
1
1
  // Wraps text at word boundaries for output to columnar displays.
2
2
  // Manages levels of indentation, bullets, and margin text.
3
- 'use strict';
4
3
 
5
- module.exports = Wrapper;
6
-
7
- function Wrapper(target, width) {
4
+ export default class Wrapper {
5
+ constructor(target, width) {
8
6
  this.target = target;
9
7
  this.width = width || 60;
10
8
  this.indents = [''];
11
9
  this.leads = [''];
12
10
  this.index = 0;
13
11
  this.flush = false;
14
- }
12
+ }
15
13
 
16
- // istanbul ignore next
17
- Wrapper.prototype.words = function words(words) {
18
- var array = words.split(' ');
19
- for (var i = 0; i < array.length; i++) {
20
- this.word(array[i]);
14
+ words(words) {
15
+ const array = words.split(' ');
16
+ for (let i = 0; i < array.length; i++) {
17
+ this.word(array[i]);
21
18
  }
22
- };
19
+ }
23
20
 
24
- Wrapper.prototype.push = function push(indent, lead) {
25
- var prefix = this.indents[this.indents.length - 1];
21
+ push(indent, lead) {
22
+ const prefix = this.indents[this.indents.length - 1];
26
23
  this.indents.push(prefix + indent);
27
24
  this.leads.push(prefix + lead);
28
- };
25
+ }
29
26
 
30
- Wrapper.prototype.pop = function pop() {
27
+ pop() {
31
28
  this.indents.pop();
32
29
  this.leads.pop();
33
- };
30
+ }
34
31
 
35
- Wrapper.prototype.word = function word(word) {
36
- var indent = this.indents[this.indents.length - 1];
32
+ word(word) {
33
+ const indent = this.indents[this.indents.length - 1];
37
34
  if (this.index === 0) {
38
- this.target.write(indent);
39
- this.index += indent.length;
40
- this.flush = true;
35
+ this.target.write(indent);
36
+ this.index += indent.length;
37
+ this.flush = true;
41
38
  }
42
39
  if (this.index + word.length + 1 > this.width) {
43
- this.break();
44
- this.target.write(indent + word);
45
- this.index += indent.length + word.length + 1;
46
- this.flush = false;
40
+ this.break();
41
+ this.target.write(indent + word);
42
+ this.index += indent.length + word.length + 1;
43
+ this.flush = false;
47
44
  } else if (this.flush) {
48
- this.target.write(word);
49
- this.index += word.length;
50
- this.flush = false;
45
+ this.target.write(word);
46
+ this.index += word.length;
47
+ this.flush = false;
51
48
  } else {
52
- this.target.write(' ' + word);
53
- this.index += word.length + 1;
54
- this.flush = false;
55
- }
56
-
57
- };
49
+ this.target.write(` ${word}`);
50
+ this.index += word.length + 1;
51
+ this.flush = false;
52
+ }
53
+ }
58
54
 
59
- Wrapper.prototype.break = function _break() {
55
+ break() {
60
56
  this.target.write('\n');
61
57
  this.index = 0;
62
58
  this.flush = true;
63
- };
59
+ }
64
60
 
65
- // Bring your own break, if you need it.
66
- // istanbul ignore next
67
- Wrapper.prototype.bullet = function bullet() {
68
- var lead = this.leads[this.leads.length - 1];
61
+ // Bring your own break, if you need it.
62
+ bullet() {
63
+ const lead = this.leads[this.leads.length - 1];
69
64
  this.target.write(lead);
70
65
  this.index = lead.length;
71
66
  this.flush = true;
72
- };
67
+ }
68
+ }
package/template.js DELETED
@@ -1,69 +0,0 @@
1
- 'use strict';
2
- var Engine = require('./engine');
3
- var story = require('./story.json');
4
- var Story = require('./story');
5
- var Document = require('./document');
6
-
7
- var reset = document.querySelector(".reset");
8
- reset.onclick = function onclick() {
9
- engine.reset();
10
- };
11
-
12
- var doc = new Document(document.body);
13
- var engine = new Engine({
14
- story: story,
15
- render: doc,
16
- dialog: doc,
17
- handler: {
18
- waypoint: function waypoint(waypoint) {
19
- var json = JSON.stringify(waypoint);
20
- window.history.pushState(waypoint, '', '#' + btoa(json));
21
- localStorage.setItem('kni', json);
22
- },
23
- goto: function _goto(label) {
24
- console.log(label);
25
- },
26
- answer: function answer(text) {
27
- console.log('>', text);
28
- }
29
- }
30
- });
31
-
32
- doc.clear();
33
-
34
- var waypoint;
35
- var json;
36
- if (waypoint = window.location.hash || null) {
37
- try {
38
- waypoint = atob(waypoint.slice(1));
39
- waypoint = JSON.parse(waypoint);
40
- } catch (error) {
41
- console.error(error);
42
- waypoint = null;
43
- }
44
- } else if (json = localStorage.getItem('kni')) {
45
- try {
46
- waypoint = JSON.parse(json);
47
- } catch (error) {
48
- console.error(error);
49
- waypoint = null;
50
- }
51
- window.history.replaceState(waypoint, '', '#' + btoa(json));
52
- }
53
-
54
- window.onpopstate = function onpopstate(event) {
55
- console.log('> back');
56
- engine.resume(event.state);
57
- };
58
-
59
- engine.resume(waypoint);
60
-
61
- window.onkeypress = function onkeypress(event) {
62
- var key = event.code;
63
- var match = /^Digit(\d+)$/.exec(key);
64
- if (match) {
65
- engine.answer(match[1]);
66
- } else if (key === 'KeyR') {
67
- engine.reset();
68
- }
69
- };