@chemistry/formula 3.1.1 → 3.1.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +14 -25
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
# @chemistry/formula
|
|
2
2
|
|
|
3
|
-
[](https://opensource.org/licenses/MIT)
|
|
3
|
+
[](https://www.npmjs.com/package/@chemistry/formula)
|
|
5
4
|
|
|
6
|
-
|
|
5
|
+
Chemical formula parser — parse, stringify, and calculate molecular weight.
|
|
7
6
|
|
|
8
|
-
##
|
|
7
|
+
## Installation
|
|
9
8
|
|
|
10
9
|
```bash
|
|
11
10
|
npm install @chemistry/formula
|
|
@@ -16,32 +15,22 @@ npm install @chemistry/formula
|
|
|
16
15
|
```typescript
|
|
17
16
|
import { Formula } from '@chemistry/formula';
|
|
18
17
|
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
console.log(formula); // { C: 2, H: 6, O: 1 }
|
|
18
|
+
const parsed = Formula.parse('C2H5OH');
|
|
19
|
+
// { C: 2, H: 6, O: 1 }
|
|
22
20
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
console.log(str); // C2H6O
|
|
21
|
+
const weight = Formula.convertToWeight(parsed);
|
|
22
|
+
// 46.069
|
|
26
23
|
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
console.log(weight); // 46.069...
|
|
24
|
+
const str = Formula.stringify(parsed);
|
|
25
|
+
// "C2H6O"
|
|
30
26
|
```
|
|
31
27
|
|
|
32
|
-
##
|
|
28
|
+
## Features
|
|
33
29
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
### `Formula.convertToString(formula: Record<string, number>): string`
|
|
39
|
-
|
|
40
|
-
Converts an element count object back to a formatted formula string (Hill system order: C first, H second, then alphabetical).
|
|
41
|
-
|
|
42
|
-
### `Formula.convertToWeight(formula: Record<string, number>): number`
|
|
43
|
-
|
|
44
|
-
Calculates the molecular weight from an element count object using standard atomic masses.
|
|
30
|
+
- Parse chemical formulas into element counts
|
|
31
|
+
- Calculate molecular weight
|
|
32
|
+
- Stringify parsed formulas back to string
|
|
33
|
+
- Isomorphic — works in Node.js and browsers
|
|
45
34
|
|
|
46
35
|
## License
|
|
47
36
|
|