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

@eik/common

v5.0.0

Published

Common utilities for Eik modules

Downloads

11,270

Readme

@eik/common

This package contains common utilities and schemas used in other Eik modules.

Schema

The schema for eik.json can be found here in this repo. Here is how you can use it in your eik.json.

{
    "$schema": "https://raw.githubusercontent.com/eik-lib/common/main/lib/schemas/eikjson.schema.json",
    "name": "my-app",
    "version": "1.0.0",
    "server": "https://eik.store.com",
    "files": "./public",
    "import-map": ["https://eik.store.com/map/store/v1"]
}

@eik/common has a JavaScript API to check against the schema.

API

helpers

helpers has utility functions used by several other Eik modules.

import { helpers } from '@eik/common';

let config = helpers.getDefaults();

These are the available functions on helpers.

| Name | Description | | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | | getDefaults | Reads configuration from eik.json or package.json. Includes defaults for missing optional settings. | | localAssets | Sets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file. | | typeSlug | Maps between Eik configuration values for the package type and its URL/file system value. | | typeTitle | Maps between a type config value and its title. Essentially uppercases the input. | | addTrailingSlash | | | removeTrailingSlash | | | addLeadingSlash | | | removeLeadingSlash | | | resolveFiles | Uses an Eik JSON "files" definition to resolve files on disk into a data structure. Returns a list of ResolvedFile. | | configStore | Collection of helper methods for reading and writing Eik configuration files. |

localAssets

Sets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file.

Given this server and eik.json, the following routes would be added to your app.

import { helpers } from '@eik/common';
import express from 'express';

let app = express();

await helpers.localAssets(app);
{
    "name": "my-app",
    "version": "1.0.0",
    "server": "https://eik.store.com",
    "files": {
        "esm.js": "./assets/esm.js",
        "esm.css": "./assets/esm.css",
        "/": "./assets/**/*.map"
    }
}
/pkg/my-app/1.0.0/esm.js
/pkg/my-app/1.0.0/esm.css
/pkg/my-app/1.0.0/esm.js.map
/pkg/my-app/1.0.0/esm.css.map

schemas

schemas has functions to check values against the eik.json schema. You can check a value against the schema for eik.json as a whole, or for individual values in the schema.

import { schemas } from '@eik/common';

let { error, value } = schemas.validate.eikJSON(eikConfig);
if (error) {
    // fallback
}

If you prefer, you can use the assert API which throws on error.

import { schemas } from '@eik/common';

try {
    schemas.assert.eikJSON(eikConfig);
} catch {
    // fallback
}

These are the available functions on schemas.validate and schemas.assert.

| Name | Description | | ----------- | ----------------------------------------------------------------------- | | eikJSON | Checks that the given value includes required fields that are valid | | name | Checks name | | version | Checks version | | type | Checks type | | server | Checks server | | files | Checks files | | importMap | Checks import-map | | out | Checks out |

stream

stream has functions to check that a value is a Stream.

import { stream } from '@eik/common';

if (stream.isStream(maybeStream)) {
    // yup, it's a Stream
}

if (stream.isReadableStream(maybeReadableStream)) {
    // yup, it's a ReadableStream
}

validators

validators functions return the provided string normalized to lowercase, or throw an Error if the value does not pass the validation rules. Where possible, prefer using the schemas API.

import { validators } from '@eik/common';

let alias = validators.alias('1');

These are the available functions on validators.

| Name | Description | | ------------ | ---------------------------------------------------------------- | | alias | Checks that a value is a valid alias value (ex 1) | | name | Checks that a value is a valid package name | | org | Checks that a value is a valid organisation name. | | origin | Check that a value looks like an HTTP origin. | | version | Checks that a value is a valid semver version | | semverType | Checks that a value is a valid semver type (major, minor, patch) | | type | Checks that the value is a valid Eik type (pkg, npm, map) |