@lhncbc/ucum-lhc 5.0.0 → 5.0.2

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 CHANGED
@@ -27,7 +27,7 @@ concerned with importing and exporting the UCUM data, and in supporting the
27
27
  demo page (noted above). If you are looking to include the ucum-lhc core code
28
28
  in your application, download the code as an [npm](https://www.npmjs.com) package.
29
29
 
30
- #### Getting the code as an npm package
30
+ ### Getting the code as an npm package
31
31
 
32
32
  You can use the [npm](https://www.npmjs.com) package manager
33
33
  to install the ucum-lhc npm package. (npm is
@@ -39,7 +39,7 @@ This will install the @lhncbc/ucum-lhc directory in your node_modules diretory.
39
39
  The dist subdirectory will contain ucum-lhc.js and ucum-lhc.min.js (minimized
40
40
  version of ucum-lhc.js).
41
41
 
42
- #### Getting the code as a bower package
42
+ ### Getting the code as a bower package
43
43
 
44
44
  You can use the [bower](https://bower.io) package manager to install the
45
45
  ucum-lhc bower package. (If you do not have bower installed on your machine
@@ -52,7 +52,7 @@ This will install the ucum-lhc directory in your bower_components directory.
52
52
  The dist subdirectory will contain ucum-lhc.js and ucum-lhc.min.js (minimized
53
53
  version of ucum-lhc.js).
54
54
 
55
- ### Using the code
55
+ ## Using the code
56
56
 
57
57
  The ucum-lhc.min.js file (which is the minimized version of the ucum-lhc.js
58
58
  file) includes the source code you need for the validation, conversion and
@@ -60,14 +60,14 @@ commensurable units functions as well as the ucum code definitions file. We
60
60
  assume that your main motivation for including the ucum-lhc code is to have
61
61
  those capabilities for units of measure on your system.
62
62
 
63
- #### Server side
63
+ ### Server side
64
64
  To access those capabilities from your server side code, require the npm package
65
65
  and create a UcumLhcUtils object that contains those functions.
66
66
 
67
67
  var ucum = require('@lhncbc/ucum-lhc');
68
68
  var utils = ucum.UcumLhcUtils.getInstance();
69
69
 
70
- #### Client side
70
+ ### Client side
71
71
 
72
72
  To access those capabilities from your client side code, include the
73
73
  ucum-lhc.min.js package in your html file.
@@ -80,11 +80,16 @@ those functions via the ucumPkg object. For example,
80
80
 
81
81
  var parseResp = ucumPkg.UcumLhcUtils.getInstance().validateUnitString(uStr, true);
82
82
 
83
- #### Function descriptions
83
+ ### Function descriptions
84
84
 
85
- Here are the function descriptions:
85
+ Below is documentation for the public functions on the UcumLhcUtils instance.
86
+ * [validateUnitString](#validateUnitString)
87
+ * [convertUnitTo](#convertUnitTo)
88
+ * [checkSynonyms](#checkSynonyms)
89
+ * [convertToBaseUnits](#convertToBaseUnits)
86
90
 
87
- **validateUnitString(uStr, suggest)**
91
+ <a id="validateUnitString"></a>
92
+ #### validateUnitString(uStr, suggest)
88
93
 
89
94
  This method validates a unit string. It first checks to see if the string passed
90
95
  in is a unit code that is found in the unit codes table. If it is not found it
@@ -155,7 +160,8 @@ of unit strings, and includes a link to the
155
160
  [UCUM Specification](http://unitsofmeasure.org/ucum.html), where you can find
156
161
  the full deal.
157
162
 
158
- **convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight)**
163
+ <a id="convertUnitTo"></a>
164
+ #### convertUnitTo(fromUnitCode, fromVal, toUnitCode, suggest, molecularWeight)
159
165
 
160
166
  This method converts a number of one type of unit to the equivalent number of
161
167
  another type of unit. Note that the number returned is not trimmed or
@@ -251,7 +257,8 @@ If you want to know what unit types a particular unit can be converted to, the
251
257
  checkSynonyms function will provide a list of commensurable units for a specified
252
258
  unit expression.
253
259
 
254
- **checkSynonyms(theSyn)**
260
+ <a id="checkSynonyms"></a>
261
+ #### checkSynonyms(theSyn)
255
262
 
256
263
  This method searches for units that include a single search term (theSyn) in the
257
264
  unit's synonyms data and/or the unit name. It returns all units found with a
@@ -289,14 +296,45 @@ of possible pound units.
289
296
  else
290
297
  /* returnObj['status'] will be 'error' and returnObj['msg'] will indicate
291
298
  what the error was. */
292
-
299
+
300
+ <a id="convertToBaseUnits"></a>
301
+ #### convertToBaseUnits(fromUnit, fromVal)
302
+
303
+ Converts the given unit string into its base units, their exponents, and
304
+ a magnitude, and returns that data.
305
+
306
+ **Parameters**:
307
+ 1) fromUnit: the unit string to be converted to base units information
308
+ 2) fromVal: the number of "from" units to be converted
309
+
310
+ **Returns**: an object with the properties:
311
+ * status: indicates whether the result succeeded. The value will be one of:
312
+ * 'succeeded': the conversion was successfully calculated (which can be
313
+ true even if it was already in base units);
314
+ * 'invalid': fromUnit is not a valid UCUM code;
315
+ * 'failed': the conversion could not be made (e.g., if it is an "arbitrary" unit);
316
+ * 'error': if an error occurred (an input or programming error)
317
+ * msg: an array of messages (possibly empty), if the string is invalid or
318
+ an error occurred, indicating the problem, or a suggestion of a
319
+ substitution such as the substitution of 'G' for 'Gauss', or
320
+ an empty array if no messages were generated. There can also be a
321
+ message that is just informational or warning.
322
+ * magnitude: the new value when fromVal units of fromUnits is expressed in the base units.
323
+ * fromUnitIsSpecial: whether the input unit fromUnit is a "special unit"
324
+ as defined in UCUM. This means there is some function applied to convert
325
+ between fromUnit and the base units, so the returned magnitude is likely not
326
+ useful as a scale factor for other conversions (i.e., it only has validity
327
+ and usefulness for the input values that produced it).
328
+ * unitToExp: a map of base units in fromUnit to their exponent
329
+
293
330
 
294
331
  ### Download the GitHub repository
295
332
 
296
333
  The code available here on GitHub includes functions and scripts to perform
297
334
  additional functions, mainly to convert ucum data from various formats to
298
335
  the data used by our code as well as the code that supports the demo page.
299
- Click on the green "Clone or download" button above to download the repository.
336
+ Click on the green "Code" button above to download the repository.
337
+
300
338
 
301
339
  ### Building the code and data
302
340
  If you wish to modify the code, the build process is simply: