(
strInput: string,
options?: {
// String that contributes to the hash value
// but does not contribute to the returned string
hashExtra?: string;
// Length of the hash to append
hashLength?: number;
},
)
| 26 | * filename per OS, avoiding `ERRNAMETOOLONG` error. |
| 27 | */ |
| 28 | export function docuHash( |
| 29 | strInput: string, |
| 30 | options?: { |
| 31 | // String that contributes to the hash value |
| 32 | // but does not contribute to the returned string |
| 33 | hashExtra?: string; |
| 34 | // Length of the hash to append |
| 35 | hashLength?: number; |
| 36 | }, |
| 37 | ): string { |
| 38 | // TODO check this historical behavior |
| 39 | // I'm not sure it makes sense to keep it... |
| 40 | if (strInput === '/' && typeof options?.hashExtra === 'undefined') { |
| 41 | return 'index'; |
| 42 | } |
| 43 | const str = strInput === '/' ? 'index' : strInput; |
| 44 | |
| 45 | const hashExtra = options?.hashExtra ?? ''; |
| 46 | const hashLength = options?.hashLength ?? 3; |
| 47 | |
| 48 | const stringToHash = str + hashExtra; |
| 49 | const shortHash = simpleHash(stringToHash, hashLength); |
| 50 | const parsedPath = `${_.kebabCase(str)}-${shortHash}`; |
| 51 | if (isNameTooLong(parsedPath)) { |
| 52 | return `${shortName(_.kebabCase(str))}-${shortHash}`; |
| 53 | } |
| 54 | return parsedPath; |
| 55 | } |
no test coverage detected
searching dependent graphs…