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

@commonshost/configuration

v10.0.0

Published

Configuration file utilities

Downloads

41

Readme

@commonshost/configuration ⚙️

These are the schemas for @commonshost/server configuration files. They are shared between various related projects. This package acts as the versioned reference.

API

validate(json)

Throws the first encountered error if the configuration syntax is invalid, otherwise returns true.

const { validate } = require('@commonshost/configuration')

const configuration = {
  hosts: [
    {
      domain: 'commons.host',
      root: 'public'
    }
  ]
}

validate(configuration)

normaliseHost(host, options)

Process an individual host instance to return a cleaned up representation.

const { normaliseHost } = require('@commonshost/configuration')

const normalised = await normaliseHost(host, options)

Returns a promise which resolves to a host object with various sanity checks applied.

Options:

  • externalManifest: A boolean (default: false) that enables (true) or disables (false) the resolving of external HTTP/2 server push manifests.

  • configurationFilepath: The file path, as a string, of the configuration file to which any external manifest should be resolved. If not specified, external manifests will not be resolved. Example: /etc/commonshost/server.json

findFile(cwd)

Looks for a configuration file matching commons((.)host)(.conf(ig)).js(on) in the given directory.

cwd defaults to the current working directory.

Returns the filepath if a configuration file is found.

The configuration file name is any permutation of these pre-, in-, and suffixes.

| Prefix | Infix | Suffix | |-|-|-| | commons | .conf | .js | | commonshost | .config | .json | | commons.host | none | |

loadFile(filepath)

Loads a configuration file that can be a JSON file or a CommonsJS module.

For JSON, the object is returned.

{
  "hosts": [
    {
      "domain": "example.com"
    }
  ]
}

If a CommonJS module exports an object then it is simply returned.

module.exports = {
  hosts: [
    {
      domain: 'example.com'
    }
  ]
}

If a CommonJS module exports a function, it is evaluated. Async functions that return a promise are awaited.

module.exports = async function () {
  const response = await fetch('https://example.com/commonshost.json')
  // Response body: {"hosts":[{"domain":"example.com"}]}
  return response.json()
}

For each of these configuration file examples, the result is the same.

const configuration = await loadFile(filepath)
// {
//   hosts: [
//     {
//       domain: 'example.com'
//     }
//   ]
// }

JSON Schemas

Server

The server schema defines the main structure of a configuration file. It contains options that apply to the overall server instance.

const serverSchema = require('@commonshost/configuration/schema/server')

Host

The schema specifically for validating a host section of the configuration. It contains options that apply to an individual site by domain.

const hostSchema = require('@commonshost/configuration/schema/host')

Manifest

The HTTP/2 Server Push Manifest schema is available in @commonshost/manifest and used to validate the manifest property of a host.

const { schema: manifestSchema } = require('@commonshost/manifest')