1import { compose, strSplice } from 'lib/lib';
3const HEX_PREFIX = '0x';
4const TICKET_MAX_BYTE_LEN = 32; // tickets can be as large as 32 bytes
5const PAT_BLOCK_CHAR_LENGTH = 6; // pat{p,q} blocks are 6 characters long
7export const buildFormatter = (formatters = []) =>
8 compose(...formatters.reverse());
11 * inserts a ~ or - before every pat block
13export const ensurePatFormat = s => {
14 // bail if falsy or empty string, nothing to do
15 if (!s || s.length === 0) {
19 // ensure there's a dash every 6 + 1 characters
20 const dashAt = i => i * (PAT_BLOCK_CHAR_LENGTH + 1);
21 const maxBlocks = TICKET_MAX_BYTE_LEN / 2;
23 // for every index that may need a separator
24 for (let i = 0; i !== maxBlocks; i++) {
25 const dashIndex = dashAt(i);
27 // if the string is too short to have a separator here, we're done
28 if (s.length - 1 < dashIndex) {
32 // insert the separator at the correct index if not already there
33 const sep = i === 0 ? '~' : '-';
34 if (s.charAt(dashIndex) !== sep) {
35 s = strSplice(s, dashIndex, sep);
42export const ensureHexPrefix = s => {
43 if (!s || s.length < HEX_PREFIX.length) {
47 return s.indexOf(HEX_PREFIX) !== 0 ? `${HEX_PREFIX}${s}` : s;
50export const convertToNumber = s => {
52 return parseInt(s, 10);
58export const downcase = s => {
63 return s.toLowerCase();
66export const stripHexPrefix = s => {
71 return s.toLowerCase().indexOf(HEX_PREFIX) === 0
72 ? s.slice(HEX_PREFIX.length)
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