-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(mf-parser): provide getInfo advanced typings (#241)
Refs: #231 (comment) Refs: #226
- Loading branch information
Showing
12 changed files
with
358 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import type { | ||
DisplayPart, | ||
EA, | ||
Element, | ||
FlattenOptions, | ||
Parts, | ||
} from './MF.types'; | ||
import { MFInternal } from './MFInternal'; | ||
import type { | ||
GetInfoOptions, | ||
GetInfoOptionsAllowed, | ||
PartInfo, | ||
PartInfoWithParts, | ||
} from './util/getInfo.types'; | ||
import type { IsotopesInfo } from './util/getIsotopesInfo.types'; | ||
|
||
export interface MFConstructorOptions { | ||
ensureCase?: boolean; | ||
} | ||
|
||
export class MF { | ||
private readonly internal: MFInternal; | ||
|
||
constructor(mf: string, options: MFConstructorOptions = {}) { | ||
this.internal = new MFInternal(mf, options); | ||
} | ||
|
||
/** | ||
* Returns an array of objects with kind and value that can be used to easily | ||
* display the molecular formula. | ||
*/ | ||
toDisplay(): DisplayPart[] { | ||
return this.internal.toDisplay(); | ||
} | ||
|
||
/** | ||
* Returns a string that represents the molecular formula adding subscript and superscript in HTML. | ||
*/ | ||
toHtml(): string { | ||
return this.internal.toHtml(); | ||
} | ||
|
||
/** | ||
* Returns a string that represents the molecular formula adding subscript and superscript | ||
* using Unicode characters. This can not be parsed anymore so kind of dead end ... | ||
*/ | ||
toText(): string { | ||
return this.internal.toText(); | ||
} | ||
|
||
/** | ||
* Similar to toText but returns a canonic string in which the atoms are sorted using the Hill system | ||
*/ | ||
toCanonicText(): string { | ||
return this.internal.toCanonicText(); | ||
} | ||
|
||
toParts(options?: { expand?: boolean }): Parts[] { | ||
return this.internal.toParts(options); | ||
} | ||
|
||
/** | ||
* Returns an object with the global MF, global charge, monoisotopic mass and mass | ||
* as well as the same information for all the parts | ||
*/ | ||
getInfo<GIO extends GetInfoOptionsAllowed = GetInfoOptions>( | ||
options?: GIO, | ||
): PartInfo<GIO> | PartInfoWithParts<GIO> { | ||
return this.internal.getInfo(options); | ||
} | ||
|
||
/** | ||
* Returns an object with the elemental analysis | ||
*/ | ||
getEA(): EA[] { | ||
return this.internal.getEA(); | ||
} | ||
|
||
/** | ||
* Get the different elements for each part | ||
*/ | ||
getElements(): Element[] { | ||
return this.internal.getElements(); | ||
} | ||
|
||
/** | ||
* Returns an array with each atom and isotopic composition | ||
*/ | ||
getIsotopesInfo(options = {}): IsotopesInfo | [] { | ||
return this.internal.getIsotopesInfo(options); | ||
} | ||
|
||
/** | ||
* Get a canonized parsable Molecule Formula | ||
*/ | ||
toMF(): string { | ||
return this.internal.toMF(); | ||
} | ||
|
||
/** | ||
* Get a canonized MF | ||
*/ | ||
toNeutralMF(): string { | ||
return this.internal.toNeutralMF(); | ||
} | ||
|
||
canonize(): void { | ||
return this.internal.canonize(); | ||
} | ||
|
||
flatten(options?: FlattenOptions): string[] { | ||
return this.internal.flatten(options); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
/** | ||
* Temporary interface for incremental migrations to typescript | ||
*/ | ||
|
||
/** | ||
* approximately toDisplay return type | ||
*/ | ||
export interface DisplayPart { | ||
kind: string; | ||
value: string; | ||
} | ||
|
||
/** | ||
* approximately toParts return type | ||
*/ | ||
// eslint-disable-next-line @typescript-eslint/no-explicit-any | ||
export type Parts = any[]; | ||
|
||
/** | ||
* approximately getEA return type | ||
*/ | ||
export interface EA { | ||
element: string; | ||
mass: number; | ||
ratio: number; | ||
} | ||
|
||
/** | ||
* approximately getElements return type | ||
*/ | ||
export interface Element { | ||
symbol: string; | ||
number: number; | ||
isotope?: number; | ||
} | ||
|
||
/** | ||
* approximately flatten options type | ||
*/ | ||
export interface FlattenOptions { | ||
/** @default false */ | ||
groupIdentical: boolean; | ||
/** @default 100000 */ | ||
limit: number; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.