Eik Common
This package contains common utilities and schemas
ESM ONLY
From v4, this module is ESM only and cannot be used with Common JS.
APIs
schemas
eik.json
Importing schemas
import { schemas, assert } from '@eik/common';
Validating an eik.json
file
const { error, value } = schemas.validate.eikJSON({
name: 'my-app',
version: '1.0.0',
server: 'http://eik-server',
files: [],
});
assert.eikJSON({
name: 'my-app',
version: '1.0.0',
server: 'http://eik-server',
files: [],
});
Using individual schema validators
name
const { error, value } = schemas.validate.name('my-app');
assert.name('my-app');
version
const { error, value } = schemas.validate.version('1.0.0');
assert.version('1.0.0');
type
const { error, value } = schemas.validate.type('package');
assert.type('package');
server
const { error, value } = schemas.validate.server('http://myeikserver.com');
assert.server('http://myeikserver.com');
files
const { error, value } = schemas.validate.files({
'./index.js': '/path/to/file.js',
});
assert.files({
'./index.js': '/path/to/file.js',
});
import map
const { error, value } = schemas.validate.importMap(
'http://meserver.com/map.json',
);
const { error, value } = schemas.validate.importMap([
'http://meserver.com/map1.json',
'http://meserver.com/map2.json',
]);
assert.importMap([
'http://meserver.com/map1.json',
'http://meserver.com/map2.json',
]);
out
const { error, value } = schemas.validate.out('./.eik');
assert.out('./.eik');
helpers
localAssets
A function to help development by mounting development routes to an Express.js or Fastify app based on values defined in eik.json
import express from 'express';
import { helpers } from '@eik/common';
const app = express();
await helpers.localAssets(app);
For an eik.json
file such as
{
"name": "my-app",
"version": "1.0.0",
"server": "https://assets.myeikserver.com",
"files": {
"esm.js": "./assets/esm.js",
"esm.css": "./assets/esm.css",
"/": "./assets/**/*.map"
}
}
A number of routes would be mounted into your app.
/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
packageURL
This helper function can be used to build URLs for given entries in an eik.json
files section.
Given the following eik.json
file:
{
"name": "my-app",
"version": "1.0.0",
"server": "https://assets.myeikserver.com",
"files": {
"esm.js": "./assets/esm.js",
"esm.css": "./assets/esm.css",
"/": "./assets/**/*.map"
}
}
and the following call to packageURL
import { helpers } from '@eik/common';
const url = await helpers.packageURL('esm.js');
The URL returned will be https://assets.myeikserver.com/pkg/my-app/1.0.0/esm.js