INNER CODE UNIT · TypeScript
basename
modem-dev/hunk · packages/hunk-git/src/index.ts:59
function basename(path: string) {
return path.split(/[\\/]/).filter(Boolean).pop() ?? path;
}
const GIT_SHORT_OBJECT_ID_LENGTH = 7;
const FULL_GIT_OBJECT_ID = /^(?:[0-9a-f]{40}|[0-9a-f]{64})$/i;
const GIT_RANGE = /^(.*?)(\.\.\.?)(.*)$/;
/** Shorten one complete Git object ID while preserving every named revision spelling. */
function shortenGitObjectId(revision: string) {
return FULL_GIT_OBJECT_ID.test(revision)
? revision.slice(0, GIT_SHORT_OBJECT_ID_LENGTH)
: revision;
}
/** Shorten full Git object IDs in a display range while preserving named revisions. */
export function describeGitDiffTitleRange(input: {
readonly range?: string;