@eik/node-client
Advanced tools
Comparing version 1.0.1 to 1.1.0
@@ -0,1 +1,8 @@ | ||
# [1.1.0](https://github.com/eik-lib/node-client/compare/v1.0.1...v1.1.0) (2021-11-05) | ||
### Features | ||
* Add .base() method to retrieve a base URL to a package ([#33](https://github.com/eik-lib/node-client/issues/33)) ([1dae896](https://github.com/eik-lib/node-client/commit/1dae89696911e6257bf9f89078e2e68e139291c5)) | ||
## [1.0.1](https://github.com/eik-lib/node-client/compare/v1.0.0...v1.0.1) (2021-11-03) | ||
@@ -2,0 +9,0 @@ |
{ | ||
"name": "@eik/node-client", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"description": "A node.js client for interacting with a Eik server.", | ||
@@ -5,0 +5,0 @@ "type": "module", |
@@ -111,8 +111,60 @@ # @eik/node-client | ||
Loads Eik config into the module. The config will be cached in the module. If `loadMaps` is set to `true` on the constructor, the import maps defined in the config will be loaded from the Eik server | ||
Loads Eik config from the Eik config into the object instance. If `loadMaps` is set to `true` on the constructor, the import maps defined in the config will be loaded from the Eik server. | ||
### .base() | ||
Constructs a URL to the base of a package of assets. The returned value will differ depending on if development mode is set to true or not. | ||
When in non development mode, the returned value will be built up by the values found in the loaded Eik config and provide a URL to where the files can be expected to be on the Eik server. | ||
```js | ||
const client = new EikNodeClient({ | ||
development: false, | ||
base: 'http://localhost:8080/assets' | ||
}); | ||
await client.load(); | ||
client.base() // https://cdn.eik.dev/pkg/mymodue/2.4.1 | ||
``` | ||
When in development mode, the returned value will be equal to whats set on the `base` argument on the constructor. | ||
```js | ||
const client = new EikNodeClient({ | ||
development: true, | ||
base: 'http://localhost:8080/assets' | ||
}); | ||
await client.load(); | ||
client.base() // http://localhost:8080/assets | ||
``` | ||
### .file(file) | ||
Constructs a full URL to an asset. The URL is built up by appending the value of the `file` argument to a `base` root. By default (production mode) the `base` root is built up from values in Eik config matching where the package for the config are located on the Eik server. If the module is in development mode, the value set for `base` on the constructor will be used as the `base` root. | ||
Constructs a full URL to an asset. The URL is built up by appending the value of the `file` argument to a `base` root. The returned value will differ depending on if development mode is set to true or not. | ||
When in non development mode, the returned value will be built up by the values found in the loaded Eik config and provide a URL to where the files can be expected to be on the Eik server plus the provided value to the `file` argument on the method. | ||
```js | ||
const client = new EikNodeClient({ | ||
development: false, | ||
base: 'http://localhost:8080/assets' | ||
}); | ||
await client.load(); | ||
client.file('/js/script.js') // Returns an asset.value like: https://cdn.eik.dev/pkg/mymodue/2.4.1/js/script.js | ||
``` | ||
When in development mode, the returned value will be equal to whats set on the `base` argument on the constructor plus the provided value to the `file` argument on the method. | ||
```js | ||
const client = new EikNodeClient({ | ||
development: true, | ||
base: 'http://localhost:8080/assets' | ||
}); | ||
await client.load(); | ||
client.file('/js/script.js') // Returns an asset.value like: http://localhost:8080/assets/js/script.js | ||
``` | ||
#### arguments | ||
@@ -119,0 +171,0 @@ |
@@ -6,3 +6,6 @@ import { helpers } from '@eik/common'; | ||
const isUrl = (value = '') => value.startsWith('http'); | ||
const trimSlash = (value = '') => { | ||
if (value.endsWith('/')) return value.substring(0, value.length - 1); | ||
return value; | ||
} | ||
@@ -51,3 +54,3 @@ const fetchImportMaps = async (urls = []) => { | ||
this.#path = path; | ||
this.#base = base; | ||
this.#base = trimSlash(base); | ||
this.#maps = []; | ||
@@ -89,17 +92,12 @@ } | ||
base() { | ||
if (this.#development) return this.#base; | ||
return `${this.server}${this.pathname}`; | ||
} | ||
file(file = '') { | ||
const asset = new Asset(); | ||
if (this.#development) { | ||
if (isUrl(this.#base)) { | ||
const base = new URL(this.#base); | ||
asset.value = new URL(join(base.pathname, file), base).href; | ||
} else { | ||
asset.value = join(this.#base, file); | ||
} | ||
} else { | ||
asset.value = new URL(join(this.pathname, file), this.server).href; | ||
} | ||
return asset; | ||
const base = this.base(); | ||
return new Asset({ | ||
value: `${base}${file}`, | ||
}); | ||
} | ||
@@ -106,0 +104,0 @@ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23332
211
203