aboutsummaryrefslogtreecommitdiffstats
path: root/packages/react-shared/src/ts/utils/utils.ts
diff options
context:
space:
mode:
Diffstat (limited to 'packages/react-shared/src/ts/utils/utils.ts')
-rw-r--r--packages/react-shared/src/ts/utils/utils.ts32
1 files changed, 32 insertions, 0 deletions
diff --git a/packages/react-shared/src/ts/utils/utils.ts b/packages/react-shared/src/ts/utils/utils.ts
new file mode 100644
index 000000000..7498342b6
--- /dev/null
+++ b/packages/react-shared/src/ts/utils/utils.ts
@@ -0,0 +1,32 @@
+import * as _ from 'lodash';
+import { scroller } from 'react-scroll';
+
+import { constants } from './constants';
+
+export const utils = {
+ setUrlHash(anchorId: string) {
+ window.location.hash = anchorId;
+ },
+ scrollToHash(hash: string, containerId: string): void {
+ let finalHash = hash;
+ if (_.isEmpty(hash)) {
+ finalHash = constants.SCROLL_TOP_ID; // scroll to the top
+ }
+
+ scroller.scrollTo(finalHash, {
+ duration: 0,
+ offset: 0,
+ containerId,
+ });
+ },
+ getIdFromName(name: string) {
+ const id = name.replace(/ /g, '-');
+ return id;
+ },
+ getCurrentBaseUrl() {
+ const port = window.location.port;
+ const hasPort = !_.isUndefined(port);
+ const baseUrl = `https://${window.location.hostname}${hasPort ? `:${port}` : ''}`;
+ return baseUrl;
+ },
+};