3.0.1 • Published 2 years ago

@eik/common v3.0.1

Weekly downloads
445
License
ISC
Repository
github
Last release
2 years ago

Eik Commons

This package contains common utilities and schemas

APIs

schemas

eik.json

Importing schemas

const { schemas, assert } = require('@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: [],
});

//or

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');

// or

assert.name('my-app');
version
const { error, value } = schemas.validate.version('1.0.0');

// or

assert.version('1.0.0');
type
const { error, value } = schemas.validate.type('package');

// or

assert.type('package');
server
const { error, value } = schemas.validate.server('http://myeikserver.com');

// or

assert.server('http://myeikserver.com');
files
const { error, value } = schemas.validate.files({
    './index.js': '/path/to/file.js',
});

// or

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',
]);

// or

assert.importMap([
    'http://meserver.com/map1.json',
    'http://meserver.com/map2.json',
]);
out
const { error, value } = schemas.validate.out('./.eik');

// or

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

const express = require('express');
const { helpers } = require('@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

const { helpers } = require('@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

4.0.0-next.7

2 years ago

4.0.0-next.6

2 years ago

4.0.0-next.5

2 years ago

3.0.1

2 years ago

3.0.0

3 years ago

4.0.0-next.4

3 years ago

4.0.0-next.3

3 years ago

4.0.0-next.2

3 years ago

4.0.0-next.1

3 years ago

3.0.0-next.1

3 years ago

2.0.3

3 years ago

2.0.2

3 years ago

2.0.1

3 years ago

2.0.0

3 years ago

1.6.0

3 years ago

1.5.0

3 years ago

1.4.2

3 years ago

1.4.1

3 years ago

1.4.0

3 years ago

1.3.3

3 years ago

1.3.2

3 years ago

1.3.1

3 years ago

1.3.0

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago

1.0.0-alpha.7

4 years ago

1.0.0-alpha.6

4 years ago

1.0.0-alpha.5

4 years ago

1.0.0-alpha.4

4 years ago

1.0.0-alpha.3

4 years ago

1.0.0-alpha.2

4 years ago

1.0.0-alpha.1

4 years ago