I have an array of string unique ids from a Firebase database, one of which looks like this: QXgZI3JB72Zf1qzeawIdxHSsPa62
I want to print these ids to the user, but first I'd like to first shorten the ids to around 7 characters long minimum, but have it go over that length in case two shortened ids end up becoming equal. That way, if somebody wants to refer to a specific id, they can use the shortened version without accidentally referring to multiple things.
Is there any way to accomplish this?
To get a better idea of what I'm talking about, refer to the git
command git rev-parse
(docs), which has the --short
flag that cuts a commit hash to at least 7 characters long (but will allow it to be longer in case it's no longer unique):
Instead of outputting the full SHA-1 values of object names try to abbreviate them to a shorter unique name.