@sebbo2002/vestaboard 1.0.0-develop.1

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/LICENSE ADDED
@@ -0,0 +1,16 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2022 Sebastian Pekarek
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
6
+ documentation files (the "Software"), to deal in the Software without restriction, including without limitation the
7
+ rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit
8
+ persons to whom the Software is furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in all copies or substantial portions of the
11
+ Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
14
+ WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
15
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16
+ OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,89 @@
1
+ <p align="center">
2
+ <img src="https://d.sebbo.net/vestaboard-client-logo-CHm68XZRk-zNNTOboqFhVFbeuN6ccZkBsvGQxAJPx5GCBbSI2GnbSse6ovApzaULciWRnoOTzOny70L7Rcpv0SIkOPGIwCC3ZDsJFNeH1A00lB.png" alt="Logo" />
3
+ </p>
4
+
5
+ # `@sebbo2002/vestaboard`
6
+
7
+ [![MIT LICENSE](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](https://github.com/sebbo2002/vestaboard/blob/develop/LICENSE)
8
+ [![Package Size](https://img.shields.io/bundlephobia/min/@sebbo2002/vestaboard?style=flat-square)](https://bundlephobia.com/package/@sebbo2002/vestaboard)
9
+ [![CI Status](https://img.shields.io/github/workflow/status/sebbo2002/vestaboard/Test%20%26%20Release?style=flat-square)](https://github.com/sebbo2002/vestaboard/actions)
10
+
11
+ <br />
12
+
13
+
14
+ Just another client for the [Vestaboard](https://www.vestaboard.com/) [APIs](https://docs.vestaboard.com/). It supports
15
+ the [Subscription API](https://docs.vestaboard.com/methods), [Read/Write API](https://docs.vestaboard.com/read-write) and
16
+ the [Local API](https://docs.vestaboard.com/local). Written in Typescript.
17
+
18
+ The library also provides a small collection of helpers to format messages on the Vestaboard. This includes a `write()`
19
+ method that automatically wraps text, a `fill()` method to fill the board with nice characters, or `table()` to conjure
20
+ up a table on the board.
21
+
22
+
23
+ ## 📦 Installation
24
+
25
+ npm i --save @sebbo2002/vestaboard
26
+
27
+
28
+ ## ⚡️ Quick Start
29
+
30
+ #### Draw some patterns using the Subscription API
31
+
32
+ ```js
33
+ import { SubscriptionAPI, Message } from '@sebbo2002/vestaboard';
34
+ const api = new SubscriptionAPI('3eadf7a8-6602-4bf5-92f4-970d36066958', '******************************');
35
+ const msg = new Message().fill('🟥🟧🟨🟩🟦🟪');
36
+
37
+ api.postMessage(msg);
38
+ ```
39
+
40
+ #### Write a calendar on a local Vestaboard
41
+ ```js
42
+ import { LocalAPI, Message } from '@sebbo2002/vestaboard';
43
+ const api = new LocalAPI('***');
44
+ const msg = new Message().table([
45
+ ['now', 'Daily'],
46
+ ['13:00', 'Super Secret Meeting'],
47
+ ['16:30', 'Awesome Presentation']
48
+ ]);
49
+
50
+ api.postMessage(msg);
51
+ ```
52
+
53
+ #### Write Hello World on multiple local boards
54
+ ```js
55
+ import { MultipleBoards, LocalAPI, Message } from '@sebbo2002/vestaboard';
56
+ const board1 = new LocalAPI('***');
57
+ const board2 = new LocalAPI('***');
58
+ const boards = new MultipleBoards([board1, board2]);
59
+
60
+ boards.postMessage('Hello World');
61
+ ```
62
+
63
+ See the [examples](./examples) folder for more examples.
64
+
65
+
66
+ ## 📑 API-Reference
67
+
68
+ - [Index](https://sebbo2002.github.io/vestaboard/develop/reference/)
69
+ - [LocalAPI](https://sebbo2002.github.io/vestaboard/develop/reference/classes/LocalAPI.html)
70
+ - [Message](https://sebbo2002.github.io/vestaboard/develop/reference/classes/Message.html)
71
+ - [MultipleBoards](https://sebbo2002.github.io/vestaboard/develop/reference/classes/MultipleBoards.html)
72
+ - [ReadWriteAPI](https://sebbo2002.github.io/vestaboard/develop/reference/classes/ReadWriteAPI.html)
73
+ - [SubscriptionAPI](https://sebbo2002.github.io/vestaboard/develop/reference/classes/SubscriptionAPI.html)
74
+
75
+
76
+ ## 🚦 Tests
77
+
78
+ Some unit tests use the Vestaboard API to run the tests. You can use the `.env.example` file as a template and enter your
79
+ data there accordingly.
80
+
81
+ ```
82
+ npm test
83
+ npm run coverage
84
+ ```
85
+
86
+
87
+ ## 🙆🏼‍♂️ Copyright and license
88
+
89
+ Copyright (c) Sebastian Pekarek under the [MIT license](LICENSE).
@@ -0,0 +1,6 @@
1
+ export { default as LocalAPI } from './local-api.js';
2
+ export { default as Message } from './message.js';
3
+ export { default as MultipleBoards } from './multiple-boards.js';
4
+ export { default as ReadWriteAPI } from './read-write-api.js';
5
+ export { default as SubscriptionAPI } from './subscription-api.js';
6
+ export { BOARD_LINE_LENGTH, BOARD_LINES, BoardCharLine, BoardCharArray, MessageWriteCoords, MessageWritePosition, MessageWriteOptions, Installation, Viewer, Subscription, Subscriptions, SubscriptionPostResponse, RequestOptions, Boards } from './types';
package/dist/index.js ADDED
@@ -0,0 +1,7 @@
1
+ export { default as LocalAPI } from './local-api.js';
2
+ export { default as Message } from './message.js';
3
+ export { default as MultipleBoards } from './multiple-boards.js';
4
+ export { default as ReadWriteAPI } from './read-write-api.js';
5
+ export { default as SubscriptionAPI } from './subscription-api.js';
6
+ export { BOARD_LINE_LENGTH, BOARD_LINES, MessageWritePosition } from './types';
7
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,IAAI,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AACrD,OAAO,EAAE,OAAO,IAAI,OAAO,EAAE,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,IAAI,cAAc,EAAE,MAAM,sBAAsB,CAAC;AACjE,OAAO,EAAE,OAAO,IAAI,YAAY,EAAE,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EAAE,OAAO,IAAI,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACnE,OAAO,EACH,iBAAiB,EACjB,WAAW,EAIX,oBAAoB,EASvB,MAAM,SAAS,CAAC"}
@@ -0,0 +1,11 @@
1
+ import Message from './message.js';
2
+ import type { RequestOptions } from './types.js';
3
+ export default class LocalAPI {
4
+ private readonly key;
5
+ private readonly host;
6
+ private readonly options;
7
+ constructor(key: string, host?: string, options?: RequestOptions);
8
+ private request;
9
+ getCurrentMessage(): Promise<Message>;
10
+ postMessage(message: Message | string): Promise<void>;
11
+ }
@@ -0,0 +1,38 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Message from './message.js';
11
+ import { request } from './tools.js';
12
+ export default class LocalAPI {
13
+ constructor(key, host, options) {
14
+ this.key = key;
15
+ this.host = host || 'vestaboard.local';
16
+ this.options = options || {};
17
+ }
18
+ request(path, data, options = {}) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return request(`http://${this.host}:7000/local-api/message`, {
21
+ 'X-Vestaboard-Local-Api-Key': this.key
22
+ }, data, Object.assign({}, this.options, options));
23
+ });
24
+ }
25
+ getCurrentMessage() {
26
+ return __awaiter(this, void 0, void 0, function* () {
27
+ const response = yield this.request('/');
28
+ return new Message(Array.isArray(response) ? response : response.message);
29
+ });
30
+ }
31
+ postMessage(message) {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ const msgObj = typeof message === 'string' ? new Message(message) : message;
34
+ yield this.request('/', JSON.stringify(msgObj.toCharArray()), { parseResponse: false });
35
+ });
36
+ }
37
+ }
38
+ //# sourceMappingURL=local-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"local-api.js","sourceRoot":"","sources":["../src/local-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,MAAM,CAAC,OAAO,OAAO,QAAQ;IAKzB,YAAa,GAAW,EAAE,IAAa,EAAE,OAAwB;QAC7D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,IAAI,GAAG,IAAI,IAAI,kBAAkB,CAAC;QACvC,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IACjC,CAAC;IAEa,OAAO,CAAK,IAAY,EAAE,IAAa,EAAE,UAA0B,EAAE;;YAC/E,OAAO,OAAO,CAAC,UAAU,IAAI,CAAC,IAAI,yBAAyB,EAAE;gBACzD,4BAA4B,EAAE,IAAI,CAAC,GAAG;aACzC,EAAE,IAAI,EAAE,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,IAAI,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,CAAC;QACvD,CAAC;KAAA;IAEK,iBAAiB;;YACnB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAA6C,GAAG,CAAC,CAAC;YACrF,OAAO,IAAI,OAAO,CAAC,KAAK,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;QAC9E,CAAC;KAAA;IAEK,WAAW,CAAE,OAAyB;;YACxC,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC5E,MAAM,IAAI,CAAC,OAAO,CAAO,GAAG,EACxB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,EACpC,EAAE,aAAa,EAAE,KAAK,EAAE,CAC3B,CAAC;QACN,CAAC;KAAA;CACJ"}
@@ -0,0 +1,73 @@
1
+ import { BoardCharArray, MessageWriteOptions } from './types.js';
2
+ /**
3
+ * Map with all supported characters plus a few emojis
4
+ * mapped to corresponding characters of the Vestaboard
5
+ */
6
+ export declare const CHAR_MAP: Array<[string, number[]]>;
7
+ /**
8
+ * You can build a message like this:
9
+ *
10
+ * ```javascript
11
+ * import { Message } from '@sebbo2002/vestaboard';
12
+ *
13
+ * const myMessage = new Message('Hello World');
14
+ *
15
+ * // same as
16
+ *
17
+ * const myOtherMessage = new Message()
18
+ * .write('Hello World')
19
+ * .center();
20
+ * ```
21
+ */
22
+ export default class Message {
23
+ private static readonly splitter;
24
+ private readonly board;
25
+ private cursor;
26
+ constructor(message?: BoardCharArray | string);
27
+ static string2chars(word: string, options?: MessageWriteOptions): number[];
28
+ static char2char(char: string): number[];
29
+ static charToString(char: number): string;
30
+ static splitCharsIntoLines(chars: number[], lineLength: [number, number]): Array<number[]>;
31
+ static removeEmojisFromChars(chars: number[]): number[];
32
+ static getColumnSizesFromData(rows: Array<string[]>, options?: MessageWriteOptions): number[];
33
+ get isEmpty(): boolean;
34
+ /**
35
+ * Fills the board with the passed character or text. The text
36
+ * is repeated again and again until the board is completely filled.
37
+ */
38
+ fill(text?: string): this;
39
+ /**
40
+ * Write a text on your new message. If your message is not empty it will continue
41
+ * where you last left off (`position: MessageWritePosition.CURRENT`). Alternatively
42
+ * you can continue on the next line or give an exact position.
43
+ *
44
+ * @param text
45
+ * @param options
46
+ */
47
+ write(text: string, options?: MessageWriteOptions): this;
48
+ /**
49
+ * Generate a table with the given data
50
+ *
51
+ * @example new Message().table([
52
+ * ['now', 'Daily'],
53
+ * ['13:00', 'Super Secret Meeting'],
54
+ * ['16:30', 'Awesome Presentation']
55
+ * ])
56
+ *
57
+ * #==============================================#
58
+ * # N O W D A I L Y #
59
+ * # #
60
+ * # 1 3 : 0 0 S U P E R S E C R E T #
61
+ * # M E E T I N G #
62
+ * # #
63
+ * # 1 6 : 3 0 A W E S O M E P R E S E N T - #
64
+ * #==============================================#
65
+ */
66
+ table(rows: Array<string[]>): this;
67
+ /**
68
+ * Center the current message content
69
+ */
70
+ center(): void;
71
+ toString(): string;
72
+ toCharArray(): BoardCharArray;
73
+ }
@@ -0,0 +1,545 @@
1
+ import GraphemeSplitter from 'grapheme-splitter';
2
+ import { BOARD_LINE_LENGTH, BOARD_LINES, MessageWritePosition } from './types.js';
3
+ /**
4
+ * Map with all supported characters plus a few emojis
5
+ * mapped to corresponding characters of the Vestaboard
6
+ */
7
+ export const CHAR_MAP = [
8
+ [' ', [0]],
9
+ ['A', [1]],
10
+ ['a', [1]],
11
+ ['b', [2]],
12
+ ['B', [2]],
13
+ ['C', [3]],
14
+ ['c', [3]],
15
+ ['d', [4]],
16
+ ['e', [5]],
17
+ ['f', [6]],
18
+ ['g', [7]],
19
+ ['h', [8]],
20
+ ['i', [9]],
21
+ ['j', [10]],
22
+ ['k', [11]],
23
+ ['l', [12]],
24
+ ['m', [13]],
25
+ ['n', [14]],
26
+ ['o', [15]],
27
+ ['p', [16]],
28
+ ['q', [17]],
29
+ ['r', [18]],
30
+ ['s', [19]],
31
+ ['t', [20]],
32
+ ['u', [21]],
33
+ ['v', [22]],
34
+ ['w', [23]],
35
+ ['x', [24]],
36
+ ['y', [25]],
37
+ ['z', [26]],
38
+ ['D', [4]],
39
+ ['E', [5]],
40
+ ['F', [6]],
41
+ ['G', [7]],
42
+ ['H', [8]],
43
+ ['I', [9]],
44
+ ['J', [10]],
45
+ ['K', [11]],
46
+ ['L', [12]],
47
+ ['M', [13]],
48
+ ['N', [14]],
49
+ ['O', [15]],
50
+ ['P', [16]],
51
+ ['Q', [17]],
52
+ ['R', [18]],
53
+ ['S', [19]],
54
+ ['T', [20]],
55
+ ['U', [21]],
56
+ ['V', [22]],
57
+ ['W', [23]],
58
+ ['X', [24]],
59
+ ['Y', [25]],
60
+ ['Z', [26]],
61
+ ['1', [27]],
62
+ ['2', [28]],
63
+ ['3', [29]],
64
+ ['4', [30]],
65
+ ['5', [31]],
66
+ ['6', [32]],
67
+ ['7', [33]],
68
+ ['8', [34]],
69
+ ['9', [35]],
70
+ ['0', [36]],
71
+ ['!', [37]],
72
+ ['@', [38]],
73
+ ['#', [39]],
74
+ ['$', [40]],
75
+ ['(', [41]],
76
+ [')', [42]],
77
+ ['-', [44]],
78
+ ['+', [46]],
79
+ ['&', [47]],
80
+ ['=', [48]],
81
+ [';', [49]],
82
+ [':', [50]],
83
+ ['\'', [52]],
84
+ ['"', [53]],
85
+ ['%', [54]],
86
+ [',', [55]],
87
+ ['.', [56]],
88
+ ['/', [59]],
89
+ ['?', [60]],
90
+ ['°', [62]],
91
+ ['ä', [1, 5]],
92
+ ['Ä', [1, 5]],
93
+ ['ö', [15, 5]],
94
+ ['Ö', [15, 5]],
95
+ ['ü', [21, 5]],
96
+ ['Ü', [21, 5]],
97
+ ['ß', [19, 19]],
98
+ ['🟥', [63]],
99
+ ['🟧', [64]],
100
+ ['🟨', [65]],
101
+ ['🟩', [66]],
102
+ ['🟦', [67]],
103
+ ['🟪', [68]],
104
+ ['⬜️', [69]],
105
+ ['⬜', [69]],
106
+ ['⬛️', [-2]],
107
+ ['⬛', [-2]],
108
+ ['﹫', [38]],
109
+ ['@', [38]],
110
+ ['0️⃣', [36]],
111
+ ['1️⃣', [27]],
112
+ ['2️⃣', [28]],
113
+ ['3️⃣', [29]],
114
+ ['4️⃣', [30]],
115
+ ['5️⃣', [31]],
116
+ ['6️⃣', [32]],
117
+ ['7️⃣', [33]],
118
+ ['8️⃣', [34]],
119
+ ['9️⃣', [35]],
120
+ ['❕', [37]],
121
+ ['‼️', [37, 37]],
122
+ ['❗️', [37]],
123
+ ['⁉️', [37, 60]],
124
+ ['#️⃣', [39]],
125
+ ['💲', [40]],
126
+ ['$', [40]],
127
+ ['﹩', [40]],
128
+ ['$', [40]],
129
+ ['←', [44]],
130
+ ['→', [44]],
131
+ ['➡', [44]],
132
+ ['⬅', [44]],
133
+ ['➔', [44]],
134
+ ['↔', [44]],
135
+ ['–', [44]],
136
+ ['➕', [46]],
137
+ ['+', [46]],
138
+ ['﹪', [54]],
139
+ ['%', [54]],
140
+ ['❓', [60]],
141
+ ['❔', [60]],
142
+ ['℃', [62, 3]],
143
+ ['℉', [62, 6]]
144
+ ];
145
+ const EMPTY_BOARD = new Array(BOARD_LINES).fill(new Array(BOARD_LINE_LENGTH).fill(0));
146
+ /**
147
+ * You can build a message like this:
148
+ *
149
+ * ```javascript
150
+ * import { Message } from '@sebbo2002/vestaboard';
151
+ *
152
+ * const myMessage = new Message('Hello World');
153
+ *
154
+ * // same as
155
+ *
156
+ * const myOtherMessage = new Message()
157
+ * .write('Hello World')
158
+ * .center();
159
+ * ```
160
+ */
161
+ export default class Message {
162
+ constructor(message) {
163
+ this.cursor = [0, 0];
164
+ if (typeof message === 'string' && message) {
165
+ this.board = JSON.parse(JSON.stringify(EMPTY_BOARD));
166
+ this.write(message);
167
+ this.center();
168
+ }
169
+ else if (Array.isArray(message)) {
170
+ this.board = message;
171
+ }
172
+ else {
173
+ this.board = JSON.parse(JSON.stringify(EMPTY_BOARD));
174
+ }
175
+ }
176
+ static string2chars(word, options = {}) {
177
+ let chars = [];
178
+ const singleCharStrings = Message.splitter.splitGraphemes(word);
179
+ for (const char of singleCharStrings) {
180
+ chars.push(...this.char2char(char));
181
+ }
182
+ // trim emoji words if not disabled
183
+ if (options.removeUnsupportedWords !== false) {
184
+ chars = Message.removeEmojisFromChars(chars);
185
+ }
186
+ // replace -1 with fallback char
187
+ chars = chars.map(char => {
188
+ if (char >= 0) {
189
+ return char;
190
+ }
191
+ else if (char === -2) {
192
+ return 0;
193
+ }
194
+ else if (typeof options.fallbackChar === 'number') {
195
+ return options.fallbackChar;
196
+ }
197
+ else if (options.fallbackChar === null) {
198
+ return -1;
199
+ }
200
+ else {
201
+ return 60;
202
+ }
203
+ }).filter(char => char >= 0);
204
+ return chars;
205
+ }
206
+ static char2char(char) {
207
+ const fromMap = CHAR_MAP
208
+ .find(([mapChar]) => char === mapChar);
209
+ if (fromMap && Array.isArray(fromMap[1])) {
210
+ return fromMap[1];
211
+ }
212
+ return [-1];
213
+ }
214
+ static charToString(char) {
215
+ const entry = Object.values(CHAR_MAP)
216
+ .filter(([name]) => name.length <= 2)
217
+ .find(([, code]) => code[0] === char);
218
+ if (entry) {
219
+ return entry[0].toUpperCase() + (entry[0].length === 1 ? ' ' : '');
220
+ }
221
+ return '⚡︎ ';
222
+ }
223
+ static splitCharsIntoLines(chars, lineLength) {
224
+ // Array with splitting char (if any) and chars of the word
225
+ const words = [];
226
+ for (const char of chars) {
227
+ if (!words.length) {
228
+ words.push([null, []]);
229
+ }
230
+ const currentWord = words[words.length - 1];
231
+ if (char === 0) {
232
+ words.push([0, []]);
233
+ }
234
+ else if (char === 44) {
235
+ currentWord[1].push(char);
236
+ words.push([null, []]);
237
+ }
238
+ else {
239
+ currentWord[1].push(char);
240
+ }
241
+ }
242
+ const lines = [];
243
+ for (const [separator, word] of words) {
244
+ if (!lines.length) {
245
+ lines.push([]);
246
+ }
247
+ let currentLine = lines[lines.length - 1];
248
+ let charsLeft = lineLength[lines.length === 1 ? 0 : 1] - currentLine.length;
249
+ // start of line, word fits
250
+ if (!currentLine.length && word.length <= charsLeft) {
251
+ currentLine.push(...word);
252
+ }
253
+ // add separator and the whole word
254
+ else if (separator !== null && word.length + 1 <= charsLeft) {
255
+ currentLine.push(0, ...word);
256
+ }
257
+ else if (word.length <= charsLeft) {
258
+ currentLine.push(...word);
259
+ }
260
+ // no space for the word, write into next line
261
+ else if (word.length <= lineLength[1]) {
262
+ currentLine = [...word];
263
+ charsLeft = lineLength[1];
264
+ lines.push(currentLine);
265
+ }
266
+ // word too long for one line, start in
267
+ // current line and continue in next line
268
+ else {
269
+ if (charsLeft >= 3 && !currentLine.length) {
270
+ // No space required in front of long word
271
+ }
272
+ else if (charsLeft >= 4 && currentLine.length) {
273
+ // Add space for next word
274
+ currentLine.push(0);
275
+ charsLeft--;
276
+ }
277
+ else {
278
+ // No enough space for word, go to next line
279
+ currentLine = [];
280
+ charsLeft = lineLength[1];
281
+ lines.push(currentLine);
282
+ }
283
+ for (const char of word) {
284
+ currentLine.push(char);
285
+ charsLeft--;
286
+ if (charsLeft <= 1) {
287
+ currentLine.push(44);
288
+ currentLine = [];
289
+ charsLeft = lineLength[1];
290
+ lines.push(currentLine);
291
+ }
292
+ }
293
+ }
294
+ }
295
+ return lines;
296
+ }
297
+ static removeEmojisFromChars(chars) {
298
+ const words = [];
299
+ for (const char of chars) {
300
+ if (!words.length) {
301
+ words.push([]);
302
+ }
303
+ if (char === 0) {
304
+ words.push([]);
305
+ }
306
+ else {
307
+ words[words.length - 1].push(char);
308
+ }
309
+ }
310
+ words.forEach(chars => {
311
+ if (chars.length > 0 && chars[0] === -1) {
312
+ while (chars[0] < 0) {
313
+ chars.splice(0, 1);
314
+ }
315
+ }
316
+ if (chars.length > 0 && chars[chars.length - 1] === -1) {
317
+ while (chars.length > 0 && chars[chars.length - 1] < 0) {
318
+ chars.splice(chars.length - 1, 1);
319
+ }
320
+ }
321
+ });
322
+ const result = [];
323
+ words
324
+ .filter(chars => chars.length > 0)
325
+ .forEach(chars => {
326
+ if (result.length !== 0) {
327
+ result.push(0);
328
+ }
329
+ result.push(...chars);
330
+ });
331
+ return result;
332
+ }
333
+ static getColumnSizesFromData(rows, options = {}) {
334
+ if (!rows.length) {
335
+ return [];
336
+ }
337
+ const columns = rows[0].length;
338
+ const columnDefaultSizes = [];
339
+ rows.forEach((row, rowIndex) => {
340
+ if (row.length !== columns) {
341
+ throw new Error(`Unable to render table: Row ${rowIndex} has ${row.length} entries, but first row has ${columns}!`);
342
+ }
343
+ row.forEach((column, columnIndex) => {
344
+ columnDefaultSizes[columnIndex] = Math.max(columnDefaultSizes[columnIndex] || 0, this.string2chars(column, options).length);
345
+ });
346
+ });
347
+ const columnDefaultSum = columnDefaultSizes.reduce((a, b) => a + b, 0);
348
+ const columnBorders = rows[0].length - 1;
349
+ const factor = Math.max((BOARD_LINE_LENGTH - columnBorders) / columnDefaultSum, 1);
350
+ const columnSizes = columnDefaultSizes.map(size => Math.round(size * factor));
351
+ while (true) {
352
+ const size = columnSizes.reduce((a, b) => a + b, 0) + columnBorders;
353
+ if (size === BOARD_LINE_LENGTH) {
354
+ break;
355
+ }
356
+ const diff = BOARD_LINE_LENGTH - size < 0 ? -1 : 1;
357
+ const index = columnSizes.indexOf(diff < 0 ? Math.max(...columnSizes) : Math.min(...columnSizes));
358
+ if (index < 0) {
359
+ // This can actually never be achieved...
360
+ throw new Error('Unable to find max value in array…');
361
+ }
362
+ columnSizes[index] += diff;
363
+ }
364
+ return columnSizes;
365
+ }
366
+ get isEmpty() {
367
+ return !this.board.find(line => line.find(char => char !== 0));
368
+ }
369
+ /**
370
+ * Fills the board with the passed character or text. The text
371
+ * is repeated again and again until the board is completely filled.
372
+ */
373
+ fill(text = ' ') {
374
+ let pointer = 0;
375
+ const chars = Message.string2chars(text, { removeUnsupportedWords: false });
376
+ this.board.forEach((line) => {
377
+ line.forEach((char, charIndex) => {
378
+ line[charIndex] = chars[pointer];
379
+ pointer++;
380
+ if (pointer > chars.length - 1) {
381
+ pointer = 0;
382
+ }
383
+ });
384
+ });
385
+ return this;
386
+ }
387
+ /**
388
+ * Write a text on your new message. If your message is not empty it will continue
389
+ * where you last left off (`position: MessageWritePosition.CURRENT`). Alternatively
390
+ * you can continue on the next line or give an exact position.
391
+ *
392
+ * @param text
393
+ * @param options
394
+ */
395
+ write(text, options = {}) {
396
+ // Cursor blow board length? Just return…
397
+ if (!this.board[this.cursor[0]]) {
398
+ return this;
399
+ }
400
+ // Add new line if NEXT_LINE is set (except it's already in the first line)
401
+ if (options.position === MessageWritePosition.NEXT_LINE && (this.cursor[0] !== 0 || this.cursor[1] !== 0)) {
402
+ this.cursor[0]++;
403
+ this.cursor[1] = 0;
404
+ }
405
+ // Set cursor to given position
406
+ else if (typeof options.position === 'object') {
407
+ this.cursor[0] = options.position.line;
408
+ this.cursor[1] = options.position.row || 0;
409
+ }
410
+ // Add space before text as it
411
+ // will be rendered in the same line
412
+ if ((options.position === undefined || options.position === MessageWritePosition.CURRENT) &&
413
+ this.cursor[1] !== 0 && this.cursor[1] < BOARD_LINE_LENGTH - 1) {
414
+ this.board[this.cursor[0]].splice(this.cursor[1], 1, 0);
415
+ this.cursor[1] += 1;
416
+ }
417
+ // Figure out left indent
418
+ let indent = 0;
419
+ if (options.indent === true) {
420
+ indent = this.cursor[1];
421
+ }
422
+ else if (typeof options.indent === 'number' && options.indent >= 0 && options.indent <= BOARD_LINE_LENGTH - 5) {
423
+ indent = options.indent;
424
+ }
425
+ const linesOfText = text.split('\n');
426
+ let isFirstLine = true;
427
+ for (const lineOfText of linesOfText) {
428
+ const chars = Message.string2chars(lineOfText, options);
429
+ const charsLeftInLine = [
430
+ BOARD_LINE_LENGTH - this.cursor[1],
431
+ BOARD_LINE_LENGTH - indent
432
+ ];
433
+ if (!isFirstLine) {
434
+ this.cursor[0]++;
435
+ this.cursor[1] = indent;
436
+ }
437
+ if (typeof options.position === 'object' && options.position.width) {
438
+ charsLeftInLine[0] = Math.min(charsLeftInLine[0], options.position.width);
439
+ charsLeftInLine[1] = Math.min(charsLeftInLine[1], options.position.width - indent);
440
+ }
441
+ const linesOfChars = Message.splitCharsIntoLines(chars, charsLeftInLine);
442
+ for (const chars of linesOfChars) {
443
+ // Board is over, skip line…
444
+ if (!this.board[this.cursor[0]]) {
445
+ break;
446
+ }
447
+ // Add chars to current line and update cursor
448
+ this.board[this.cursor[0]].splice(this.cursor[1], chars.length, ...chars);
449
+ this.cursor[1] += chars.length;
450
+ // Add new line (and update cursor),
451
+ // if this wasn't the last line
452
+ if (chars !== linesOfChars[linesOfChars.length - 1]) {
453
+ this.cursor[0]++;
454
+ this.cursor[1] = indent;
455
+ }
456
+ }
457
+ isFirstLine = false;
458
+ }
459
+ return this;
460
+ }
461
+ /**
462
+ * Generate a table with the given data
463
+ *
464
+ * @example new Message().table([
465
+ * ['now', 'Daily'],
466
+ * ['13:00', 'Super Secret Meeting'],
467
+ * ['16:30', 'Awesome Presentation']
468
+ * ])
469
+ *
470
+ * #==============================================#
471
+ * # N O W D A I L Y #
472
+ * # #
473
+ * # 1 3 : 0 0 S U P E R S E C R E T #
474
+ * # M E E T I N G #
475
+ * # #
476
+ * # 1 6 : 3 0 A W E S O M E P R E S E N T - #
477
+ * #==============================================#
478
+ */
479
+ table(rows) {
480
+ const columnWidths = Message.getColumnSizesFromData(rows);
481
+ if (this.cursor[0] !== 0 || this.cursor[1] !== 0) {
482
+ this.cursor[0]++;
483
+ this.cursor[1] = 0;
484
+ }
485
+ rows.forEach(line => {
486
+ const lineStart = this.cursor[0];
487
+ let lineHeight = 1;
488
+ line.forEach((column, columnIndex) => {
489
+ const columnWidth = columnWidths[columnIndex];
490
+ const indent = columnWidths
491
+ .filter((width, index) => index < columnIndex)
492
+ .reduce((a, b) => a + b + 1, 0);
493
+ this.write(column, {
494
+ position: {
495
+ line: lineStart,
496
+ row: indent,
497
+ width: columnWidth
498
+ },
499
+ indent
500
+ });
501
+ lineHeight = Math.max(lineHeight, this.cursor[0] - lineStart + 1);
502
+ });
503
+ this.cursor[0] = lineStart + lineHeight + 1;
504
+ this.cursor[1] = 0;
505
+ });
506
+ return this;
507
+ }
508
+ /**
509
+ * Center the current message content
510
+ */
511
+ center() {
512
+ const space = [
513
+ this.board.findIndex(l => l.find(c => c !== 0)),
514
+ Math.min(...this.board.map(l => l.find(c => c !== 0) ? l.slice().reverse().findIndex(c => c !== 0) : l.length)),
515
+ this.board.slice().reverse().findIndex(l => l.find(c => c !== 0)),
516
+ Math.min(...this.board.map(l => l.find(c => c !== 0) ? l.findIndex(c => c !== 0) : l.length)),
517
+ ];
518
+ const padding = [
519
+ Math.floor((space[0] + space[2]) / 2),
520
+ Math.floor((space[1] + space[3]) / 2)
521
+ ];
522
+ // Move up/down
523
+ if (space[0] !== padding[0]) {
524
+ const add = padding[0] - space[0];
525
+ this.board.splice(add > 0 ? 0 : this.board.length, 0, ...this.board.splice(add > 0 ? this.board.length - add : 0, Math.abs(add)));
526
+ }
527
+ // Move left/right
528
+ if (space[3] !== padding[1]) {
529
+ const add = padding[1] - space[3];
530
+ this.board.forEach(line => {
531
+ line.splice(add > 0 ? 0 : line.length, 0, ...line.splice(add > 0 ? line.length - add : 0, Math.abs(add)));
532
+ });
533
+ }
534
+ }
535
+ toString() {
536
+ return '#=' + '='.repeat(BOARD_LINE_LENGTH * 2) + '=#\n' +
537
+ this.board.map(line => '# ' + line.map(char => Message.charToString(char)).join('') + ' #\n').join('') +
538
+ '#=' + '='.repeat(BOARD_LINE_LENGTH * 2) + '=#\n';
539
+ }
540
+ toCharArray() {
541
+ return JSON.parse(JSON.stringify(this.board));
542
+ }
543
+ }
544
+ Message.splitter = new GraphemeSplitter();
545
+ //# sourceMappingURL=message.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"message.js","sourceRoot":"","sources":["../src/message.ts"],"names":[],"mappings":"AAAA,OAAO,gBAAgB,MAAM,mBAAmB,CAAC;AACjD,OAAO,EAAE,iBAAiB,EAAE,WAAW,EAAuC,oBAAoB,EAAE,MAAM,YAAY,CAAC;AAGvH;;;GAGG;AACH,MAAM,CAAC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AAG,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAC1C,OAAO,CAAC,YAAY,CAAC,IAAI,CAAC,CAC7B,CAAC,IAAI,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,CAAC,IAAI,CAAC,EAAE,CAAC;YAC7B,IAAI,GAAG,GAAG,CAAC,MAAM,CAAC,iBAAiB,GAAG,CAAC,CAAC,GAAG,MAAM,CAAC;IAC1D,CAAC;IAED,WAAW;QACP,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IAClD,CAAC;;AAjcuB,gBAAQ,GAAG,IAAI,gBAAgB,EAAE,CAAC"}
@@ -0,0 +1,8 @@
1
+ import { Boards } from './types.js';
2
+ import Message from './message.js';
3
+ export default class MultipleBoards {
4
+ private readonly boards;
5
+ constructor(boards?: Boards);
6
+ push(...boards: Boards): void;
7
+ postMessage(message: Message | string): Promise<void>;
8
+ }
@@ -0,0 +1,25 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ export default class MultipleBoards {
11
+ constructor(boards = []) {
12
+ this.boards = boards;
13
+ }
14
+ push(...boards) {
15
+ boards.forEach(board => this.boards.push(board));
16
+ }
17
+ postMessage(message) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ for (const board of this.boards) {
20
+ yield board.postMessage(message);
21
+ }
22
+ });
23
+ }
24
+ }
25
+ //# sourceMappingURL=multiple-boards.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"multiple-boards.js","sourceRoot":"","sources":["../src/multiple-boards.ts"],"names":[],"mappings":";;;;;;;;;AAGA,MAAM,CAAC,OAAO,OAAO,cAAc;IAG/B,YAAa,SAAiB,EAAE;QAC5B,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACzB,CAAC;IAED,IAAI,CAAC,GAAG,MAAc;QAClB,MAAM,CAAC,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC;IACrD,CAAC;IAEK,WAAW,CAAE,OAAyB;;YACxC,KAAI,MAAM,KAAK,IAAI,IAAI,CAAC,MAAM,EAAE;gBAC5B,MAAM,KAAK,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;aACpC;QACL,CAAC;KAAA;CACJ"}
@@ -0,0 +1,10 @@
1
+ import Message from './message.js';
2
+ import type { RequestOptions } from './types.js';
3
+ export default class ReadWriteAPI {
4
+ private readonly key;
5
+ private readonly options;
6
+ constructor(key: string, options?: RequestOptions);
7
+ private request;
8
+ getCurrentMessage(): Promise<Message>;
9
+ postMessage(message: Message | string): Promise<void>;
10
+ }
@@ -0,0 +1,37 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Message from './message.js';
11
+ import { request } from './tools.js';
12
+ export default class ReadWriteAPI {
13
+ constructor(key, options) {
14
+ this.key = key;
15
+ this.options = options || {};
16
+ }
17
+ request(path, data) {
18
+ return __awaiter(this, void 0, void 0, function* () {
19
+ return request(`https://rw.vestaboard.com${path}`, {
20
+ 'X-Vestaboard-Read-Write-Key': this.key
21
+ }, data, this.options);
22
+ });
23
+ }
24
+ getCurrentMessage() {
25
+ return __awaiter(this, void 0, void 0, function* () {
26
+ const response = yield this.request('/');
27
+ return new Message(JSON.parse(response.currentMessage.layout));
28
+ });
29
+ }
30
+ postMessage(message) {
31
+ return __awaiter(this, void 0, void 0, function* () {
32
+ const msgObj = typeof message === 'string' ? new Message(message) : message;
33
+ yield this.request('/', JSON.stringify(msgObj.toCharArray()));
34
+ });
35
+ }
36
+ }
37
+ //# sourceMappingURL=read-write-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read-write-api.js","sourceRoot":"","sources":["../src/read-write-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAGrC,MAAM,CAAC,OAAO,OAAO,YAAY;IAI7B,YAAa,GAAW,EAAE,OAAwB;QAC9C,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IACjC,CAAC;IAEa,OAAO,CAAK,IAAY,EAAE,IAAa;;YACjD,OAAO,OAAO,CAAC,4BAA4B,IAAI,EAAE,EAAE;gBAC/C,6BAA6B,EAAE,IAAI,CAAC,GAAG;aAC1C,EAAE,IAAI,EAAE,IAAI,CAAC,OAAO,CAAC,CAAC;QAC3B,CAAC;KAAA;IAEK,iBAAiB;;YACnB,MAAM,QAAQ,GAAG,MAAM,IAAI,CAAC,OAAO,CAA8B,GAAG,CAAC,CAAC;YACtE,OAAO,IAAI,OAAO,CAAC,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC,CAAC;QACnE,CAAC;KAAA;IAEK,WAAW,CAAE,OAAyB;;YACxC,MAAM,MAAM,GAAG,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC;YAC5E,MAAM,IAAI,CAAC,OAAO,CAAO,GAAG,EACxB,IAAI,CAAC,SAAS,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,CACvC,CAAC;QACN,CAAC;KAAA;CACJ"}
@@ -0,0 +1,15 @@
1
+ import Message from './message.js';
2
+ import type { SubscriptionPostResponse, Subscriptions, Viewer } from './types.js';
3
+ import { RequestOptions } from './types.js';
4
+ export default class SubscriptionAPI {
5
+ private readonly key;
6
+ private readonly secret;
7
+ private readonly options;
8
+ constructor(key: string, secret: string, options?: RequestOptions);
9
+ private request;
10
+ getViewer(): Promise<Viewer>;
11
+ getSubscriptions(): Promise<Subscriptions>;
12
+ postMessage(message: Message | string): Promise<SubscriptionPostResponse[]>;
13
+ postMessage(message: Message | string, subscriptionId: string): Promise<SubscriptionPostResponse>;
14
+ postMessage(message: Message | string, subscriptionIds: string[]): Promise<SubscriptionPostResponse[]>;
15
+ }
@@ -0,0 +1,65 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import Message from './message.js';
11
+ import { request } from './tools.js';
12
+ export default class SubscriptionAPI {
13
+ constructor(key, secret, options) {
14
+ this.key = key;
15
+ this.secret = secret;
16
+ this.options = options || {};
17
+ }
18
+ request(path, data) {
19
+ return __awaiter(this, void 0, void 0, function* () {
20
+ return request(`https://platform.vestaboard.com${path}`, {
21
+ 'X-Vestaboard-Api-Key': this.key,
22
+ 'X-Vestaboard-Api-Secret': this.secret
23
+ }, data, this.options);
24
+ });
25
+ }
26
+ getViewer() {
27
+ return __awaiter(this, void 0, void 0, function* () {
28
+ return yield this.request('/viewer');
29
+ });
30
+ }
31
+ getSubscriptions() {
32
+ return __awaiter(this, void 0, void 0, function* () {
33
+ return yield this.request('/subscriptions');
34
+ });
35
+ }
36
+ postMessage(message, subscriptionIds) {
37
+ return __awaiter(this, void 0, void 0, function* () {
38
+ let singleMode = false;
39
+ const ids = [];
40
+ const msgObj = typeof message === 'string' ? new Message(message) : message;
41
+ if (typeof subscriptionIds === 'string') {
42
+ singleMode = true;
43
+ ids.push(subscriptionIds);
44
+ }
45
+ else if (Array.isArray(subscriptionIds)) {
46
+ ids.push(...subscriptionIds);
47
+ }
48
+ else {
49
+ const subscriptions = yield this.getSubscriptions();
50
+ ids.push(...subscriptions.subscriptions.map(subscription => subscription._id));
51
+ }
52
+ const results = [];
53
+ for (const id of ids) {
54
+ results.push(yield this.request(`/subscriptions/${id}/message`, {
55
+ characters: msgObj.toCharArray()
56
+ }));
57
+ }
58
+ if (singleMode) {
59
+ return results[0];
60
+ }
61
+ return results;
62
+ });
63
+ }
64
+ }
65
+ //# sourceMappingURL=subscription-api.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"subscription-api.js","sourceRoot":"","sources":["../src/subscription-api.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,OAAO,MAAM,cAAc,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,MAAM,YAAY,CAAC;AAIrC,MAAM,CAAC,OAAO,OAAO,eAAe;IAKhC,YAAa,GAAW,EAAE,MAAc,EAAE,OAAwB;QAC9D,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,OAAO,GAAG,OAAO,IAAI,EAAE,CAAC;IAC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CAAC,IAAI,CACR,MAAM,IAAI,CAAC,OAAO,CAA2B,kBAAkB,EAAE,UAAU,EAAE;oBACzE,UAAU,EAAE,MAAM,CAAC,WAAW,EAAE;iBACnC,CAAC,CACL,CAAC;aACL;YACD,IAAI,UAAU,EAAE;gBACZ,OAAO,OAAO,CAAC,CAAC,CAAC,CAAC;aACrB;YAED,OAAO,OAAO,CAAC;QACnB,CAAC;KAAA;CACJ"}
@@ -0,0 +1,2 @@
1
+ import { RequestOptions } from './types.js';
2
+ export declare function request<T>(url: string, headers: Record<string, string>, data?: Record<string, unknown> | string, options?: RequestOptions): Promise<T>;
package/dist/tools.js ADDED
@@ -0,0 +1,48 @@
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ import fetch from 'node-fetch';
11
+ export function request(url, headers, data, options = {}) {
12
+ return __awaiter(this, void 0, void 0, function* () {
13
+ const method = data === undefined ? 'GET' : 'POST';
14
+ if (data !== undefined) {
15
+ Object.assign(headers, {
16
+ 'Content-Type': 'application/json'
17
+ });
18
+ }
19
+ const init = {
20
+ method,
21
+ headers
22
+ };
23
+ if (data !== undefined && typeof data === 'string') {
24
+ init.body = data;
25
+ }
26
+ else if (data !== undefined) {
27
+ init.body = JSON.stringify(data);
28
+ }
29
+ let response = null;
30
+ for (let i = 0; i < 10; i++) {
31
+ response = yield (options.fetch || fetch)(url, init);
32
+ if (response.ok) {
33
+ break;
34
+ }
35
+ yield new Promise(resolve => setTimeout(resolve, 1000));
36
+ }
37
+ /* c8 ignore next */
38
+ if (!(response === null || response === void 0 ? void 0 : response.ok)) {
39
+ throw new Error('HTTP Request failed');
40
+ }
41
+ if (options.parseResponse === false) {
42
+ return undefined;
43
+ }
44
+ const json = yield response.json();
45
+ return json;
46
+ });
47
+ }
48
+ //# sourceMappingURL=tools.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tools.js","sourceRoot":"","sources":["../src/tools.ts"],"names":[],"mappings":";;;;;;;;;AACA,OAAO,KAAK,MAAM,YAAY,CAAC;AAE/B,MAAM,UAAgB,OAAO,CACzB,GAAW,EACX,OAA+B,EAC/B,IAAuC,EACvC,UAA0B,EAAE;;QAE5B,MAAM,MAAM,GAAG,IAAI,KAAK,SAAS,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC;QACnD,IAAI,IAAI,KAAK,SAAS,EAAE;YACpB,MAAM,CAAC,MAAM,CAAC,OAAO,EAAE;gBACnB,cAAc,EAAE,kBAAkB;aACrC,CAAC,CAAC;SACN;QAED,MAAM,IAAI,GAAwB;YAC9B,MAAM;YACN,OAAO;SACV,CAAC;QACF,IAAG,IAAI,KAAK,SAAS,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE;YAC/C,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC;SACpB;aACI,IAAG,IAAI,KAAK,SAAS,EAAE;YACxB,IAAI,CAAC,IAAI,GAAG,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;SACpC;QAED,IAAI,QAAQ,GAAgC,IAAI,CAAC;QACjD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;YACzB,QAAQ,GAAG,MAAM,CAAC,OAAO,CAAC,KAAK,IAAI,KAAK,CAAC,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;YACrD,IAAG,QAAQ,CAAC,EAAE,EAAE;gBACZ,MAAM;aACT;YAED,MAAM,IAAI,OAAO,CAAC,OAAO,CAAC,EAAE,CAAC,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;SAC3D;QAED,oBAAoB;QACpB,IAAG,CAAC,CAAA,QAAQ,aAAR,QAAQ,uBAAR,QAAQ,CAAE,EAAE,CAAA,EAAE;YACd,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;SAC1C;QAED,IAAG,OAAO,CAAC,aAAa,KAAK,KAAK,EAAE;YAChC,OAAO,SAAyB,CAAC;SACpC;QAED,MAAM,IAAI,GAAG,MAAM,QAAQ,CAAC,IAAI,EAAE,CAAC;QACnC,OAAO,IAAS,CAAC;IACrB,CAAC;CAAA"}
@@ -0,0 +1,106 @@
1
+ import SubscriptionAPI from './subscription-api.js';
2
+ import ReadWriteAPI from './read-write-api.js';
3
+ import LocalAPI from './local-api.js';
4
+ export declare const BOARD_LINE_LENGTH = 22;
5
+ export declare const BOARD_LINES = 6;
6
+ export declare type BoardCharLine = [
7
+ number,
8
+ number,
9
+ number,
10
+ number,
11
+ number,
12
+ number,
13
+ number,
14
+ number,
15
+ number,
16
+ number,
17
+ number,
18
+ number,
19
+ number,
20
+ number,
21
+ number,
22
+ number,
23
+ number,
24
+ number,
25
+ number,
26
+ number,
27
+ number,
28
+ number
29
+ ];
30
+ export declare type BoardCharArray = [
31
+ BoardCharLine,
32
+ BoardCharLine,
33
+ BoardCharLine,
34
+ BoardCharLine,
35
+ BoardCharLine,
36
+ BoardCharLine
37
+ ];
38
+ export interface MessageWriteCoords {
39
+ line: number;
40
+ row?: number;
41
+ width?: number;
42
+ }
43
+ export declare enum MessageWritePosition {
44
+ CURRENT = 0,
45
+ NO_SPACE_BETWEEN = 1,
46
+ NEXT_LINE = 2
47
+ }
48
+ export interface MessageWriteOptions {
49
+ position?: MessageWriteCoords | MessageWritePosition;
50
+ indent?: boolean | number;
51
+ fallbackChar?: number | null;
52
+ removeUnsupportedWords?: boolean;
53
+ }
54
+ export interface RequestFetchOptions {
55
+ body?: string;
56
+ headers?: Record<string, string>;
57
+ method?: string;
58
+ }
59
+ export interface RequestFetchResponse {
60
+ readonly ok: boolean;
61
+ readonly status: number;
62
+ readonly statusText: string;
63
+ json(): Promise<unknown>;
64
+ }
65
+ export declare type RequestOptionsFetch = (url: string, init?: RequestFetchOptions) => Promise<RequestFetchResponse>;
66
+ export interface RequestOptions {
67
+ fetch?: RequestOptionsFetch;
68
+ parseResponse?: boolean;
69
+ }
70
+ export interface Installation {
71
+ _id: string;
72
+ installable?: {
73
+ _id: string;
74
+ };
75
+ }
76
+ export interface Viewer {
77
+ type: string;
78
+ _id: string;
79
+ _created: string;
80
+ installation: {
81
+ _id: string;
82
+ };
83
+ }
84
+ export interface Subscription {
85
+ _id: string;
86
+ _created: string;
87
+ installation: Installation;
88
+ boards: Array<{
89
+ _id: string;
90
+ }>;
91
+ }
92
+ export interface Subscriptions {
93
+ subscriptions: Subscription[];
94
+ }
95
+ export interface SubscriptionPostResponse {
96
+ message: {
97
+ id: string;
98
+ created: number;
99
+ };
100
+ }
101
+ export interface ReadWriteGetMessageResponse {
102
+ currentMessage: {
103
+ layout: string;
104
+ };
105
+ }
106
+ export declare type Boards = Array<LocalAPI | ReadWriteAPI | SubscriptionAPI>;
package/dist/types.js ADDED
@@ -0,0 +1,9 @@
1
+ export const BOARD_LINE_LENGTH = 22;
2
+ export const BOARD_LINES = 6;
3
+ export var MessageWritePosition;
4
+ (function (MessageWritePosition) {
5
+ MessageWritePosition[MessageWritePosition["CURRENT"] = 0] = "CURRENT";
6
+ MessageWritePosition[MessageWritePosition["NO_SPACE_BETWEEN"] = 1] = "NO_SPACE_BETWEEN";
7
+ MessageWritePosition[MessageWritePosition["NEXT_LINE"] = 2] = "NEXT_LINE";
8
+ })(MessageWritePosition || (MessageWritePosition = {}));
9
+ //# sourceMappingURL=types.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAIA,MAAM,CAAC,MAAM,iBAAiB,GAAG,EAAE,CAAC;AACpC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,CAAC;AA0C7B,MAAM,CAAN,IAAY,oBAIX;AAJD,WAAY,oBAAoB;IAC5B,qEAAO,CAAA;IACP,uFAAgB,CAAA;IAChB,yEAAS,CAAA;AACb,CAAC,EAJW,oBAAoB,KAApB,oBAAoB,QAI/B"}
package/package.json ADDED
@@ -0,0 +1,62 @@
1
+ {
2
+ "author": "Sebastian Pekarek <mail@sebbo.net>",
3
+ "bugs": {
4
+ "url": "https://github.com/sebbo2002/vestaboard/issues"
5
+ },
6
+ "dependencies": {
7
+ "grapheme-splitter": "^1.0.4",
8
+ "node-fetch": "^3.2.9"
9
+ },
10
+ "description": "Just another client for the Vestaboard APIs.",
11
+ "devDependencies": {
12
+ "@amanda-mitchell/semantic-release-npm-multiple": "^3.5.0",
13
+ "@qiwi/semantic-release-gh-pages-plugin": "^5.2.3",
14
+ "@semantic-release/changelog": "^6.0.1",
15
+ "@semantic-release/exec": "^6.0.3",
16
+ "@semantic-release/git": "^10.0.1",
17
+ "@types/express": "^4.17.13",
18
+ "@types/mocha": "^9.1.1",
19
+ "@types/node": "^18.0.0",
20
+ "@typescript-eslint/eslint-plugin": "^5.30.0",
21
+ "@typescript-eslint/parser": "^5.30.0",
22
+ "c8": "^7.11.3",
23
+ "dotenv": "^16.0.1",
24
+ "eslint": "^8.18.0",
25
+ "eslint-plugin-jsonc": "^2.3.0",
26
+ "esm": "^3.2.25",
27
+ "license-checker": "^25.0.1",
28
+ "mocha": "^10.0.0",
29
+ "mochawesome": "^7.1.3",
30
+ "semantic-release-license": "^1.0.3",
31
+ "source-map-support": "^0.5.21",
32
+ "ts-node": "^10.8.1",
33
+ "typedoc": "^0.23.2",
34
+ "typescript": "^4.7.4"
35
+ },
36
+ "engines": {
37
+ "node": "^12.20.0 || >=14.13.1"
38
+ },
39
+ "exports": "./dist/index.js",
40
+ "files": [
41
+ "/dist"
42
+ ],
43
+ "homepage": "https://github.com/sebbo2002/vestaboard#readme",
44
+ "license": "MIT",
45
+ "name": "@sebbo2002/vestaboard",
46
+ "repository": {
47
+ "type": "git",
48
+ "url": "git+https://github.com/sebbo2002/vestaboard.git"
49
+ },
50
+ "scripts": {
51
+ "build": "tsc",
52
+ "build-all": "./.github/workflows/build.sh",
53
+ "coverage": "c8 mocha",
54
+ "develop": "ts-node ./src/bin/start.ts",
55
+ "license-check": "license-checker --production --summary",
56
+ "lint": "eslint . --ext .ts,.json",
57
+ "start": "node ./dist/bin/start.js",
58
+ "test": "mocha"
59
+ },
60
+ "type": "module",
61
+ "version": "1.0.0-develop.1"
62
+ }