Skip to content

Commit

Permalink
Merge pull request #67 from bioinformatics-ua/change/pure-esm
Browse files Browse the repository at this point in the history
Change to pure ECMAScript modules
  • Loading branch information
Enet4 authored Oct 11, 2023
2 parents 8285169 + 9bba89b commit 9bf1fad
Show file tree
Hide file tree
Showing 28 changed files with 705 additions and 5,142 deletions.
10 changes: 0 additions & 10 deletions .babelrc

This file was deleted.

2 changes: 1 addition & 1 deletion .c8rc
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"extension": [
".js"
".ts"
],
"exclude": [
"gulpfile.js",
Expand Down
2 changes: 1 addition & 1 deletion .eslintrc
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"plugin:@typescript-eslint/recommended"
],
"parserOptions": {
"ecmaVersion": 6,
"ecmaVersion": 2019,
"sourceType": "module"
},
"parser": "@typescript-eslint/parser",
Expand Down
5 changes: 4 additions & 1 deletion .mocharc.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"extension": ["ts"],
"spec": ["test/*.test.ts"],
"require": "ts-node/register"
"require": "ts-node/register",
"node-option": [
"loader=ts-node/esm"
]
}
51 changes: 23 additions & 28 deletions README.docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

`dicoogle-client` is a client API to the web services provided by [Dicoogle](https://www.dicoogle.com), the open-source PACS archive, for use in JavaScript applications.

This library is compatible with Dicoogle versions 2 and 3.

## Top-level API

Documentation was built from our TypeScript definitions, and should be automatically considered by the TypeScript compiler (version 4+).
Expand All @@ -14,38 +16,33 @@ Documentation was built from our TypeScript definitions, and should be automatic

## Installing

### In Node.js
### Node.js

Install "dicoogle-client" with `npm` and import the default export
or the named export `dicoogleClient`
from the "dicoogle-client" module.
Install `dicoogle-client` with `npm` and
import the _default_ export or the named export `dicoogleClient`.
This works both in JavaScript and in TypeScript.

```javascript
import dicoogleClient from 'dicoogle-client';
```

When not using ES2015 modules, you need to retrieve the export manually:

```typescript
const {dicoogleClient} = require('dicoogle-client');
```

### On the browser, no module system

When _not_ using Node.js or any module system,
you can build the distributable bundle by running:
When not using ECMAScript modules (e.g. using CommonJS),
you need to use an interoperability layer such as [Babel](https://babeljs.io).
Otherwise, the module will need to be imported dynamically:

```sh
npm run build
```javascript
import('dicoogle-client')
.then(m => {
const dicoogleClient = m.default;
});
```

Then include the "dist/dicoogle-client.min.js" file as a script,
thus exposing the `DicoogleClient` module as a global variable.
### On a Browser with Bundling

```html
<script src='path/to/my/libs/dicoogle-client.min.js'></script>
```
Install and use `dicoogle-client` like in Node.js.
The library includes a few uses of `process.env.NODE_ENV`,
which will need to be replaced in a browser environment.
See an example of this using webpack [here](https://webpack.js.org/plugins/environment-plugin/#root).

## Basic Usage

Expand All @@ -55,7 +52,7 @@ Calling the module function again will change the Dicoogle base URL of that obje
This object provides a Promise-based API.
You can write the following code inside an async function:

```JavaScript
```javascript
const dicoogle = dicoogleClient("localhost:8080");

// if required, login to the system before using
Expand All @@ -73,8 +70,8 @@ for (const r of result) {

Alternatively, the same methods work when passing a callback as the last parameter.

```JavaScript
const dicoogle = dicoogleClient("localhost:8080").default;
```javascript
const dicoogle = dicoogleClient("localhost:8080");

// if required, login to the system before using
dicoogle.login('admin', 'mysecretpassword', function(error, outcome) {
Expand All @@ -99,7 +96,5 @@ dicoogle.login('admin', 'mysecretpassword', function(error, outcome) {

## Examples

The repository includes two examples of dicoogle-client for simple querying:

- "bin/dicoogle-query-cli.js" is a complete stand-alone Node.js application for querying Dicoogle. This is the source code of the `dicoogle-query` executable.
- "example/app.html" is a web page demonstrating simple querying.
- "bin/dicoogle-query-cli.js" is a complete stand-alone Node.js application for querying Dicoogle.
This is the source code of the `dicoogle-query` executable.
7 changes: 3 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
This is a web service client API to [Dicoogle](http://www.dicoogle.com), the open-source PACS archive, for use in JavaScript applications.
This library is compatible with browser-based JavaScript and Node.js. A CLI application for searching medical images in Dicoogle is also included (`dicoogle-query`).

This library intends to be fully compatible with Dicoogle versions 2 and 3,
and may be updated as future versions of Dicoogle are released.

## Using the JavaScript API

The full API is documented [here](https://bioinformatics-ua.github.io/dicoogle-client-js).
Expand Down Expand Up @@ -53,10 +56,6 @@ Install this package globally (`npm install -g dicoogle-client`), then use `dico

**Example:** `dicoogle-query -p lucene -s "http://demo.dicoogle.com" "Modality:MR"`

## Further Notice

This library is compatible with versions of Dicoogle in the range `>=2.0.0 <3.2.0`, and may be updated as future versions of Dicoogle are released.

## License

Copyright (C) 2016 Universidade de Aveiro, DETI/IEETA, Bioinformatics Group - http://bioinformatics.ua.pt/
Expand Down
31 changes: 15 additions & 16 deletions bin/dicoogle-query-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,23 +6,22 @@
*
* Usage:
* dicoogle-query [-k] [-s server_location] [-p provider_name]* QUERY
*
* @author Eduardo Pinho ([email protected])
*/
var dicoogleClient = require("../lib");
var util = require('util');
var server = "http://localhost:8080";
var query;
var keyword = undefined;
var debug = false;
var forceTTY = false;
var forceJSON = false;
var providers = [];
import dicoogleClient from "../lib/index.js";
import { inspect } from 'node:util';

let server = "http://localhost:8080";
let query;
let keyword = undefined;
let debug = false;
let forceTTY = false;
let forceJSON = false;
let providers = [];

var USER = process.env.DICOOGLE_USER;
var PASSWORD = process.env.DICOOGLE_PASSWORD;
let USER = process.env.DICOOGLE_USER;
let PASSWORD = process.env.DICOOGLE_PASSWORD;

for (var i = 2; i < process.argv.length; i++) {
for (let i = 2; i < process.argv.length; i++) {
if (process.argv[i] === '--help' || process.argv[i] === '-h') {
console.log("Usage: dicoogle-query [OPTIONS] QUERY");
console.log("Description: search for images in Dicoogle using text queries\n");
Expand Down Expand Up @@ -75,7 +74,7 @@ process.stdout.on('error', function() {
// ignore problem, the user must have just closed the consumer
});

var Dicoogle = dicoogleClient(server);
let Dicoogle = dicoogleClient(server);

if (USER && PASSWORD) {
Dicoogle.login(USER, PASSWORD, function(err, out) {
Expand Down Expand Up @@ -105,7 +104,7 @@ function doSearch() {
} else {
var result = outcome.results || [];
if ((process.stdout.isTTY && !forceJSON) || forceTTY) {
console.log(util.inspect(result, {colors: true, depth: 2}));
console.log(inspect(result, {colors: true, depth: 2}));
} else {
console.log(JSON.stringify(result));
}
Expand Down
63 changes: 0 additions & 63 deletions gulpfile.js

This file was deleted.

12 changes: 0 additions & 12 deletions jsconfig.json

This file was deleted.

Loading

0 comments on commit 9bf1fad

Please sign in to comment.