MCPcopy
hub / github.com/facebook/docusaurus / docuHash

Function docuHash

packages/docusaurus-utils/src/hashUtils.ts:28–55  ·  view source on GitHub ↗
(
  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;
  },
)

Source from the content-addressed store, hash-verified

26 * filename per OS, avoiding `ERRNAMETOOLONG` error.
27 */
28export 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}

Callers 10

createBlogMDXLoaderRuleFunction · 0.90
buildAllRoutesFunction · 0.90
hashUtils.test.tsFile · 0.90
createDocsMDXLoaderRuleFunction · 0.90
buildVersionDocRoutesFunction · 0.90
createPagesMDXLoaderRuleFunction · 0.90
buildMDXPageRouteFunction · 0.90
genChunkNameFunction · 0.90
configureWebpackFunction · 0.90

Calls 3

isNameTooLongFunction · 0.90
shortNameFunction · 0.90
simpleHashFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…