# @hashicorp/platform-util

> General utilities for HashiCorp next.js websites

Latest version **0.2.0** (published 2022-07-14) · MPL-2.0 license · 0 weekly downloads

## Install

```sh
npm install @hashicorp/platform-util
pnpm add @hashicorp/platform-util
yarn add @hashicorp/platform-util
bun add @hashicorp/platform-util
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.2.0 |
| Published | 2022-07-14 |
| First published | 2021-06-21 |
| Weekly downloads | 0 |
| License | MPL-2.0 |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Unpacked size | 13.8 KB |
| Known vulnerabilities | 0 (+1 in 1 direct dependencies) |
| Install scripts | no |
| Author | HashiCorp |
| Maintainers | hashibot-hds, lackeyjb1, alexcarpenter, youriwims, jpogran, ashleemboyer, _natmegs, thrashr888, amyrlam, melsumner, johncowen, mwickett, didoo, zchsh, brandonromano, hcitsec, gregone, meirish, enmod, kylemac, kaxcode, anubhavmishra-hashicorp, hashibot-web, cstitt-hashi, bkalow, kstraut, mocohen, dhaulagiri |

## Links

- npm: https://www.npmjs.com/package/@hashicorp/platform-util
- npm.io page: https://npm.io/package/@hashicorp/platform-util

## Dependencies (2)

- [js-cookie](https://npm.io/package/js-cookie.md) ^2.2.1
- [nprogress](https://npm.io/package/nprogress.md) 0.2.0

## Recent versions

- 0.2.0 (latest) — 2022-07-14
- 0.2.1-canary-202302404810 (canary) — 2023-01-24
- 0.2.0-canary-2022614181233 — 2022-07-14
- 0.2.0-canary-202261418638 — 2022-07-14
- 0.2.0-canary-2022614163324 — 2022-07-14
- 0.2.0-canary-2022614162925 — 2022-07-14
- 0.2.0-canary-202261415942 — 2022-07-14
- 0.1.0 — 2021-07-14
- 0.1.0-canary.0 — 2021-06-21

## README

# `@hashicorp/platform-util`

Shared utilities used across our web properties and libraries.

### NProgress

By default, Next.js does not provide any loading indicator for client-side route transitions. They recommend the use of [NProgress](https://ricostacruz.com/nprogress/), a small script that dislays a loading bar at the top of the browser frame.

It can be added to your app as such, within `_app.js`

```js
import '@hashicorp/platform-util/nprogress/style.css'
import NProgress from '@hashicorp/platform-util/nprogress'
import Router from 'next/router'

NProgress({ Router })
```

If you want to add some custom action to the route change's `start`, `finish`, or `error` states, you can pass in functions that will run accordingly:

```js
import '@hashicorp/platform-util/nprogress/style.css'
import NProgress from '@hashicorp/platform-util/nprogress'
import Router from 'next/router'

NProgress({
  Router,
  start: () => console.log('route change started'),
  finish: () => console.log('route change complete'),
  error: () => console.log('route change error'),
})
```

It's worth noting that the `finish` handler will always automatically fire an analytics `page` event as long as the `window.analytics` object is present.

Make sure to remember the css import as well!

### Anchor Link Analytics

HashiCorp maintains a lot of documentation sites, all of which have many automatically generated permalinks based on headline text, and which can often break as a result of text changes and reorganization. As such, we try to run some extra analytics on permalinks by tracking, when a page url contains an anchor link (like `hashicorp.com#foo`) whether the given anchor is actually present on the page. This allows us to more confidently remove custom anchor links that are unused, and to detect when a popular incoming anchor link is broken so it can be fixed.

To enable this tracking, simply import `@hashicorp/platform-util/anchor-link-analytics` in your `_app.js`. This script is SSR-compatible and runs inside `requestIdleCallback` so that it has a minimal impact on page performance. An example of a bare bones implementation:

```js
import useAnchorLinkAnalytics from '@hashicorp/platform-util/anchor-link-analytics'

export default function App({ Component, pageProps }) {
  useAnchorLinkAnalytics()
  return <Component {...pageProps} />
}
```

### Geo Utilities

Provides utilities for accessing geo location data stored in the `hc_geo` cookie.

```ts
import { getGeoInformation, isInUS } from '@hashicorp/platform-util/geo'

console.log(getGeoInformation()) // { country: 'US', region: 'MN' }
console.log(isInUS()) // true
```

---
_Source: https://npm.io/package/@hashicorp/platform-util · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
