@eik/common

中文文档
5.2.2发布于 2026/11/03ISCTypeScriptES Module构建来源已验证近 30 天下载 5587

Common utilities for Eik modules

原始使用文档
文档目录6 节
  1. Schema
  2. API
  3. helpers
  4. schemas
  5. stream
  6. validators

@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.
fetchImportMapsHelper to get import maps (array of URLs) with some common error handling.

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)

版本与发布记录

@eik/common 共发布 86 个版本,首次发布于 2019/11/15;过去 12 个月发布了 27 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
5.2.2latest2026/11/0310 天前
5.2.12026/08/212 个月前
5.2.02026/08/192 个月前
5.1.342026/06/204 个月前
5.1.332026/06/105 个月前
5.1.322026/06/095 个月前

其他发布通道:next → 4.0.0-next.7。

关于 @eik/common 的常见问题

@eik/common 是什么?

Common utilities for Eik modules

如何安装 @eik/common?

在项目目录运行 npm install @eik/common,或使用 pnpm add / yarn add / bun add。

@eik/common 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@eik/common 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@eik/common 可以商用吗?

@eik/common 使用 ISC 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@eik/common 的下载量有多少?

根据 npm 官方下载统计,@eik/common 在 2026/10/13 – 2026/11/11 这 30 天内被下载 5,587 次,日均约 186 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@eik/common 还在维护吗?

最新版本 5.2.2 发布于 2026/11/03(10 天前);至今共发布 86 个版本,其中过去 12 个月发布了 27 个;首次发布于 2019/11/15。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。