@azerion/bunosaurus-utils-common 0.0.0-stage → 4.0.0

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.
package/README.md CHANGED
@@ -1,3 +1,3 @@
1
- # Temporary Holding Version
1
+ # `@docusaurus/utils-common`
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ Common (Node/Browser) utility functions for Docusaurus packages.
@@ -0,0 +1,19 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ import type { DocusaurusConfig } from '@docusaurus/types';
8
+ export type ApplyTrailingSlashParams = Pick<DocusaurusConfig, 'trailingSlash' | 'baseUrl'>;
9
+ export declare function addTrailingSlash(str: string): string;
10
+ /**
11
+ * Apply/remove a trailing slash on an URL path according to site config options
12
+ * Usually applied on permalinks / URL paths, but also works with absolute URL
13
+ */
14
+ export default function applyTrailingSlash(path: string, options: ApplyTrailingSlashParams): string;
15
+ /** Appends a leading slash to `str`, if one doesn't exist. */
16
+ export declare function addLeadingSlash(str: string): string;
17
+ /** Removes the trailing slash from `str`. */
18
+ export declare function removeTrailingSlash(str: string): string;
19
+ //# sourceMappingURL=applyTrailingSlash.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTrailingSlash.d.ts","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAC,gBAAgB,EAAC,MAAM,mBAAmB,CAAC;AAExD,MAAM,MAAM,wBAAwB,GAAG,IAAI,CACzC,gBAAgB,EAChB,eAAe,GAAG,SAAS,CAC5B,CAAC;AAEF,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEpD;AAED;;;GAGG;AACH,MAAM,CAAC,OAAO,UAAU,kBAAkB,CACxC,IAAI,EAAE,MAAM,EACZ,OAAO,EAAE,wBAAwB,GAChC,MAAM,CAgCR;AAED,8DAA8D;AAC9D,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEnD;AAED,6CAA6C;AAC7C,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,CAEvD"}
@@ -0,0 +1,55 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.addTrailingSlash = addTrailingSlash;
10
+ exports.default = applyTrailingSlash;
11
+ exports.addLeadingSlash = addLeadingSlash;
12
+ exports.removeTrailingSlash = removeTrailingSlash;
13
+ const stringUtils_1 = require("./stringUtils");
14
+ function addTrailingSlash(str) {
15
+ return str.endsWith('/') ? str : `${str}/`;
16
+ }
17
+ /**
18
+ * Apply/remove a trailing slash on an URL path according to site config options
19
+ * Usually applied on permalinks / URL paths, but also works with absolute URL
20
+ */
21
+ function applyTrailingSlash(path, options) {
22
+ const { trailingSlash, baseUrl } = options;
23
+ if (path.startsWith('#')) {
24
+ // Never apply trailing slash to an anchor link
25
+ return path;
26
+ }
27
+ function handleTrailingSlash(str, trailing) {
28
+ return trailing ? addTrailingSlash(str) : removeTrailingSlash(str);
29
+ }
30
+ // undefined = legacy retrocompatible behavior
31
+ if (typeof trailingSlash === 'undefined') {
32
+ return path;
33
+ }
34
+ // The trailing slash should be handled before the ?search#hash !
35
+ const [pathname] = path.split(/[#?]/);
36
+ const queryHash = path.slice(pathname.length);
37
+ // Never transform '/' to ''
38
+ // Never remove the baseUrl trailing slash!
39
+ // If baseUrl = /myBase/, we want to emit /myBase/index.html and not
40
+ // /myBase.html! See https://github.com/facebook/docusaurus/issues/5077
41
+ const shouldNotApply = pathname === '/' || pathname === baseUrl;
42
+ const newPathname = shouldNotApply
43
+ ? pathname
44
+ : handleTrailingSlash(pathname, trailingSlash);
45
+ return `${newPathname}${queryHash}`;
46
+ }
47
+ /** Appends a leading slash to `str`, if one doesn't exist. */
48
+ function addLeadingSlash(str) {
49
+ return (0, stringUtils_1.addPrefix)(str, '/');
50
+ }
51
+ /** Removes the trailing slash from `str`. */
52
+ function removeTrailingSlash(str) {
53
+ return (0, stringUtils_1.removeSuffix)(str, '/');
54
+ }
55
+ //# sourceMappingURL=applyTrailingSlash.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"applyTrailingSlash.js","sourceRoot":"","sources":["../src/applyTrailingSlash.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,+CAAsD;AAQtD,0BAAiC,GAAW;IAC1C,OAAO,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,CAAC;AAC7C,CAAC;AAED;;;GAGG;AACH,4BACE,IAAY,EACZ,OAAiC;IAEjC,MAAM,EAAC,aAAa,EAAE,OAAO,EAAC,GAAG,OAAO,CAAC;IAEzC,IAAI,IAAI,CAAC,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;QACzB,+CAA+C;QAC/C,OAAO,IAAI,CAAC;IACd,CAAC;IAED,SAAS,mBAAmB,CAAC,GAAW,EAAE,QAAiB;QACzD,OAAO,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,mBAAmB,CAAC,GAAG,CAAC,CAAC;IACrE,CAAC;IAED,8CAA8C;IAC9C,IAAI,OAAO,aAAa,KAAK,WAAW,EAAE,CAAC;QACzC,OAAO,IAAI,CAAC;IACd,CAAC;IAED,iEAAiE;IACjE,MAAM,CAAC,QAAQ,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,MAAM,CAA0B,CAAC;IAC/D,MAAM,SAAS,GAAG,IAAI,CAAC,KAAK,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC;IAE9C,4BAA4B;IAC5B,2CAA2C;IAC3C,oEAAoE;IACpE,uEAAuE;IACvE,MAAM,cAAc,GAAG,QAAQ,KAAK,GAAG,IAAI,QAAQ,KAAK,OAAO,CAAC;IAEhE,MAAM,WAAW,GAAG,cAAc;QAChC,CAAC,CAAC,QAAQ;QACV,CAAC,CAAC,mBAAmB,CAAC,QAAQ,EAAE,aAAa,CAAC,CAAC;IAEjD,OAAO,GAAG,WAAW,GAAG,SAAS,EAAE,CAAC;AACtC,CAAC;AAED,8DAA8D;AAC9D,yBAAgC,GAAW;IACzC,OAAO,IAAA,uBAAS,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAC7B,CAAC;AAED,6CAA6C;AAC7C,6BAAoC,GAAW;IAC7C,OAAO,IAAA,0BAAY,EAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAChC,CAAC"}
@@ -0,0 +1,10 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ type CausalChain = [Error, ...Error[]];
8
+ export declare function getErrorCausalChain(error: Error): CausalChain;
9
+ export {};
10
+ //# sourceMappingURL=errorUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorUtils.d.ts","sourceRoot":"","sources":["../src/errorUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AACH,KAAK,WAAW,GAAG,CAAC,KAAK,EAAE,GAAG,KAAK,EAAE,CAAC,CAAC;AAEvC,wBAAgB,mBAAmB,CAAC,KAAK,EAAE,KAAK,GAAG,WAAW,CAK7D"}
@@ -0,0 +1,10 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getErrorCausalChain = getErrorCausalChain;
4
+ function getErrorCausalChain(error) {
5
+ if (error.cause) {
6
+ return [error, ...getErrorCausalChain(error.cause)];
7
+ }
8
+ return [error];
9
+ }
10
+ //# sourceMappingURL=errorUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errorUtils.js","sourceRoot":"","sources":["../src/errorUtils.ts"],"names":[],"mappings":";;;AAQA,6BAAoC,KAAY;IAC9C,IAAI,KAAK,CAAC,KAAK,EAAE,CAAC;QAChB,OAAO,CAAC,KAAK,EAAE,GAAG,mBAAmB,CAAC,KAAK,CAAC,KAAc,CAAC,CAAC,CAAC;IAC/D,CAAC;IACD,OAAO,CAAC,KAAK,CAAC,CAAC;AACjB,CAAC"}
package/lib/index.d.ts ADDED
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ export declare const blogPostContainerID = "__blog-post-container";
8
+ export { default as applyTrailingSlash, addTrailingSlash, addLeadingSlash, removeTrailingSlash, type ApplyTrailingSlashParams, } from './applyTrailingSlash';
9
+ export { addPrefix, removeSuffix, addSuffix, removePrefix } from './stringUtils';
10
+ export { getErrorCausalChain } from './errorUtils';
11
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAIH,eAAO,MAAM,mBAAmB,0BAA0B,CAAC;AAE3D,OAAO,EACL,OAAO,IAAI,kBAAkB,EAC7B,gBAAgB,EAChB,eAAe,EACf,mBAAmB,EACnB,KAAK,wBAAwB,GAC9B,MAAM,sBAAsB,CAAC;AAC9B,OAAO,EAAC,SAAS,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAC,MAAM,eAAe,CAAC;AAC/E,OAAO,EAAC,mBAAmB,EAAC,MAAM,cAAc,CAAC"}
package/lib/index.js ADDED
@@ -0,0 +1,26 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.getErrorCausalChain = exports.removePrefix = exports.addSuffix = exports.removeSuffix = exports.addPrefix = exports.removeTrailingSlash = exports.addLeadingSlash = exports.addTrailingSlash = exports.applyTrailingSlash = exports.blogPostContainerID = void 0;
10
+ const tslib_1 = require("tslib");
11
+ // __ prefix allows search crawlers (Algolia/DocSearch) to ignore anchors
12
+ // https://github.com/facebook/docusaurus/issues/8883#issuecomment-1516328368
13
+ exports.blogPostContainerID = '__blog-post-container';
14
+ var applyTrailingSlash_1 = require("./applyTrailingSlash");
15
+ Object.defineProperty(exports, "applyTrailingSlash", { enumerable: true, get: function () { return tslib_1.__importDefault(applyTrailingSlash_1).default; } });
16
+ Object.defineProperty(exports, "addTrailingSlash", { enumerable: true, get: function () { return applyTrailingSlash_1.addTrailingSlash; } });
17
+ Object.defineProperty(exports, "addLeadingSlash", { enumerable: true, get: function () { return applyTrailingSlash_1.addLeadingSlash; } });
18
+ Object.defineProperty(exports, "removeTrailingSlash", { enumerable: true, get: function () { return applyTrailingSlash_1.removeTrailingSlash; } });
19
+ var stringUtils_1 = require("./stringUtils");
20
+ Object.defineProperty(exports, "addPrefix", { enumerable: true, get: function () { return stringUtils_1.addPrefix; } });
21
+ Object.defineProperty(exports, "removeSuffix", { enumerable: true, get: function () { return stringUtils_1.removeSuffix; } });
22
+ Object.defineProperty(exports, "addSuffix", { enumerable: true, get: function () { return stringUtils_1.addSuffix; } });
23
+ Object.defineProperty(exports, "removePrefix", { enumerable: true, get: function () { return stringUtils_1.removePrefix; } });
24
+ var errorUtils_1 = require("./errorUtils");
25
+ Object.defineProperty(exports, "getErrorCausalChain", { enumerable: true, get: function () { return errorUtils_1.getErrorCausalChain; } });
26
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;AAEH,yEAAyE;AACzE,6EAA6E;AAChE,QAAA,mBAAmB,GAAG,uBAAuB,CAAC;AAE3D,2DAM8B;AAL5B,iJAAA,OAAO,OAAsB;AAC7B,sHAAA,gBAAgB,OAAA;AAChB,qHAAA,eAAe,OAAA;AACf,yHAAA,mBAAmB,OAAA;AAGrB,6CAA+E;AAAvE,wGAAA,SAAS,OAAA;AAAE,2GAAA,YAAY,OAAA;AAAE,wGAAA,SAAS,OAAA;AAAE,2GAAA,YAAY,OAAA;AACxD,2CAAiD;AAAzC,iHAAA,mBAAmB,OAAA"}
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ /** Adds a given string prefix to `str`. */
8
+ export declare function addPrefix(str: string, prefix: string): string;
9
+ /** Removes a given string suffix from `str`. */
10
+ export declare function removeSuffix(str: string, suffix: string): string;
11
+ /** Adds a given string suffix to `str`. */
12
+ export declare function addSuffix(str: string, suffix: string): string;
13
+ /** Removes a given string prefix from `str`. */
14
+ export declare function removePrefix(str: string, prefix: string): string;
15
+ //# sourceMappingURL=stringUtils.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringUtils.d.ts","sourceRoot":"","sources":["../src/stringUtils.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAMhE;AAED,2CAA2C;AAC3C,wBAAgB,SAAS,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAE7D;AAED,gDAAgD;AAChD,wBAAgB,YAAY,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,MAAM,CAEhE"}
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ /**
3
+ * Copyright (c) Facebook, Inc. and its affiliates.
4
+ *
5
+ * This source code is licensed under the MIT license found in the
6
+ * LICENSE file in the root directory of this source tree.
7
+ */
8
+ Object.defineProperty(exports, "__esModule", { value: true });
9
+ exports.addPrefix = addPrefix;
10
+ exports.removeSuffix = removeSuffix;
11
+ exports.addSuffix = addSuffix;
12
+ exports.removePrefix = removePrefix;
13
+ /** Adds a given string prefix to `str`. */
14
+ function addPrefix(str, prefix) {
15
+ return str.startsWith(prefix) ? str : `${prefix}${str}`;
16
+ }
17
+ /** Removes a given string suffix from `str`. */
18
+ function removeSuffix(str, suffix) {
19
+ if (suffix === '') {
20
+ // str.slice(0, 0) is ""
21
+ return str;
22
+ }
23
+ return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
24
+ }
25
+ /** Adds a given string suffix to `str`. */
26
+ function addSuffix(str, suffix) {
27
+ return str.endsWith(suffix) ? str : `${str}${suffix}`;
28
+ }
29
+ /** Removes a given string prefix from `str`. */
30
+ function removePrefix(str, prefix) {
31
+ return str.startsWith(prefix) ? str.slice(prefix.length) : str;
32
+ }
33
+ //# sourceMappingURL=stringUtils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"stringUtils.js","sourceRoot":"","sources":["../src/stringUtils.ts"],"names":[],"mappings":";AAAA;;;;;GAKG;;;;;;AAEH,2CAA2C;AAC3C,mBAA0B,GAAW,EAAE,MAAc;IACnD,OAAO,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,MAAM,GAAG,GAAG,EAAE,CAAC;AAC1D,CAAC;AAED,gDAAgD;AAChD,sBAA6B,GAAW,EAAE,MAAc;IACtD,IAAI,MAAM,KAAK,EAAE,EAAE,CAAC;QAClB,wBAAwB;QACxB,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC,EAAE,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACnE,CAAC;AAED,2CAA2C;AAC3C,mBAA0B,GAAW,EAAE,MAAc;IACnD,OAAO,GAAG,CAAC,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,GAAG,GAAG,MAAM,EAAE,CAAC;AACxD,CAAC;AAED,gDAAgD;AAChD,sBAA6B,GAAW,EAAE,MAAc;IACtD,OAAO,GAAG,CAAC,UAAU,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC;AACjE,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,28 @@
1
1
  {
2
2
  "name": "@azerion/bunosaurus-utils-common",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "4.0.0",
4
+ "description": "Common (Node/Browser) utility functions for Docusaurus packages.",
5
+ "main": "./lib/index.js",
6
+ "types": "./lib/index.d.ts",
7
+ "sideEffects": false,
8
+ "scripts": {
9
+ "build": "tsc",
10
+ "watch": "tsc --watch"
11
+ },
12
+ "publishConfig": {
13
+ "access": "public"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "https://github.com/azerion/bunosaurus.git",
18
+ "directory": "packages/docusaurus-utils-common"
19
+ },
20
+ "license": "MIT",
21
+ "dependencies": {
22
+ "@docusaurus/types": "npm:@azerion/bunosaurus-types@4.0.0",
23
+ "tslib": "^2.8.1"
24
+ },
25
+ "engines": {
26
+ "bun": ">=1.4.1"
27
+ }
28
+ }
@@ -0,0 +1,69 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ import {addPrefix, removeSuffix} from './stringUtils';
9
+ import type {DocusaurusConfig} from '@docusaurus/types';
10
+
11
+ export type ApplyTrailingSlashParams = Pick<
12
+ DocusaurusConfig,
13
+ 'trailingSlash' | 'baseUrl'
14
+ >;
15
+
16
+ export function addTrailingSlash(str: string): string {
17
+ return str.endsWith('/') ? str : `${str}/`;
18
+ }
19
+
20
+ /**
21
+ * Apply/remove a trailing slash on an URL path according to site config options
22
+ * Usually applied on permalinks / URL paths, but also works with absolute URL
23
+ */
24
+ export default function applyTrailingSlash(
25
+ path: string,
26
+ options: ApplyTrailingSlashParams,
27
+ ): string {
28
+ const {trailingSlash, baseUrl} = options;
29
+
30
+ if (path.startsWith('#')) {
31
+ // Never apply trailing slash to an anchor link
32
+ return path;
33
+ }
34
+
35
+ function handleTrailingSlash(str: string, trailing: boolean): string {
36
+ return trailing ? addTrailingSlash(str) : removeTrailingSlash(str);
37
+ }
38
+
39
+ // undefined = legacy retrocompatible behavior
40
+ if (typeof trailingSlash === 'undefined') {
41
+ return path;
42
+ }
43
+
44
+ // The trailing slash should be handled before the ?search#hash !
45
+ const [pathname] = path.split(/[#?]/) as [string, ...string[]];
46
+ const queryHash = path.slice(pathname.length);
47
+
48
+ // Never transform '/' to ''
49
+ // Never remove the baseUrl trailing slash!
50
+ // If baseUrl = /myBase/, we want to emit /myBase/index.html and not
51
+ // /myBase.html! See https://github.com/facebook/docusaurus/issues/5077
52
+ const shouldNotApply = pathname === '/' || pathname === baseUrl;
53
+
54
+ const newPathname = shouldNotApply
55
+ ? pathname
56
+ : handleTrailingSlash(pathname, trailingSlash);
57
+
58
+ return `${newPathname}${queryHash}`;
59
+ }
60
+
61
+ /** Appends a leading slash to `str`, if one doesn't exist. */
62
+ export function addLeadingSlash(str: string): string {
63
+ return addPrefix(str, '/');
64
+ }
65
+
66
+ /** Removes the trailing slash from `str`. */
67
+ export function removeTrailingSlash(str: string): string {
68
+ return removeSuffix(str, '/');
69
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+ type CausalChain = [Error, ...Error[]];
8
+
9
+ export function getErrorCausalChain(error: Error): CausalChain {
10
+ if (error.cause) {
11
+ return [error, ...getErrorCausalChain(error.cause as Error)];
12
+ }
13
+ return [error];
14
+ }
package/src/index.ts ADDED
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ // __ prefix allows search crawlers (Algolia/DocSearch) to ignore anchors
9
+ // https://github.com/facebook/docusaurus/issues/8883#issuecomment-1516328368
10
+ export const blogPostContainerID = '__blog-post-container';
11
+
12
+ export {
13
+ default as applyTrailingSlash,
14
+ addTrailingSlash,
15
+ addLeadingSlash,
16
+ removeTrailingSlash,
17
+ type ApplyTrailingSlashParams,
18
+ } from './applyTrailingSlash';
19
+ export {addPrefix, removeSuffix, addSuffix, removePrefix} from './stringUtils';
20
+ export {getErrorCausalChain} from './errorUtils';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Copyright (c) Facebook, Inc. and its affiliates.
3
+ *
4
+ * This source code is licensed under the MIT license found in the
5
+ * LICENSE file in the root directory of this source tree.
6
+ */
7
+
8
+ /** Adds a given string prefix to `str`. */
9
+ export function addPrefix(str: string, prefix: string): string {
10
+ return str.startsWith(prefix) ? str : `${prefix}${str}`;
11
+ }
12
+
13
+ /** Removes a given string suffix from `str`. */
14
+ export function removeSuffix(str: string, suffix: string): string {
15
+ if (suffix === '') {
16
+ // str.slice(0, 0) is ""
17
+ return str;
18
+ }
19
+ return str.endsWith(suffix) ? str.slice(0, -suffix.length) : str;
20
+ }
21
+
22
+ /** Adds a given string suffix to `str`. */
23
+ export function addSuffix(str: string, suffix: string): string {
24
+ return str.endsWith(suffix) ? str : `${str}${suffix}`;
25
+ }
26
+
27
+ /** Removes a given string prefix from `str`. */
28
+ export function removePrefix(str: string, prefix: string): string {
29
+ return str.startsWith(prefix) ? str.slice(prefix.length) : str;
30
+ }