Skip to content

Commit

Permalink
feat: add types in the code
Browse files Browse the repository at this point in the history
  • Loading branch information
jobo322 committed Feb 14, 2024
1 parent d50afc6 commit b602345
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions src/index.js → src/index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { join } from 'path';

import { DataXY } from 'cheminfo-types';
import { FileCollection } from 'file-collection';
import { convert } from 'jcampconverter';
import { xySortX } from 'ml-spectra-processing';

const path = join(__dirname, '../data/');

async function getFileCollection() {
type ConvertResult = ReturnType<typeof convert>;

async function getFileCollection(): Promise<FileCollection> {
const fileCollection = new FileCollection();
await fileCollection.appendPath(path);
fileCollection.files.forEach((file) => {
Expand All @@ -15,12 +18,12 @@ async function getFileCollection() {
return fileCollection;
}

export async function getList() {
export async function getList(): Promise<string[]> {
const fileCollection = await getFileCollection();
return fileCollection.files.map((f) => f.relativePath);
}

export async function getFile(relativePath) {
export async function getFile(relativePath: string) {
const fileCollection = await getFileCollection();
const file = fileCollection.files.find(
(d) => d.relativePath === relativePath,
Expand All @@ -31,13 +34,13 @@ export async function getFile(relativePath) {
return file;
}

export async function getParsedFile(name) {
export async function getParsedFile(name: string): Promise<ConvertResult> {
const file = await getFile(name);
const jcamp = await file.text();
return convert(jcamp, { noContour: true });
}

export async function getXY(name) {
export async function getXY(name: string): Promise<DataXY> {
const parsed = await getParsedFile(name);
const firstSpectrum = parsed.flatten[0]?.spectra[0]?.data;
return xySortX(firstSpectrum);
Expand Down

0 comments on commit b602345

Please sign in to comment.