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 🙏

© 2024 – Pkg Stats / Ryan Hefner

shopify-normalize-hostname

v2.0.0

Published

Takes an input string and returns the normalized Shopify store hostname, or alternatively just the store subdomain, or null if the input is not valid.

Downloads

1

Readme

Normalize Shopify Hostnames

Takes an input string and returns the normalized Shopify store hostname, or alternatively just the store subdomain, or null if the input is not valid.

For any input that isn't a string or isn't a URL that can be turned into a .myshopify.com hostname, the return value is null. This makes it safe to accept unsafe user input.

Valid input examples:

  • fancy-widgets
  • fancy-widgets.myshopify.com
  • https://fancy-widgets.myshopify.com
  • https://fancy-widgets.myshopify.com/some/path

Output for all of the above inputs:

  • Hostname: fancy-widgets.myshopify.com
  • Subdomain: fancy-widgets

The store hostname can always be re-created from the store subdomain by appending .myshopify.com.

Usage

normalizeOutput(input, options = {})

| Parameter | type | | | --- | --- | --- | |input | any | expected to be a string, but can be any value | | options | object | | | options.returnSubdomain | boolean = false | return only the subdomain instead of the entire hostname | | return | string | null | the normalized hostname if valid, or null |

Example

const normalizeOutput = require('shopify-normalize-output');

normalizeHostname('fancy-widgets.myshopify.com');
// Output: "fancy-widgets.myshopify.com"

normalizeHostname('fancy-widgets.myshopify.com', { returnSubdomain: true });
// Output: "fancy-widgets"

Background: Shopify Store Hostnames

Each Shopify store is uniquely identified by a hostname which consists of a subdomain on the myshopify.com domain.

This is true regardless of whether the store has its own custom domain. It's always has a subdomain on myshopify.com behind the scenes.

Here are examples of store hostnames:

  • shiny-trinkets.myshopify.com
  • fancy-widgets.myshopify.com
  • tattly.myshopify.com

When dealing with the Shopify API, this hostname is the primary way to identify a store. It's used in URLs like these:

  • The API endpoints like https://{hostname}/admin/products.json
  • The OAuth authorization page at https://{hostname}/admin/oauth/authorize
  • The admin interface for a store at https://{hostname}/admin
  • The admin interface of an app within a store at https://{hostname}/admin/apps/{api-key}
  • ScriptTags URL which are automatically loaded with the hostname as a query parameter, like https://example.com/script.js?shop={hostname}

Definition of Valid Hostname

Here's how the Shopify documentation defines a valid hostname:

Ensure the provided hostname parameter is a valid hostname, ends with myshopify.com, and does not contain characters other than letters (a-z), numbers (0-9), dots, and hyphens.