This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Given a source directory and a target filename, return the relative | |
| * file path from source to target. | |
| * @param source {String} directory path to start from for traversal | |
| * @param target {String} directory path and filename to seek from source | |
| * @return Relative path (e.g. "../../style.css") as {String} | |
| */ | |
| function getRelativePath(source, target) { | |
| var sep = (source.indexOf("/") !== -1) ? "/" : "\\", | |
| targetArr = target.split(sep), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Since ES6 Map()'s' retain their order of insertion, it can sometimes be useful to get the last item or value inserted: | |
| export const getLastItemInMap = map => Array.from(map)[map.size-1] | |
| export const getLastKeyInMap = map => Array.from(map)[map.size-1][0] | |
| export const getLastValueInMap = map => Array.from(map)[map.size-1][1] | |
| // Obviously getLastKey and getLastValue can reuse getLastItem, but for maximum portability I opted for verbosity. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| pub fn header(otext, divider string) string { | |
| cols, _ := get_terminal_size() | |
| mut text := otext | |
| if text.len > 0 { | |
| text = ' $text ' | |
| } | |
| // clip the text if it is too long | |
| text = if cols > text.len + 1 + 2*divider.len { text } else { text[0..cols-(1+2*divider.len)] } | |
| // make the text align with the terminal size: | |
| if (text.len % 2) != (cols % 2 ) { |
OlderNewer