@docusaurus/utils 0.0.0-5939 → 0.0.0-5941

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,5 +13,8 @@ export declare function simpleHash(str: string, length: number): string;
13
13
  * collision. Also removes part of the string if its larger than the allowed
14
14
  * filename per OS, avoiding `ERRNAMETOOLONG` error.
15
15
  */
16
- export declare function docuHash(str: string): string;
16
+ export declare function docuHash(strInput: string, options?: {
17
+ hashExtra?: string;
18
+ hashLength?: number;
19
+ }): string;
17
20
  //# sourceMappingURL=hashUtils.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;GAIG;AACH,wBAAgB,QAAQ,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAU5C"}
1
+ {"version":3,"file":"hashUtils.d.ts","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAMH,sDAAsD;AACtD,wBAAgB,OAAO,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAE3C;AAED,gEAAgE;AAChE,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE9D;AAGD;;;;GAIG;AACH,wBAAgB,QAAQ,CACtB,QAAQ,EAAE,MAAM,EAChB,OAAO,CAAC,EAAE;IAGR,SAAS,CAAC,EAAE,MAAM,CAAC;IAEnB,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,GACA,MAAM,CAkBR"}
package/lib/hashUtils.js CHANGED
@@ -27,11 +27,17 @@ exports.simpleHash = simpleHash;
27
27
  * collision. Also removes part of the string if its larger than the allowed
28
28
  * filename per OS, avoiding `ERRNAMETOOLONG` error.
29
29
  */
30
- function docuHash(str) {
31
- if (str === '/') {
30
+ function docuHash(strInput, options) {
31
+ // TODO check this historical behavior
32
+ // I'm not sure it makes sense to keep it...
33
+ if (strInput === '/' && typeof options?.hashExtra === 'undefined') {
32
34
  return 'index';
33
35
  }
34
- const shortHash = simpleHash(str, 3);
36
+ const str = strInput === '/' ? 'index' : strInput;
37
+ const hashExtra = options?.hashExtra ?? '';
38
+ const hashLength = options?.hashLength ?? 3;
39
+ const stringToHash = str + hashExtra;
40
+ const shortHash = simpleHash(stringToHash, hashLength);
35
41
  const parsedPath = `${lodash_1.default.kebabCase(str)}-${shortHash}`;
36
42
  if ((0, pathUtils_1.isNameTooLong)(parsedPath)) {
37
43
  return `${(0, pathUtils_1.shortName)(lodash_1.default.kebabCase(str))}-${shortHash}`;
@@ -1 +1 @@
1
- {"version":3,"file":"hashUtils.js","sourceRoot":"","sources":["../src/hashUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,mCAAkC;AAClC,4DAAuB;AACvB,2CAAqD;AAErD,sDAAsD;AACtD,SAAgB,OAAO,CAAC,GAAW;IACjC,OAAO,IAAA,mBAAU,EAAC,KAAK,CAAC,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;AACrD,CAAC;AAFD,0BAEC;AAED,gEAAgE;AAChE,SAAgB,UAAU,CAAC,GAAW,EAAE,MAAc;IACpD,OAAO,OAAO,CAAC,GAAG,CAAC,CAAC,SAAS,CAAC,CAAC,EAAE,MAAM,CAAC,CAAC;AAC3C,CAAC;AAFD,gCAEC;AAED,+DAA+D;AAC/D;;;;GAIG;AACH,SAAgB,QAAQ,CAAC,GAAW;IAClC,IAAI,GAAG,KAAK,GAAG,EAAE,CAAC;QAChB,OAAO,OAAO,CAAC;IACjB,CAAC;IACD,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E,CAAC;IAC3C,MAAM,UAAU,GAAG,OAAO,EAAE,UAAU,IAAI,CAAC,CAAC;IAE5C,MAAM,YAAY,GAAG,GAAG,GAAG,SAAS,CAAC;IACrC,MAAM,SAAS,GAAG,UAAU,CAAC,YAAY,EAAE,UAAU,CAAC,CAAC;IACvD,MAAM,UAAU,GAAG,GAAG,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,IAAI,SAAS,EAAE,CAAC;IACtD,IAAI,IAAA,yBAAa,EAAC,UAAU,CAAC,EAAE,CAAC;QAC9B,OAAO,GAAG,IAAA,qBAAS,EAAC,gBAAC,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,IAAI,SAAS,EAAE,CAAC;IACvD,CAAC;IACD,OAAO,UAAU,CAAC;AACpB,CAAC;AA3BD,4BA2BC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/utils",
3
- "version": "0.0.0-5939",
3
+ "version": "0.0.0-5941",
4
4
  "description": "Node utility functions for Docusaurus packages.",
5
5
  "main": "./lib/index.js",
6
6
  "types": "./lib/index.d.ts",
@@ -18,8 +18,8 @@
18
18
  },
19
19
  "license": "MIT",
20
20
  "dependencies": {
21
- "@docusaurus/logger": "0.0.0-5939",
22
- "@docusaurus/utils-common": "0.0.0-5939",
21
+ "@docusaurus/logger": "0.0.0-5941",
22
+ "@docusaurus/utils-common": "0.0.0-5941",
23
23
  "@svgr/webpack": "^8.1.0",
24
24
  "escape-string-regexp": "^4.0.0",
25
25
  "file-loader": "^6.2.0",
@@ -42,7 +42,7 @@
42
42
  "node": ">=18.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@docusaurus/types": "0.0.0-5939",
45
+ "@docusaurus/types": "0.0.0-5941",
46
46
  "@types/dedent": "^0.7.0",
47
47
  "@types/github-slugger": "^1.3.0",
48
48
  "@types/micromatch": "^4.0.2",
@@ -58,5 +58,5 @@
58
58
  "optional": true
59
59
  }
60
60
  },
61
- "gitHead": "e192aae8dee40f308af03a5e2050407cbd285c7d"
61
+ "gitHead": "a7af113c6e6ce762ad4ac764fb89a32252600e82"
62
62
  }
package/src/hashUtils.ts CHANGED
@@ -25,11 +25,28 @@ export function simpleHash(str: string, length: number): string {
25
25
  * collision. Also removes part of the string if its larger than the allowed
26
26
  * filename per OS, avoiding `ERRNAMETOOLONG` error.
27
27
  */
28
- export function docuHash(str: string): string {
29
- if (str === '/') {
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') {
30
41
  return 'index';
31
42
  }
32
- const shortHash = simpleHash(str, 3);
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);
33
50
  const parsedPath = `${_.kebabCase(str)}-${shortHash}`;
34
51
  if (isNameTooLong(parsedPath)) {
35
52
  return `${shortName(_.kebabCase(str))}-${shortHash}`;