Skip to content

Commit

Permalink
refactor!: migrate to TypeScript (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: Adithya Krishna <adikrish@redhat.com>
  • Loading branch information
adithyaakrishna committed Aug 8, 2023
1 parent bea14eb commit 9bf14de
Show file tree
Hide file tree
Showing 39 changed files with 875 additions and 747 deletions.
3 changes: 0 additions & 3 deletions .babelrc

This file was deleted.

4 changes: 1 addition & 3 deletions .eslintrc.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1 @@
extends: cheminfo
parserOptions:
sourceType: module
extends: cheminfo-typescript
21 changes: 0 additions & 21 deletions .github/workflows/documentationjs.yml

This file was deleted.

2 changes: 2 additions & 0 deletions .github/workflows/nodejs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ jobs:
nodejs:
# Documentation: https://github.com/zakodium/workflows#nodejs-ci
uses: zakodium/workflows/.github/workflows/nodejs.yml@nodejs-v1
with:
lint-check-types: true
32 changes: 32 additions & 0 deletions .github/workflows/typedoc.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Deploy TypeDoc on GitHub pages

on:
workflow_dispatch:
release:
types: [published]

env:
NODE_VERSION: 16.x
ENTRY_FILE: 'src/index.ts'

jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v2
with:
node-version: ${{ env.NODE_VERSION }}
- name: Install dependencies
run: npm install
- name: Build documentation
uses: zakodium/typedoc-action@v2
with:
entry: ${{ env.ENTRY_FILE }}
- name: Deploy to GitHub pages
uses: JamesIves/github-pages-deploy-action@releases/v4
with:
token: ${{ secrets.BOT_TOKEN }}
branch: gh-pages
folder: docs
clean: true
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ dist/
.vscode
docs
lib
lib-esm
.eslintcache
7 changes: 7 additions & 0 deletions .prettierrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"arrowParens": "always",
"semi": true,
"singleQuote": true,
"tabWidth": 2,
"trailingComma": "all"
}
15 changes: 8 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# netcdfjs

[![NPM version][npm-image]][npm-url]
[![build status][travis-image]][travis-url]
[![Test coverage][coveralls-image]][coveralls-url]
[![build status][ci-image]][ci-url]
[![Test coverage][codecov-image]][codecov-url]
[![npm download][download-image]][download-url]

Read and explore NetCDF v3 files.
Expand Down Expand Up @@ -32,9 +32,10 @@ reader.getDataVariable("wmoId"); // go to offset and read it

[MIT](./LICENSE)

[npm-image]: https://img.shields.io/npm/v/netcdfjs.svg?style=flat-square
[npm-image]: https://img.shields.io/npm/v/netcdfjs.svg
[npm-url]: https://www.npmjs.com/package/netcdfjs
[coveralls-image]: https://img.shields.io/coveralls/cheminfo/netcdfjs.svg?style=flat-square
[coveralls-url]: https://coveralls.io/github/cheminfo/netcdfjs
[download-image]: https://img.shields.io/npm/dm/netcdfjs.svg?style=flat-square
[download-url]: https://www.npmjs.com/package/netcdfjs
[ci-image]: https://github.com/cheminfo/netcdfjs/workflows/Node.js%20CI/badge.svg?branch=main
[ci-url]: https://github.com/cheminfo/netcdfjs/actions?query=workflow%3A%22Node.js+CI%22
[codecov-image]: https://img.shields.io/codecov/c/github/cheminfo/netcdfjs.svg
[codecov-url]: https://codecov.io/gh/cheminfo/netcdfjs
[download-image]: https://img.shields.io/npm/dm/netcdfjs.svg
24 changes: 0 additions & 24 deletions demo/agilent.js

This file was deleted.

20 changes: 20 additions & 0 deletions demo/agilent.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { readFileSync as rfs } from 'node:fs';
import { join } from 'node:path';

import { NetCDFReader } from '../src/index';

const data = rfs(join(__dirname, '../src/__tests__/files/agilent_hplc.cdf'));

let reader = new NetCDFReader(data);

let selectedVariable = reader.variables[4];

reader.getDataVariable(selectedVariable);

for (let variable of reader.variables) {
console.log(variable.name, reader.getDataVariable(variable));
}

let ordinates = reader.getDataVariable(reader.variables[5]);
console.log(Math.max(...(ordinates as number[])));
console.log(Math.min(...(ordinates as number[])));
4 changes: 4 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
preset: 'ts-jest/presets/js-with-ts',
testEnvironment: 'node',
};
44 changes: 26 additions & 18 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@
"name": "netcdfjs",
"version": "2.0.2",
"description": "Read and explore NetCDF files",
"main": "lib/index.js",
"module": "src/index.js",
"main": "./lib/index.js",
"module": "./lib-esm/index.js",
"types": "./lib/index.d.ts",
"files": [
"src",
"lib",
"lib-esm"
],
"keywords": [
"netcdf",
"nc",
"data",
"format"
],
"files": [
"src",
"lib"
],
"author": "Miguel Asencio <maasencioh@gmail.com> (https://github.com/maasencioh)",
"repository": "cheminfo/netcdfjs",
"bugs": {
Expand All @@ -22,24 +24,30 @@
"homepage": "https://github.com/cheminfo/netcdfjs",
"license": "MIT",
"scripts": {
"build": "cheminfo-build --entry src/index.js --root NetCDF",
"eslint": "eslint src",
"eslint-fix": "npm run eslint -- --fix",
"prepack": "rollup -c",
"check-types": "tsc --noEmit",
"clean": "rimraf lib lib-esm",
"eslint": "eslint src --cache",
"eslint:fix": "npm run eslint -- --fix",
"prepack": "npm run tsc",
"prettier": "prettier --check src",
"prettier-write": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier",
"test-only": "jest --coverage"
"prettier:fix": "prettier --write src",
"test": "npm run test-only && npm run eslint && npm run prettier && npm run check-types",
"test-only": "jest --coverage",
"tsc": "npm run clean && npm run tsc-cjs && npm run tsc-esm",
"tsc-cjs": "tsc --project tsconfig.cjs.json",
"tsc-esm": "tsc --project tsconfig.esm.json"
},
"devDependencies": {
"@babel/plugin-transform-modules-commonjs": "^7.19.6",
"@types/jest": "^29.2.0",
"@types/jest": "^29.2.3",
"cheminfo-build": "^1.1.11",
"cheminfo-types": "^1.4.0",
"eslint": "^8.25.0",
"eslint-config-cheminfo": "^8.0.2",
"jest": "^29.2.1",
"eslint-config-cheminfo-typescript": "^11.2.2",
"eslint-plugin-import": "^2.28.0",
"jest": "^29.3.1",
"prettier": "^2.7.1",
"rollup": "^3.2.3"
"ts-jest": "^29.0.3",
"typescript": "^4.9.3"
},
"dependencies": {
"iobuffer": "^5.2.1"
Expand Down
10 changes: 0 additions & 10 deletions rollup.config.mjs

This file was deleted.

13 changes: 0 additions & 13 deletions src/__tests__/attributeExists.test.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/__tests__/attributeExists.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFileSync } from 'fs';

import { NetCDFReader } from '../parser';

const pathFiles = `${__dirname}/files/`;

test('attributeExists', () => {
const data = readFileSync(`${pathFiles}P071.CDF`);

let reader = new NetCDFReader(data);
expect(reader.attributeExists('operator_name')).toBe(true);
expect(reader.attributeExists('operator_nameXX')).toBe(false);
});
13 changes: 0 additions & 13 deletions src/__tests__/dataVariableExists.test.js

This file was deleted.

13 changes: 13 additions & 0 deletions src/__tests__/dataVariableExists.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import { readFileSync } from 'fs';

import { NetCDFReader } from '../parser';

const pathFiles = `${__dirname}/files/`;

test('dataVariableExists', () => {
const data = readFileSync(`${pathFiles}P071.CDF`);

let reader = new NetCDFReader(data);
expect(reader.dataVariableExists('instrument_name')).toBe(true);
expect(reader.dataVariableExists('instrument_nameXX')).toBe(false);
});
12 changes: 0 additions & 12 deletions src/__tests__/getAttribute.test.js

This file was deleted.

12 changes: 12 additions & 0 deletions src/__tests__/getAttribute.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readFileSync } from 'fs';

import { NetCDFReader } from '../parser';

const pathFiles = `${__dirname}/files/`;

test('getAttribute', () => {
const data = readFileSync(`${pathFiles}P071.CDF`);

let reader = new NetCDFReader(data);
expect(reader.getAttribute('operator_name')).toBe('SC');
});
14 changes: 0 additions & 14 deletions src/__tests__/getDataVariableAsString.test.js

This file was deleted.

14 changes: 14 additions & 0 deletions src/__tests__/getDataVariableAsString.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import { readFileSync } from 'fs';

import { NetCDFReader } from '../parser';

const pathFiles = `${__dirname}/files/`;

test('getDataVariableAsString', () => {
const data = readFileSync(`${pathFiles}P071.CDF`);

let reader = new NetCDFReader(data);
expect(reader.getDataVariableAsString('instrument_name')).toBe(
'Gas Chromatograph',
);
});

0 comments on commit 9bf14de

Please sign in to comment.