mozithermodb-settings 1.0.0

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/LICENSE ADDED
@@ -0,0 +1,201 @@
1
+ Apache License
2
+ Version 2.0, January 2004
3
+ http://www.apache.org/licenses/
4
+
5
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6
+
7
+ 1. Definitions.
8
+
9
+ "License" shall mean the terms and conditions for use, reproduction,
10
+ and distribution as defined by Sections 1 through 9 of this document.
11
+
12
+ "Licensor" shall mean the copyright owner or entity authorized by
13
+ the copyright owner that is granting the License.
14
+
15
+ "Legal Entity" shall mean the union of the acting entity and all
16
+ other entities that control, are controlled by, or are under common
17
+ control with that entity. For the purposes of this definition,
18
+ "control" means (i) the power, direct or indirect, to cause the
19
+ direction or management of such entity, whether by contract or
20
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
21
+ outstanding shares, or (iii) beneficial ownership of such entity.
22
+
23
+ "You" (or "Your") shall mean an individual or Legal Entity
24
+ exercising permissions granted by this License.
25
+
26
+ "Source" form shall mean the preferred form for making modifications,
27
+ including but not limited to software source code, documentation
28
+ source, and configuration files.
29
+
30
+ "Object" form shall mean any form resulting from mechanical
31
+ transformation or translation of a Source form, including but
32
+ not limited to compiled object code, generated documentation,
33
+ and conversions to other media types.
34
+
35
+ "Work" shall mean the work of authorship, whether in Source or
36
+ Object form, made available under the License, as indicated by a
37
+ copyright notice that is included in or attached to the work
38
+ (an example is provided in the Appendix below).
39
+
40
+ "Derivative Works" shall mean any work, whether in Source or Object
41
+ form, that is based on (or derived from) the Work and for which the
42
+ editorial revisions, annotations, elaborations, or other modifications
43
+ represent, as a whole, an original work of authorship. For the purposes
44
+ of this License, Derivative Works shall not include works that remain
45
+ separable from, or merely link (or bind by name) to the interfaces of,
46
+ the Work and Derivative Works thereof.
47
+
48
+ "Contribution" shall mean any work of authorship, including
49
+ the original version of the Work and any modifications or additions
50
+ to that Work or Derivative Works thereof, that is intentionally
51
+ submitted to Licensor for inclusion in the Work by the copyright owner
52
+ or by an individual or Legal Entity authorized to submit on behalf of
53
+ the copyright owner. For the purposes of this definition, "submitted"
54
+ means any form of electronic, verbal, or written communication sent
55
+ to the Licensor or its representatives, including but not limited to
56
+ communication on electronic mailing lists, source code control systems,
57
+ and issue tracking systems that are managed by, or on behalf of, the
58
+ Licensor for the purpose of discussing and improving the Work, but
59
+ excluding communication that is conspicuously marked or otherwise
60
+ designated in writing by the copyright owner as "Not a Contribution."
61
+
62
+ "Contributor" shall mean Licensor and any individual or Legal Entity
63
+ on behalf of whom a Contribution has been received by Licensor and
64
+ subsequently incorporated within the Work.
65
+
66
+ 2. Grant of Copyright License. Subject to the terms and conditions of
67
+ this License, each Contributor hereby grants to You a perpetual,
68
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69
+ copyright license to reproduce, prepare Derivative Works of,
70
+ publicly display, publicly perform, sublicense, and distribute the
71
+ Work and such Derivative Works in Source or Object form.
72
+
73
+ 3. Grant of Patent License. Subject to the terms and conditions of
74
+ this License, each Contributor hereby grants to You a perpetual,
75
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76
+ (except as stated in this section) patent license to make, have made,
77
+ use, offer to sell, sell, import, and otherwise transfer the Work,
78
+ where such license applies only to those patent claims licensable
79
+ by such Contributor that are necessarily infringed by their
80
+ Contribution(s) alone or by combination of their Contribution(s)
81
+ with the Work to which such Contribution(s) was submitted. If You
82
+ institute patent litigation against any entity (including a
83
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
84
+ or a Contribution incorporated within the Work constitutes direct
85
+ or contributory patent infringement, then any patent licenses
86
+ granted to You under this License for that Work shall terminate
87
+ as of the date such litigation is filed.
88
+
89
+ 4. Redistribution. You may reproduce and distribute copies of the
90
+ Work or Derivative Works thereof in any medium, with or without
91
+ modifications, and in Source or Object form, provided that You
92
+ meet the following conditions:
93
+
94
+ (a) You must give any other recipients of the Work or
95
+ Derivative Works a copy of this License; and
96
+
97
+ (b) You must cause any modified files to carry prominent notices
98
+ stating that You changed the files; and
99
+
100
+ (c) You must retain, in the Source form of any Derivative Works
101
+ that You distribute, all copyright, patent, trademark, and
102
+ attribution notices from the Source form of the Work,
103
+ excluding those notices that do not pertain to any part of
104
+ the Derivative Works; and
105
+
106
+ (d) If the Work includes a "NOTICE" text file as part of its
107
+ distribution, then any Derivative Works that You distribute must
108
+ include a readable copy of the attribution notices contained
109
+ within such NOTICE file, excluding those notices that do not
110
+ pertain to any part of the Derivative Works, in at least one
111
+ of the following places: within a NOTICE text file distributed
112
+ as part of the Derivative Works; within the Source form or
113
+ documentation, if provided along with the Derivative Works; or,
114
+ within a display generated by the Derivative Works, if and
115
+ wherever such third-party notices normally appear. The contents
116
+ of the NOTICE file are for informational purposes only and
117
+ do not modify the License. You may add Your own attribution
118
+ notices within Derivative Works that You distribute, alongside
119
+ or as an addendum to the NOTICE text from the Work, provided
120
+ that such additional attribution notices cannot be construed
121
+ as modifying the License.
122
+
123
+ You may add Your own copyright statement to Your modifications and
124
+ may provide additional or different license terms and conditions
125
+ for use, reproduction, or distribution of Your modifications, or
126
+ for any such Derivative Works as a whole, provided Your use,
127
+ reproduction, and distribution of the Work otherwise complies with
128
+ the conditions stated in this License.
129
+
130
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
131
+ any Contribution intentionally submitted for inclusion in the Work
132
+ by You to the Licensor shall be under the terms and conditions of
133
+ this License, without any additional terms or conditions.
134
+ Notwithstanding the above, nothing herein shall supersede or modify
135
+ the terms of any separate license agreement you may have executed
136
+ with Licensor regarding such Contributions.
137
+
138
+ 6. Trademarks. This License does not grant permission to use the trade
139
+ names, trademarks, service marks, or product names of the Licensor,
140
+ except as required for reasonable and customary use in describing the
141
+ origin of the Work and reproducing the content of the NOTICE file.
142
+
143
+ 7. Disclaimer of Warranty. Unless required by applicable law or
144
+ agreed to in writing, Licensor provides the Work (and each
145
+ Contributor provides its Contributions) on an "AS IS" BASIS,
146
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147
+ implied, including, without limitation, any warranties or conditions
148
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149
+ PARTICULAR PURPOSE. You are solely responsible for determining the
150
+ appropriateness of using or redistributing the Work and assume any
151
+ risks associated with Your exercise of permissions under this License.
152
+
153
+ 8. Limitation of Liability. In no event and under no legal theory,
154
+ whether in tort (including negligence), contract, or otherwise,
155
+ unless required by applicable law (such as deliberate and grossly
156
+ negligent acts) or agreed to in writing, shall any Contributor be
157
+ liable to You for damages, including any direct, indirect, special,
158
+ incidental, or consequential damages of any character arising as a
159
+ result of this License or out of the use or inability to use the
160
+ Work (including but not limited to damages for loss of goodwill,
161
+ work stoppage, computer failure or malfunction, or any and all
162
+ other commercial damages or losses), even if such Contributor
163
+ has been advised of the possibility of such damages.
164
+
165
+ 9. Accepting Warranty or Additional Liability. While redistributing
166
+ the Work or Derivative Works thereof, You may choose to offer,
167
+ and charge a fee for, acceptance of support, warranty, indemnity,
168
+ or other liability obligations and/or rights consistent with this
169
+ License. However, in accepting such obligations, You may act only
170
+ on Your own behalf and on Your sole responsibility, not on behalf
171
+ of any other Contributor, and only if You agree to indemnify,
172
+ defend, and hold each Contributor harmless for any liability
173
+ incurred by, or claims asserted against, such Contributor by reason
174
+ of your accepting any such warranty or additional liability.
175
+
176
+ END OF TERMS AND CONDITIONS
177
+
178
+ APPENDIX: How to apply the Apache License to your work.
179
+
180
+ To apply the Apache License to your work, attach the following
181
+ boilerplate notice, with the fields enclosed by brackets "[]"
182
+ replaced with your own identifying information. (Don't include
183
+ the brackets!) The text should be enclosed in the appropriate
184
+ comment syntax for the file format. We also recommend that a
185
+ file or class name and description of purpose be included on the
186
+ same "printed page" as the copyright notice for easier
187
+ identification within third-party archives.
188
+
189
+ Copyright [yyyy] [name of copyright owner]
190
+
191
+ Licensed under the Apache License, Version 2.0 (the "License");
192
+ you may not use this file except in compliance with the License.
193
+ You may obtain a copy of the License at
194
+
195
+ http://www.apache.org/licenses/LICENSE-2.0
196
+
197
+ Unless required by applicable law or agreed to in writing, software
198
+ distributed under the License is distributed on an "AS IS" BASIS,
199
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200
+ See the License for the specific language governing permissions and
201
+ limitations under the License.
package/README.md ADDED
@@ -0,0 +1,174 @@
1
+ # MoziThermoDB-Settings
2
+
3
+ [![npm version](https://badge.fury.io/js/mozithermodb-settings.svg)](https://badge.fury.io/js/mozithermodb-settings)
4
+ [![npm downloads](https://img.shields.io/npm/dm/mozithermodb-settings?color=brightgreen)](https://www.npmjs.com/package/mozithermodb-settings)
5
+ [![License: Apache-2.0](https://img.shields.io/badge/License-Apache%202.0-blue.svg)](https://opensource.org/licenses/Apache-2.0)
6
+
7
+ Shared TypeScript schemas, types, and utility functions for thermodynamic components and mixture identifiers in the Mozi ecosystem.
8
+
9
+ ## Features
10
+
11
+ - Zod schemas for temperature, pressure, volume, and custom properties
12
+ - Zod schemas and inferred types for thermodynamic components
13
+ - Consistent component identifier helpers
14
+ - Deterministic binary and multi-component mixture ID creation
15
+ - Component state setters with in-place mutation parity for interop scenarios
16
+ - ESM, CJS, browser, and `.d.ts` outputs
17
+
18
+ ## Installation
19
+
20
+ ```bash
21
+ npm install mozithermodb-settings
22
+ ```
23
+
24
+ ## Quick Start
25
+
26
+ ```ts
27
+ import {
28
+ ComponentSchema,
29
+ TemperatureSchema,
30
+ create_component_id,
31
+ create_mixture_id,
32
+ set_component_state,
33
+ } from "mozithermodb-settings";
34
+
35
+ const water = ComponentSchema.parse({
36
+ name: " Water ",
37
+ formula: " H2O ",
38
+ state: "l",
39
+ });
40
+
41
+ const temperature = TemperatureSchema.parse({
42
+ value: 298.15,
43
+ unit: "K",
44
+ source: "lab", // passthrough extra property
45
+ });
46
+
47
+ const identity = create_component_id(water);
48
+ // { name_state: "Water-l", formula_state: "H2O-l", name_formula: "Water-H2O" }
49
+
50
+ const mixture = create_mixture_id(
51
+ [
52
+ water,
53
+ { name: "Ethanol", formula: "C2H5OH", state: "l" },
54
+ { name: "Methanol", formula: "CH3OH", state: "l" },
55
+ ],
56
+ "Name",
57
+ );
58
+ // "Ethanol|Methanol|Water"
59
+
60
+ set_component_state(water, "g"); // mutates same object reference
61
+ ```
62
+
63
+ ## API
64
+
65
+ ### Condition Schemas
66
+
67
+ - `TemperatureSchema`
68
+ - `PressureSchema`
69
+ - `VolumeSchema`
70
+ - `CustomPropSchema`
71
+
72
+ All condition schemas are `z.looseObject(...)`, so unknown keys are preserved.
73
+
74
+ ### Component Schemas and Types
75
+
76
+ - `ComponentStateSchema`: `"g" | "l" | "s" | "aq"`
77
+ - `ComponentKeySchema`:
78
+ - `"Name-State"`
79
+ - `"Formula-State"`
80
+ - `"Name-Formula"`
81
+ - `"Name"`
82
+ - `"Formula"`
83
+ - `"Name-Formula-State"`
84
+ - `"Formula-Name-State"`
85
+ - `MixtureKeySchema`: same as `ComponentKeySchema`
86
+ - `BinaryMixtureKeySchema`: `"Name" | "Formula"`
87
+ - `ComponentSchema`:
88
+ - `name: string`
89
+ - `formula: string`
90
+ - `state: ComponentState`
91
+ - `mole_fraction: number` (default: `1`)
92
+ - `ComponentIdentitySchema`:
93
+ - `name_state: string`
94
+ - `formula_state: string`
95
+ - `name_formula: string`
96
+
97
+ Inferred TypeScript exports:
98
+
99
+ - `Temperature`, `Pressure`, `Volume`, `CustomProp`
100
+ - `ComponentState`, `ComponentKey`, `MixtureKey`, `BinaryMixtureKey`
101
+ - `Component`, `ComponentInput`, `ComponentIdentity`
102
+
103
+ ### Utility Functions
104
+
105
+ - `create_component_id(component, separator_symbol?)`
106
+ - Returns `{ name_state, formula_state, name_formula }`
107
+ - Trims fields and normalizes `state` to lowercase in state-based identifiers
108
+
109
+ - `set_component_id(component, component_key, separator_symbol?, case_value?)`
110
+ - Returns a string identifier for a selected key format
111
+ - `case_value` is `"lower" | "upper" | null`
112
+
113
+ - `create_binary_mixture_id(component_1, component_2, mixture_key?, delimiter?)`
114
+ - Supports `mixture_key`: `"Name"` or `"Formula"`
115
+ - Sorts component IDs before joining, so ordering is deterministic
116
+
117
+ - `create_mixture_id(components, mixture_key?, delimiter?, case_value?)`
118
+ - Supports all `MixtureKeySchema` key styles
119
+ - Sorts component IDs before joining
120
+ - Throws if `components` is empty
121
+
122
+ - `set_component_state(component, state)`
123
+ - Validates and mutates the original input object reference
124
+
125
+ - `set_components_state(components, state)`
126
+ - Applies `set_component_state` to each item
127
+
128
+ ### Errors
129
+
130
+ The package exports `ERRORS` from `src/core/errors.ts` for consistent error messages around:
131
+
132
+ - invalid component key
133
+ - invalid case value
134
+ - invalid mixture key
135
+ - empty component list
136
+ - delimiter type mismatch
137
+
138
+ ## Deterministic ID Behavior
139
+
140
+ Mixture ID helpers always sort generated component identifiers before joining with a delimiter:
141
+
142
+ - Binary: `[id1, id2].sort().join(delimiter)`
143
+ - Multi-component: `ids.sort().join(delimiter)`
144
+
145
+ This guarantees stable IDs independent of input order.
146
+
147
+ ## Build and Test
148
+
149
+ ```bash
150
+ npm run build
151
+ npm run typecheck
152
+ npm run lint
153
+ npm test
154
+ ```
155
+
156
+ Package outputs:
157
+
158
+ - `dist/index.mjs` (ESM)
159
+ - `dist/index.cjs` (CommonJS)
160
+ - `dist/index.browser.mjs` (browser ESM)
161
+ - `dist/index.d.ts` (types)
162
+
163
+ ## Example Script
164
+
165
+ See `examples/exp-1.ts` for a complete end-to-end usage sample covering:
166
+
167
+ - schema parsing
168
+ - component defaults
169
+ - component and mixture IDs
170
+ - state updates
171
+
172
+ ## License
173
+
174
+ Apache-2.0
@@ -0,0 +1,246 @@
1
+ import { z } from 'zod';
2
+
3
+ const ComponentStateSchema = z.enum(["g", "l", "s", "aq"]);
4
+ const ComponentKeySchema = z.enum([
5
+ "Name-State",
6
+ "Formula-State",
7
+ "Name-Formula",
8
+ "Name",
9
+ "Formula",
10
+ "Name-Formula-State",
11
+ "Formula-Name-State",
12
+ ]);
13
+ const MixtureKeySchema = ComponentKeySchema;
14
+ const BinaryMixtureKeySchema = z.enum(["Name", "Formula"]);
15
+ // NOTE: Component Schema
16
+ const ComponentSchema = z.looseObject({
17
+ name: z.string(),
18
+ formula: z.string(),
19
+ state: ComponentStateSchema,
20
+ mole_fraction: z.number().default(1),
21
+ });
22
+ // NOTE: Component Identity Schema
23
+ const ComponentIdentitySchema = z.object({
24
+ name_state: z.string(),
25
+ formula_state: z.string(),
26
+ name_formula: z.string(),
27
+ });
28
+
29
+ // SECTION: Schemas
30
+ const TemperatureSchema = z.looseObject({
31
+ value: z.number(),
32
+ unit: z.string(),
33
+ });
34
+ const PressureSchema = z.looseObject({
35
+ value: z.number(),
36
+ unit: z.string(),
37
+ });
38
+ const VolumeSchema = z.looseObject({
39
+ value: z.number(),
40
+ unit: z.string(),
41
+ });
42
+ const CustomPropSchema = z.looseObject({
43
+ value: z.union([z.number(), z.int()]),
44
+ unit: z.string(),
45
+ });
46
+
47
+ const ERRORS = {
48
+ invalid_component_key: (component_key) => `Invalid component_key '${component_key}'. Must be one of the supported keys.`,
49
+ invalid_case: (value) => `Invalid case '${value}'. Must be 'lower', 'upper', or null.`,
50
+ invalid_mixture_key: (mixture_key) => `component_key must be one of the following: Name, Formula, Name-State, Formula-State, Name-Formula, Name-Formula-State, Formula-Name-State`,
51
+ empty_components: "components list cannot be empty",
52
+ delimiter_type: "delimiter must be a string",
53
+ };
54
+
55
+ const CaseTransformSchema = z.union([
56
+ z.literal("lower"),
57
+ z.literal("upper"),
58
+ z.null(),
59
+ ]);
60
+ /**
61
+ * Creates a component identity object with multiple identifier formats.
62
+ * Combines component name, formula, and state in different arrangements.
63
+ * @param component - The component to create an identity for
64
+ * @param separator_symbol - The separator to use between components (default: "-")
65
+ * @returns ComponentIdentity object with name_state, formula_state, and name_formula identifiers
66
+ */
67
+ function create_component_id(component, separator_symbol = "-") {
68
+ const parsed_component = ComponentSchema.parse(component);
69
+ const separator = separator_symbol.trim();
70
+ const component_name = parsed_component.name.trim();
71
+ const component_formula = parsed_component.formula.trim();
72
+ const component_state = parsed_component.state.trim().toLowerCase();
73
+ return ComponentIdentitySchema.parse({
74
+ name_state: `${component_name}${separator}${component_state}`,
75
+ formula_state: `${component_formula}${separator}${component_state}`,
76
+ name_formula: `${component_name}${separator}${component_formula}`,
77
+ });
78
+ }
79
+ /**
80
+ * Generates a component identifier string based on the specified key and formatting options.
81
+ * Supports multiple identifier formats and case transformations.
82
+ * @param component - The component to generate an identifier for
83
+ * @param component_key - The key format to use (e.g., "Name-State", "Formula-State", "Name", "Formula")
84
+ * @param separator_symbol - The separator to use between components (default: "-")
85
+ * @param case_value - Case transformation to apply: 'lower', 'upper', or null for no change (default: null)
86
+ * @returns A formatted component identifier string
87
+ * @throws Error if component_key is invalid or case_value is invalid
88
+ */
89
+ function set_component_id(component, component_key, separator_symbol = "-", case_value = null) {
90
+ const parsed_component = ComponentSchema.parse(component);
91
+ const key = ComponentKeySchema.safeParse(component_key);
92
+ if (!key.success) {
93
+ throw new Error(ERRORS.invalid_component_key(String(component_key)));
94
+ }
95
+ const parsed_case = CaseTransformSchema.safeParse(case_value);
96
+ if (!parsed_case.success) {
97
+ throw new Error(ERRORS.invalid_case(String(case_value)));
98
+ }
99
+ const separator = separator_symbol.trim();
100
+ const component_idx = create_component_id(parsed_component, separator);
101
+ let component_id;
102
+ switch (key.data) {
103
+ case "Name-State":
104
+ component_id = component_idx.name_state.trim();
105
+ break;
106
+ case "Formula-State":
107
+ component_id = component_idx.formula_state.trim();
108
+ break;
109
+ case "Name-Formula":
110
+ component_id = component_idx.name_formula.trim();
111
+ break;
112
+ case "Name":
113
+ component_id = parsed_component.name.trim();
114
+ break;
115
+ case "Formula":
116
+ component_id = parsed_component.formula.trim();
117
+ break;
118
+ case "Name-Formula-State":
119
+ component_id = `${parsed_component.name.trim()}${separator}${parsed_component.formula.trim()}${separator}${parsed_component.state.trim().toLowerCase()}`;
120
+ break;
121
+ case "Formula-Name-State":
122
+ component_id = `${parsed_component.formula.trim()}${separator}${parsed_component.name.trim()}${separator}${parsed_component.state.trim().toLowerCase()}`;
123
+ break;
124
+ default:
125
+ throw new Error(ERRORS.invalid_component_key(String(component_key)));
126
+ }
127
+ if (parsed_case.data === "lower") {
128
+ return component_id.toLowerCase();
129
+ }
130
+ if (parsed_case.data === "upper") {
131
+ return component_id.toUpperCase();
132
+ }
133
+ return component_id;
134
+ }
135
+ /**
136
+ * Creates a mixture identifier for two components.
137
+ * Components are sorted alphabetically before joining with the delimiter.
138
+ * @param component_1 - The first component in the mixture
139
+ * @param component_2 - The second component in the mixture
140
+ * @param mixture_key - The key to use for identification: "Name" or "Formula" (default: "Name")
141
+ * @param delimiter - The delimiter to use between components (default: "|")
142
+ * @returns A sorted, delimited mixture identifier string
143
+ * @throws TypeError if delimiter is not a string
144
+ * @throws Error if mixture_key is invalid
145
+ */
146
+ function create_binary_mixture_id(component_1, component_2, mixture_key = "Name", delimiter = "|") {
147
+ const comp1 = ComponentSchema.parse(component_1);
148
+ const comp2 = ComponentSchema.parse(component_2);
149
+ if (typeof delimiter !== "string") {
150
+ throw new TypeError(ERRORS.delimiter_type);
151
+ }
152
+ const parsed_delimiter = delimiter.trim();
153
+ const key = BinaryMixtureKeySchema.safeParse(mixture_key);
154
+ if (!key.success) {
155
+ throw new Error("component_key must be either 'Name' or 'Formula'");
156
+ }
157
+ const comp1_id = key.data === "Name" ? comp1.name.trim() : comp1.formula.trim();
158
+ const comp2_id = key.data === "Name" ? comp2.name.trim() : comp2.formula.trim();
159
+ return [comp1_id, comp2_id].sort().join(parsed_delimiter).trim();
160
+ }
161
+ /**
162
+ * Creates a mixture identifier for multiple components.
163
+ * Combines component identifiers based on the specified key, sorts them, and joins with delimiter.
164
+ * @param components - Array of components in the mixture
165
+ * @param mixture_key - The key format to use (e.g., "Name", "Formula", "Name-State", "Formula-State")
166
+ * @param delimiter - The delimiter to use between components (default: "|")
167
+ * @param case_value - Case transformation to apply: 'lower', 'upper', or null for no change (default: null)
168
+ * @returns A sorted, delimited mixture identifier string
169
+ * @throws Error if components array is empty or mixture_key is invalid
170
+ * @throws TypeError if delimiter is not a string
171
+ */
172
+ function create_mixture_id(components, mixture_key = "Name", delimiter = "|", case_value = null) {
173
+ const parsed_components = z.array(ComponentSchema).parse(components);
174
+ if (parsed_components.length === 0) {
175
+ throw new Error(ERRORS.empty_components);
176
+ }
177
+ if (typeof delimiter !== "string") {
178
+ throw new TypeError(ERRORS.delimiter_type);
179
+ }
180
+ const parsed_delimiter = delimiter.trim();
181
+ const key = MixtureKeySchema.safeParse(mixture_key);
182
+ if (!key.success) {
183
+ throw new Error(ERRORS.invalid_mixture_key(String(mixture_key)));
184
+ }
185
+ const parsed_case = CaseTransformSchema.safeParse(case_value);
186
+ if (!parsed_case.success) {
187
+ throw new Error(ERRORS.invalid_case(String(case_value)));
188
+ }
189
+ const component_ids = parsed_components.map((comp) => {
190
+ switch (key.data) {
191
+ case "Name":
192
+ return comp.name.trim();
193
+ case "Formula":
194
+ return comp.formula.trim();
195
+ case "Name-State":
196
+ return `${comp.name.trim()}-${comp.state.trim()}`;
197
+ case "Formula-State":
198
+ return `${comp.formula.trim()}-${comp.state.trim()}`;
199
+ case "Name-Formula":
200
+ return `${comp.name.trim()}-${comp.formula.trim()}`;
201
+ case "Name-Formula-State":
202
+ return `${comp.name.trim()}-${comp.formula.trim()}-${comp.state.trim()}`;
203
+ case "Formula-Name-State":
204
+ return `${comp.formula.trim()}-${comp.name.trim()}-${comp.state.trim()}`;
205
+ default:
206
+ throw new Error(ERRORS.invalid_mixture_key(String(mixture_key)));
207
+ }
208
+ });
209
+ let mixture_id = component_ids.sort().join(parsed_delimiter).trim();
210
+ if (parsed_case.data === "lower") {
211
+ mixture_id = mixture_id.toLowerCase();
212
+ }
213
+ else if (parsed_case.data === "upper") {
214
+ mixture_id = mixture_id.toUpperCase();
215
+ }
216
+ return mixture_id;
217
+ }
218
+ /**
219
+ * Updates the state of a component while preserving all other properties.
220
+ * Mutates the original object reference to maintain Python parity.
221
+ * @param component - The component to update
222
+ * @param state - The new state to set (must be one of: 'g', 'l', 's', 'aq')
223
+ * @returns The modified component with updated state
224
+ * @throws Error if state is invalid
225
+ */
226
+ function set_component_state(component, state) {
227
+ const parsed_component = ComponentSchema.parse(component);
228
+ ComponentStateSchema.parse(state);
229
+ // Preserve Python parity by mutating the same object reference.
230
+ return Object.assign(component, parsed_component, { state });
231
+ }
232
+ /**
233
+ * Updates the state of multiple components while preserving all other properties.
234
+ * Applies the same state to all components in the array.
235
+ * @param components - Array of components to update
236
+ * @param state - The new state to set (must be one of: 'g', 'l', 's', 'aq')
237
+ * @returns Array of modified components with updated state
238
+ * @throws Error if state is invalid
239
+ */
240
+ function set_components_state(components, state) {
241
+ ComponentStateSchema.parse(state);
242
+ return components.map((component) => set_component_state(component, state));
243
+ }
244
+
245
+ export { BinaryMixtureKeySchema, ComponentIdentitySchema, ComponentKeySchema, ComponentSchema, ComponentStateSchema, CustomPropSchema, ERRORS, MixtureKeySchema, PressureSchema, TemperatureSchema, VolumeSchema, create_binary_mixture_id, create_component_id, create_mixture_id, set_component_id, set_component_state, set_components_state };
246
+ //# sourceMappingURL=index.browser.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.browser.mjs","sources":["../src/types/components.ts","../src/types/conditions.ts","../src/core/errors.ts","../src/utils/component_utils.ts"],"sourcesContent":[null,null,null,null],"names":[],"mappings":";;AAEO,MAAM,oBAAoB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,IAAI,CAAC;AAEzD,MAAM,kBAAkB,GAAG,CAAC,CAAC,IAAI,CAAC;IACvC,YAAY;IACZ,eAAe;IACf,cAAc;IACd,MAAM;IACN,SAAS;IACT,oBAAoB;IACpB,oBAAoB;AACrB,CAAA;AAEM,MAAM,gBAAgB,GAAG;AACzB,MAAM,sBAAsB,GAAG,CAAC,CAAC,IAAI,CAAC,CAAC,MAAM,EAAE,SAAS,CAAC;AAEhE;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