Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@eik/common

Package Overview
Dependencies
Maintainers
0
Versions
47
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@eik/common

Common utilities for Eik modules

  • 4.1.1
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.7K
increased by50.17%
Maintainers
0
Weekly downloads
 
Created
Source

@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.

NameDescription
getDefaultsReads configuration from eik.json or package.json. Includes defaults for missing optional settings.
localAssetsSets up asset routes for local development. Mounted paths match those on Eik server and values are read from projects eik.json file.
typeSlugMaps between Eik configuration values for the package type and its URL/file system value.
typeTitleMaps between a type config value and its title. Essentially uppercases the input.
addTrailingSlash
removeTrailingSlash
addLeadingSlash
removeLeadingSlash
resolveFilesUses an Eik JSON "files" definition to resolve files on disk into a data structure. Returns a list of ResolvedFile.
configStoreCollection 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.

NameDescription
eikJSONChecks that the given value includes required fields that are valid
nameChecks name
versionChecks version
typeChecks type
serverChecks server
filesChecks files
importMapChecks import-map
outChecks 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.

NameDescription
aliasChecks that a value is a valid alias value (ex 1)
nameChecks that a value is a valid package name
orgChecks that a value is a valid organisation name.
originCheck that a value looks like an HTTP origin.
versionChecks that a value is a valid semver version
semverTypeChecks that a value is a valid semver type (major, minor, patch)
typeChecks that the value is a valid Eik type (pkg, npm, map)

FAQs

Package last updated on 16 Aug 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc