@@ -1,39 +1,33 @@
1import { compose, strSplice } from 'lib/lib';
1import { compose, strSplice } from 'lib/lib';
3+const TICKET_MAX_BYTE_LEN = 32; // tickets can be as large as 32 bytes
3export const buildFormatter = (formatters = []) =>
5export const buildFormatter = (formatters = []) =>
4 compose(...formatters.reverse());
6 compose(...formatters.reverse());
6−export const prependSig = s => {
7− if (!s || s.length === 0) {
11− return s.charAt(0) === '~' ? s : `~${s}`;
15− * inserts a - every 7 characters
9+ * inserts a ~ or - every 7 characters
16− * (must be preceeded by prependSig to work correctly)
17− * @param {number} maxByteLength the maximum number of patq blocks to have in a string
19−export const ensurePatQDashes = maxByteLength => s => {
11+export const ensurePatFormat = s => {
20 if (!s || s.length === 0) {
12 if (!s || s.length === 0) {
21 return s || '';
13 return s || '';
24 // ensure there's a dash every 6 + 1 characters
16 // ensure there's a dash every 6 + 1 characters
25 const dashAt = i => i * (6 + 1);
17 const dashAt = i => i * (6 + 1);
26− const maxBlocks = maxByteLength / 2;
18+ const maxBlocks = TICKET_MAX_BYTE_LEN / 2;
28− for (let i = 1; i !== maxBlocks; i++) {
20+ for (let i = 0; i !== maxBlocks; i++) {
29 const dashIndex = dashAt(i);
21 const dashIndex = dashAt(i);
31 if (s.length - 1 < dashIndex) {
23 if (s.length - 1 < dashIndex) {
27+ const sep = i === 0 ? '~' : '-';
35− if (s.charAt(dashIndex) !== '-') {
29+ if (s.charAt(dashIndex) !== sep) {
36− s = strSplice(s, dashIndex, '-');
30+ s = strSplice(s, dashIndex, sep);