1import { compose, strSplice } from 'lib/lib';
2import { convertToInt } from 'lib/convertToInt';
4const HEX_PREFIX = '0x';
6const TICKET_MAX_BYTE_LEN = 32; // tickets can be as large as 32 bytes
7const PAT_BLOCK_CHAR_LENGTH = 6; // pat{p,q} blocks are 6 characters long
10 (s?: string | undefined): string | undefined;
13export const buildFormatter = (formatters: Array<Formatter> = []) =>
14 compose(...formatters.reverse());
17 * inserts a ~ or - before every pat block
19export const ensurePatFormat = (s?: string) => {
20 // bail if falsy or empty string, nothing to do
21 if (!s || s.length === 0) {
25 // ensure there's a dash every 6 + 1 characters
26 const dashAt = (i: number) => i * (PAT_BLOCK_CHAR_LENGTH + 1);
27 const maxBlocks = TICKET_MAX_BYTE_LEN / 2;
29 // for every index that may need a separator
30 for (let i = 0; i !== maxBlocks; i++) {
31 const dashIndex = dashAt(i);
33 // if the string is too short to have a separator here, we're done
34 if (s.length - 1 < dashIndex) {
38 // insert the separator at the correct index if not already there
39 const sep = i === 0 ? '~' : '-';
40 if (s.charAt(dashIndex) !== sep) {
41 s = strSplice(s, dashIndex, sep);
48export const ensureHexPrefix = (s?: string) => {
49 if (!s || s.length < HEX_PREFIX.length) {
53 return s.indexOf(HEX_PREFIX) !== 0 ? `${HEX_PREFIX}${s}` : s;
56export const convertToNumber = (s?: string) => {
62 return convertToInt(s, 10);
68export const downcase = (s?: string) => {
73 return s.toLowerCase();
76export const stripHexPrefix = (s?: string) => {
81 return s.toLowerCase().indexOf(HEX_PREFIX) === 0
82 ? s.slice(HEX_PREFIX.length)
86export const ensureSigPrefix = (s?: string) => {
87 if (!s || s.length < SIG_PREFIX.length) {
91 return s.indexOf(SIG_PREFIX) !== 0 ? `${SIG_PREFIX}${s}` : s;
94export const stripSigPrefix = (s: string) => {
99 return s.toLowerCase().indexOf(SIG_PREFIX) === 0
100 ? s.slice(SIG_PREFIX.length)
104export const ticketToSegments = (ticket: string): string[] => {
105 return stripSigPrefix(ticket).split('-');
108export const ticketFromSegments = (segments: string[]): string => {
109 return ensureSigPrefix(segments.join('-'));
112export const capitalize = (s: string) => {
113 if (!s || s === '') {
117 return s.charAt(0).toUpperCase() + s.slice(1);
120export const titleize = (s?: string): string => {
124 .map(_s => capitalize(_s))
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list