npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

@ongov/ontario-search

v2.0.2

Published

React components containing search bar and autosuggest to be used for search on ontario government websites

Readme

@ongov/ontario-search

This package provides a React-based search bar with autosuggest dropdown for Ontario.ca websites. It includes:

  • Typeahead completion suggestions (from Elasticsearch)
  • Page suggestions with popular page badges
  • Cookie-based search history
  • Bilingual support (EN/FR) with automatic language detection from the URL path
  • Ontario.ca URL redirect detection
  • Google Analytics (dataLayer) event tracking

Development

  1. Install dependencies: npm install from this folder
  2. Run npm run start to build and serve with hot reload (Webpack dev server)

Build Modes

Default build (UMD — recommended)

npm run build

Produces a self-contained UMD bundle at dist/index.js with all dependencies (including React) bundled in. Works with a plain <script> tag — no bundler required. This is the build published to NPM and used by both the ontario.ca search application and non-React consumers (e.g. Drupal).

No-React build (ES module)

npm run build:no-react

Produces an ES module build at dist/index.js with React, axios, i18next, and other dependencies externalized. Use this if you already have React in your project and want a smaller bundle. Requires a bundler (Vite, Webpack, etc.) to resolve the peer dependencies.

Packaging & Deployment

NPM Package Deployment (Automated)

NPM publishing is fully automated via GitLab CI.

To publish a new version of the package:

  • Ensure your changes are merged into the main branch
  • Use Conventional Commits with the (npm-components) scope, for example:
    • feat(npm-components): add autocomplete
    • fix(npm-components): fix crash

What happens automatically

Once changes are merged into main, the CI pipeline will:

  • Analyze commits since the last release
  • Determine the version bump:
    • feat → minor
    • fix → patch
    • BREAKING CHANGE → major
  • Update the version in package.json
  • Generate/update the CHANGELOG.md
  • Create and push a git tag in the format:
    • npm-vX.X.X
  • Trigger a new pipeline for packaging and publishing

Publishing to NPM

  • The pipeline will prepare the package automatically
  • If CI is set to manual deploy, you will need to click the publish job in GitLab
  • Once completed, the package will be available on NPM

Important Notes

  • Only commits with (npm-components) scope trigger a release
  • No release will occur if there are no relevant commits
  • Do not manually run npm run npm-publish
  • Do not manually create npm-v tags

Manual Override (Optional)

If needed, a release can still be triggered manually:

git tag npm-v1.2.3
git push origin npm-v1.2.3

Package Use In Projects

1. Install the package

npm install @ongov/ontario-search

2. Add runtime configuration

The package reads configuration from window.apiConfig and window.endpointConfig. Add these before the package script loads:

<script type="module">
  // Required: Elasticsearch index name used by autosuggest
  window.apiConfig = {
    elasticsearchUrl: 'elastic-url',
    index: 'your-elasticsearch-index-name',
    apiKey: 'public-api-key',
  }

  // Required: search results page endpoints for EN and FR
  window.endpointConfig = {
    en: '/search/',
    fr: '/fr/recherche/',
  }
</script>

| Config | Required | Description | | ----------------------------------- | -------- | ------------------------------------------------ | | window.apiConfig.index | Yes | Elasticsearch index name for autosuggest queries | | window.apiConfig.elasticsearchUrl | Yes | Ontario ES url (stage/prod) | | window.apiConfig.apiKey | Yes | ES public api key (stage/prod) | | window.endpointConfig.en | Yes | English search results page path | | window.endpointConfig.fr | Yes | French search results page path |

3. Add the mount target element

Create an element with id="ontario-search-autosuggest":

<div id="ontario-search-autosuggest"></div>

The package will automatically mount into this element once the DOM is ready. If the element is added dynamically (e.g. by a SPA), the package uses a MutationObserver to detect it.

4. Import the package

<script
  type="module"
  src="path/to/@ongov/ontario-search/dist/index.js"
></script>

Or in a bundled project:

import '@ongov/ontario-search'

Exported API

The package exports the following for programmatic use:

import {
  mount,
  AutosuggestBar,
  getSuggestPages,
  getSuggestSearches,
} from '@ongov/ontario-search'

| Export | Description | | ---------------------------------------- | ---------------------------------------------------------------------------------------------- | | mount(elementOrId, props) | Mount the search bar on a specific element (by ID string or DOM node). Returns the React root. | | AutosuggestBar | The React component (for use within your own React app). Accepts an index prop. | | getSuggestPages(index, query, lang) | Fetch page suggestions from Elasticsearch. | | getSuggestSearches(index, query, lang) | Fetch completion suggestions from Elasticsearch. | | window.__ontarioSearchMount(language?) | Re-mount after DOM changes (e.g. language switch). Available globally after first load. |

Styles & Shadow DOM

The Ontario Design System header renders its content inside a shadow DOM. Normal page-level <link> or <style> tags cannot penetrate the shadow boundary, so the autosuggest styles must be injected directly into the shadow root.

How it works

Before mounting, set window.__ontarioSearchStylesHref to a URL pointing to the compiled autosuggest stylesheet. At mount time, the package injects a <link rel="stylesheet"> with that URL into the header's shadow root.

<script type="module">
  // Point to the stylesheet from the npm package (adjust path to your setup)
  import ontarioSearchStylesHref from '@ongov/ontario-search/styles?url'
  window.__ontarioSearchStylesHref = ontarioSearchStylesHref
</script>

If you're not using a bundler that supports ?url imports, you can set it to any publicly accessible URL where the compiled CSS is hosted:

<script>
  window.__ontarioSearchStylesHref = '/path/to/ontario-search-styles.css'
</script>

Package export

The package exposes the SCSS source via the ./styles export:

import '@ongov/ontario-search/styles' // → dist/styles/index.scss

This is useful if your build pipeline compiles SCSS and you want to include the styles in a global bundle (for pages that don't use shadow DOM).

Summary

| Scenario | What to do | | ----------------------------- | -------------------------------------------------------------------------------------------------------------- | | DS header with shadow DOM | Set window.__ontarioSearchStylesHref to a CSS/SCSS URL — it gets injected into the shadow root automatically | | Standard page (no shadow DOM) | Import @ongov/ontario-search/styles in your SCSS/CSS bundle, or add a <link> to the compiled stylesheet |

Note: If window.__ontarioSearchStylesHref is not set, the component will still mount but will be unstyled inside the shadow root, and a warning will appear in the console.

Language Detection

The package automatically detects language from the URL path:

  • URLs containing /fr/ → French
  • All other URLs → English

You can override this by passing a language to window.__ontarioSearchMount('fr').

Search History

The package stores recent searches in a cookie (search_history) with the following behaviour:

  • Maximum 7 entries, shown when the input is focused with no text
  • Users can remove individual history items
  • History is deduplicated by normalized text
  • Entries are sanitized (HTML stripped) before storage

Tips

  • Contact the Ontario.ca Search team for the correct Elasticsearch index name.
  • The package must load after window.apiConfig and window.endpointConfig are set.
  • It is recommended to nest a simple search bar inside the mount element as a fallback in case this package does not load. The form should submit to https://www.ontario.ca/search/?query=QUERY (EN) or https://www.ontario.ca/fr/recherche/?query=QUERY (FR).
  • Make sure mobile search open/close buttons work as expected, including moving focus to the input on button click.