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

@cmchu/device-marker

v0.0.1

Published

This library provides a set of utilities for managing and interacting with device and browser components in a TypeScript-based application. It offers type definitions for devices and browsers, utility functions for converting component configurations to h

Downloads

4

Readme

device-marker Library

Overview

This library provides a set of utilities for managing and interacting with device and browser components in a TypeScript-based application. It offers type definitions for devices and browsers, utility functions for converting component configurations to hashes, and lazy-loaded functions for retrieving device and browser markers.

Key Features

  • Device & Browser Types: Clear, strongly-typed definitions for devices and browsers, enabling strict type checking in your codebase.
  • Component Configuration: A flexible configuration object (Components) that allows partial definitions of device or browser components.
  • Hash Generation: A function (components2Hash) to convert your component configurations into a unique hash, useful for caching or identification purposes.
  • Lazy Loading: Two lazy evaluation functions (getDeviceMarker and getBrowserMarker) for retrieving markers associated with devices and browsers respectively, promoting efficient resource usage.

Installation

Assuming this library is published, you can install it using npm or yarn:

npm install --save @cmchu/device-marker
# or
yarn add @cmchu/device-marker

Usage

Importing Types

import {
  components,
  components2Hash,
  getDeviceMarker,
  getBrowserMarker,
} from '@cmchu/device-marker';

Working with Types

  • Define and use types for devices and browsers in your code.

Configuring Components

import { components } from '@cmchu/device-marker';
import type { Components } from '@cmchu/device-marker';
const { osCpu, timezone } = components;
const mycomponents: Components = {
  osCpu,
  timezone
};
const hash = await components2Hash(mycomponents);

Generating Hashes

Use components2Hash to create a unique hash based on your component configuration.

async function generateComponentHash() {
  const hash = await components2Hash(myComponents);
  console.log(`Generated hash: ${hash}`);
}

Retrieving Markers (Lazy Loaded)

Access device and browser markers without immediate execution.

async function logMarkers() {
  try {
    const deviceMarker = await getDeviceMarker();
    const browserMarker = await getBrowserMarker();
    console.log(`Device Marker: ${deviceMarker}`);
    console.log(`Browser Marker: ${browserMarker}`);
  } catch (error) {
    console.error('Error fetching markers:', error);
  }
}

API Reference

Types

  • Devices, DeviceName, Device
  • Browsers, BrowserName, Browser
  • ComponentName, Component
  • Components

Functions

  • components2Hash(components: Components): Promise<string>
    Converts a Components object to a string hash.

  • getDeviceMarker(): () => Promise<string>
    Lazy-loaded function to fetch a device marker.

  • getBrowserMarker(): () => Promise<string>
    Lazy-loaded function to fetch a browser marker.

Conclusion

This library simplifies working with device and browser components in TypeScript applications, offering robust typing, configuration flexibility, and optimized retrieval of markers through lazy loading. Integrate it into your project for enhanced maintainability and performance.

Open Source License

This project is licensed under the [MIT License]. Contributions and usage are welcome.