@lhncbc/ucum-lhc 6.0.2 → 7.1.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/README.md +61 -49
- package/browser-dist/ucum-lhc.min.js +2 -0
- package/browser-dist/ucum-lhc.min.js.map +1 -0
- package/package.json +2 -5
- package/source/ucumLhcUtils.js +90 -59
- package/source/unit.js +215 -162
- package/source/unitString.js +2 -0
- package/source-cjs/ucumLhcUtils.js +79 -46
- package/source-cjs/ucumLhcUtils.js.map +1 -1
- package/source-cjs/unit.js +204 -160
- package/source-cjs/unit.js.map +1 -1
- package/source-cjs/unitString.js +2 -0
- package/source-cjs/unitString.js.map +1 -1
- package/browser-dist/ucum-lhc.js +0 -5234
package/README.md
CHANGED
|
@@ -16,9 +16,9 @@ functions described below. You might want to try that out first.
|
|
|
16
16
|
|
|
17
17
|
## Get the code
|
|
18
18
|
|
|
19
|
-
The ucum-lhc code is written
|
|
20
|
-
|
|
21
|
-
|
|
19
|
+
The ucum-lhc code is written as ES6 modules, but the npm package (see below)
|
|
20
|
+
also contains CommonJS modules, as well as a "browser-dist" directory with files
|
|
21
|
+
ready to use in a web browser.
|
|
22
22
|
|
|
23
23
|
Currently we have code to serve multiple purposes. The core code supports
|
|
24
24
|
the validation and conversion of UCUM unit expressions as well as a function
|
|
@@ -36,43 +36,31 @@ to install the ucum-lhc npm package. (npm is
|
|
|
36
36
|
npm install @lhncbc/ucum-lhc --save
|
|
37
37
|
|
|
38
38
|
This will install the @lhncbc/ucum-lhc directory in your node_modules diretory.
|
|
39
|
-
The dist subdirectory will contain ucum-lhc.
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
### Getting the code as a bower package
|
|
43
|
-
|
|
44
|
-
You can use the [bower](https://bower.io) package manager to install the
|
|
45
|
-
ucum-lhc bower package. (If you do not have bower installed on your machine
|
|
46
|
-
you can install it using npm. See https://bower.io). Install the ucum-lhc
|
|
47
|
-
package using the bower install command
|
|
48
|
-
|
|
49
|
-
bower install ucum-lhc
|
|
50
|
-
|
|
51
|
-
This will install the ucum-lhc directory in your bower_components directory.
|
|
52
|
-
The dist subdirectory will contain ucum-lhc.js and ucum-lhc.min.js (minimized
|
|
53
|
-
version of ucum-lhc.js).
|
|
39
|
+
The browser-dist subdirectory will contain ucum-lhc.min.js for use directly in a
|
|
40
|
+
browser.
|
|
54
41
|
|
|
55
42
|
## Using the code
|
|
56
43
|
|
|
57
|
-
The ucum-lhc.min.js file
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
those capabilities for units of measure on your system.
|
|
44
|
+
The ucum-lhc.min.js file includes the source code you need for the validation,
|
|
45
|
+
conversion and commensurable units functions as well as the ucum code
|
|
46
|
+
definitions file. We assume that your main motivation for including the
|
|
47
|
+
ucum-lhc code is to have those capabilities for units of measure on your system.
|
|
62
48
|
|
|
63
49
|
### Server side
|
|
64
|
-
To access those capabilities from your server side code
|
|
50
|
+
To access those capabilities from your server side code (or from client side
|
|
51
|
+
code that goes through a build system), require the npm package
|
|
65
52
|
and create a UcumLhcUtils object that contains those functions.
|
|
66
53
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
54
|
+
const ucum = require('@lhncbc/ucum-lhc');
|
|
55
|
+
const utils = ucum.UcumLhcUtils.getInstance();
|
|
56
|
+
|
|
57
|
+
|
|
70
58
|
### Client side
|
|
71
59
|
|
|
72
60
|
To access those capabilities from your client side code, include the
|
|
73
61
|
ucum-lhc.min.js package in your html file.
|
|
74
62
|
|
|
75
|
-
<script src="path-to-installed-package/dist/ucum-lhc.min.js"></script>
|
|
63
|
+
<script src="path-to-installed-package/browser-dist/ucum-lhc.min.js"></script>
|
|
76
64
|
|
|
77
65
|
The validation, conversion and commensurable units functions are available from
|
|
78
66
|
the _ucumPkg.UcumLhcUtils_ class. In your client side javascript code access
|
|
@@ -83,12 +71,12 @@ those functions via the ucumPkg object. For example,
|
|
|
83
71
|
### Function descriptions
|
|
84
72
|
|
|
85
73
|
Below is documentation for the public functions on the UcumLhcUtils instance.
|
|
86
|
-
* [validateUnitString](#
|
|
87
|
-
* [convertUnitTo](#
|
|
88
|
-
* [checkSynonyms](#
|
|
89
|
-
* [convertToBaseUnits](#
|
|
74
|
+
* [validateUnitString](#validateunitstringustr-suggest)
|
|
75
|
+
* [convertUnitTo](#convertunittofromunitcode-fromval-tounitcode-options)
|
|
76
|
+
* [checkSynonyms](#checksynonymsthesyn)
|
|
77
|
+
* [convertToBaseUnits](#converttobaseunitsfromunit-fromval)
|
|
78
|
+
* [commensurablesList](#commensurableslistfromunit-categorylist)
|
|
90
79
|
|
|
91
|
-
<a id="validateUnitString"></a>
|
|
92
80
|
#### validateUnitString(uStr, suggest)
|
|
93
81
|
|
|
94
82
|
This method validates a unit string. It first checks to see if the string passed
|
|
@@ -104,12 +92,14 @@ return, if requested, a list of suggested units in the suggestions array
|
|
|
104
92
|
that is returned. Suggestions are based on matching the expression with
|
|
105
93
|
unit names and synonyms.
|
|
106
94
|
|
|
107
|
-
|
|
108
|
-
|
|
95
|
+
**Parameters**:
|
|
96
|
+
1) uStr: the string to be validated;
|
|
97
|
+
2) suggest: a boolean to indicate whether or not suggestions are
|
|
109
98
|
requested for a string that cannot be resolved to a valid unit;
|
|
110
99
|
true indicates suggestions are wanted; false indicates they are not,
|
|
111
100
|
and is the default if the parameter is not specified;
|
|
112
|
-
|
|
101
|
+
|
|
102
|
+
**Returns**: an object with five properties:
|
|
113
103
|
* 'status' will be 'valid' (the uStr is a valid UCUM code), 'invalid'
|
|
114
104
|
(the uStr is not a valid UCUM code, and substitutions or
|
|
115
105
|
suggestions may or may not be returned, depending on what was
|
|
@@ -160,7 +150,6 @@ of unit strings, and includes a link to the
|
|
|
160
150
|
[UCUM Specification](http://unitsofmeasure.org/ucum.html), where you can find
|
|
161
151
|
the full deal.
|
|
162
152
|
|
|
163
|
-
<a id="convertUnitTo"></a>
|
|
164
153
|
#### convertUnitTo(fromUnitCode, fromVal, toUnitCode, options)
|
|
165
154
|
|
|
166
155
|
This method converts a number of one type of unit to the equivalent number of
|
|
@@ -170,25 +159,27 @@ rounded to any particular precision or significant digits.
|
|
|
170
159
|
Disclaimer: Conversion results should be verified independently before
|
|
171
160
|
using them in actual clinical settings.
|
|
172
161
|
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
162
|
+
**Parameters**:
|
|
163
|
+
1) fromUnitCode: the unit code/expression/string of the unit to be converted;
|
|
164
|
+
2) fromVal: the number of "from" units to be converted to "to" units;
|
|
165
|
+
3) toUnitCode: the unit code/expression/string of the unit that the from
|
|
176
166
|
field is to be converted to;
|
|
177
|
-
|
|
178
|
-
|
|
167
|
+
4) options: an optional hash of options that can be passed in:
|
|
168
|
+
* 'suggestions' a boolean to indicate whether or not suggestions are wanted
|
|
179
169
|
for a string that cannot be resolved to a valid unit; true indicates
|
|
180
170
|
suggestions are wanted; false indicates they are not, and is the default
|
|
181
171
|
if the parameter is not specified;
|
|
182
|
-
|
|
172
|
+
* 'molecularWeight' the molecular weight of the substance in question when a
|
|
183
173
|
conversion is being requested from mass to moles/equivalents and vice versa. It is
|
|
184
174
|
ignored if neither unit includes a measurement in moles. In such cases
|
|
185
175
|
the mole-based unit must have a single mole unit in the numerator and the
|
|
186
176
|
mass-based unit must have a single mass unit in the numerator.
|
|
187
|
-
|
|
177
|
+
* 'charge' the absolute value of the charge of the substance in question when a conversion
|
|
188
178
|
is being requested from mass/moles to equivalents and vice versa. It is required
|
|
189
179
|
when one of the units represents a value in equivalents and the other in mass or moles.
|
|
190
180
|
It is ignored if neither unit includes an equivalent unit
|
|
191
|
-
|
|
181
|
+
|
|
182
|
+
**Returns**: a hash with six elements:
|
|
192
183
|
* 'status' the will be: 'succeeded' if the conversion was successfully
|
|
193
184
|
calculated; 'failed' if the conversion could not be made, e.g., if
|
|
194
185
|
the units are not commensurable; or 'error' if an error occurred;
|
|
@@ -262,7 +253,6 @@ If you want to know what unit types a particular unit can be converted to, the
|
|
|
262
253
|
checkSynonyms function will provide a list of commensurable units for a specified
|
|
263
254
|
unit expression.
|
|
264
255
|
|
|
265
|
-
<a id="checkSynonyms"></a>
|
|
266
256
|
#### checkSynonyms(theSyn)
|
|
267
257
|
|
|
268
258
|
This method searches for units that include a single search term (theSyn) in the
|
|
@@ -272,8 +262,10 @@ submitting the term "pound" to the _validUnitString_ method will result in a
|
|
|
272
262
|
"not found" response. Submitting it to this method will return with a list
|
|
273
263
|
of possible pound units.
|
|
274
264
|
|
|
275
|
-
|
|
276
|
-
|
|
265
|
+
**Parameters**:
|
|
266
|
+
1) theSyn: the term to search for
|
|
267
|
+
|
|
268
|
+
**Returns**: a hash with three elements:
|
|
277
269
|
* 'status' contains the status of the request, which can be 'error',
|
|
278
270
|
'failed' or 'succeeded';
|
|
279
271
|
* 'msg' contains a message for an error or if no units were found; and
|
|
@@ -302,7 +294,6 @@ of possible pound units.
|
|
|
302
294
|
/* returnObj['status'] will be 'error' and returnObj['msg'] will indicate
|
|
303
295
|
what the error was. */
|
|
304
296
|
|
|
305
|
-
<a id="convertToBaseUnits"></a>
|
|
306
297
|
#### convertToBaseUnits(fromUnit, fromVal)
|
|
307
298
|
|
|
308
299
|
Converts the given unit string into its base units, their exponents, and
|
|
@@ -332,6 +323,27 @@ a magnitude, and returns that data.
|
|
|
332
323
|
and usefulness for the input values that produced it).
|
|
333
324
|
* unitToExp: a map of base units in fromUnit to their exponent
|
|
334
325
|
|
|
326
|
+
#### commensurablesList(fromUnit[, categoryList])
|
|
327
|
+
|
|
328
|
+
Retrieves a list of units commensurable, i.e., that can be converted from and
|
|
329
|
+
to, a specified unit. Returns an error if the "from" unit cannot be found.
|
|
330
|
+
If necessary, you can filter the list of units by specifying a list of unit
|
|
331
|
+
categories that should be in the resulting list.
|
|
332
|
+
|
|
333
|
+
**Parameters**:
|
|
334
|
+
1) fromUnit: the name/unit string
|
|
335
|
+
2) categoryList: optional parameter - the list of unit categories; possible
|
|
336
|
+
list values: 'Clinical', 'Nonclinical', 'Obsolete', 'Constant'
|
|
337
|
+
|
|
338
|
+
**Returns**: an array containing two elements:
|
|
339
|
+
* 0: an array of commensurable units if any were found, each of which is an
|
|
340
|
+
object with the properties:
|
|
341
|
+
* name_: unit name;
|
|
342
|
+
* csCode_: unit code;
|
|
343
|
+
* other properties are currently undocumented and their existence should not
|
|
344
|
+
be relied upon.
|
|
345
|
+
* 1: an error message if the "from" unit is not found.
|
|
346
|
+
|
|
335
347
|
|
|
336
348
|
### Download the GitHub repository
|
|
337
349
|
|