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

@bygd/opus-hl-config

v0.1.14

Published

The `@bygd/opus-hl-config` project is designed to streamline the process of fetching configuration data for your webpage. It aims to simplify interactions with the HeaderLift API by structuring and caching responses based on the page's URL and asset infor

Downloads

126

Readme

@bygd/opus-hl-config

The @bygd/opus-hl-config project is designed to streamline the process of fetching configuration data for your webpage. It aims to simplify interactions with the HeaderLift API by structuring and caching responses based on the page's URL and asset information.

How It Works

The project uses a combination of given and default parameters to build a uniquely identifiable request to the HeaderLift API. It checks if the required data is already cached to minimize repeated network requests, enhancing performance by reducing latency. If the information isn't cached, it retrieves the necessary data by creating a query to a predefined API endpoint and processes the response for use.

Key Features

  • URL Parsing: Automatically parses the page URL to extract the domain, ensuring correct API request formatting.
  • Conditional Caching: Utilizes a caching mechanism to store and reuse data for repeated requests with the same parameters.
  • Configurable Parameters: Allows overriding of default URL, page width, and type selections to accommodate a variety of use cases.
  • Robust Error Handling: Provides error feedback for missing required parameters and failed network or data responses.

Conclusion

The @bygd/opus-hl-config script is a helpful tool for developers looking to efficiently configure their webpages using HeaderLift data. Its caching functionality saves time and resources by reducing unnecessary network requests, ensuring response data is available quickly and reliably.

Developer Guide for @bygd/opus-hl-config

Overview

The @bygd/opus-hl-config library provides a simple interface for loading configuration data tailored to specific pages or assets on your website. With its key feature of caching responses, the library reduces the need for repetitive and resource-intensive network requests. This makes it particularly useful for applications where configurations change infrequently but need to be accessed often.

Installation

To integrate @bygd/opus-hl-config into your project, you can install it using either npm or yarn:

Using npm:

npm install @bygd/opus-hl-config

Using yarn:

yarn add @bygd/opus-hl-config

Usage

The main functionality of the library is accessible through the default export function. This function fetches configuration data based on the provided URL and other optional parameters.

Function Signature:

async function({
  page_url,
  page_type,
  asset_id,
  width,
} = {})

Parameters:

  • page_url (optional): The URL of the page for which you want the configuration. If not specified, the current window URL will be used.
  • page_type (optional): A string representing the page type, defaults to "gd" if asset_id is provided.
  • asset_id (optional): A unique identifier for the asset. If provided, it influences the resulting page type.
  • width (optional): The width of the page in pixels. Defaults to the current window width.

Returns:

A promise that resolves to the configuration data specific to the provided or inferred URL parameters.

Examples

Below are some examples demonstrating how to use the @bygd/opus-hl-config library:

Basic Example

This example shows how to obtain configuration data for the current page:

import loadConfig from '@bygd/opus-hl-config';

(async () => {
  try {
    const configData = await loadConfig();
    console.log(configData);
  } catch (error) {
    console.error('Error loading configuration:', error);
  }
})();

Specifying Page URL and Asset ID

You can also specify a page URL and asset ID to get configuration data for a specific asset:

import loadConfig from '@bygd/opus-hl-config';

(async () => {
  try {
    const configData = await loadConfig({
      page_url: 'https://example.com',
      asset_id: '12345'
    });
    console.log(configData);
  } catch (error) {
    console.error('Error loading configuration:', error);
  }
})();

Acknowledgement

There are no specific acknowledgments required for @bygd/opus-hl-config.

Input Schema

$schema: https://json-schema.org/draft/2020-12/schema
type: object
properties:
  page_url:
    type: string
    format: uri
    description: The URL of the page. Defaults to the current window URL or
      'https://gry.pl'.
  page_type:
    type: string
    description: The type of the page. Defaults to 'gd' if asset_id is provided,
      otherwise 'default'.
  asset_id:
    type: string
    description: The ID of the asset. Optional parameter.
  width:
    type: integer
    description: The width of the page. Defaults to the current window width or 720.
required:
  - page_url