blue-button-util
Common utility methods for Amida-Tech repositories
This library provides common Javascript utilities that are used in other Amida-Tech libraries.
Utilities
You can install using npm and require
to use in node.js
var bbu = ; var ob = bbuobject; // object libraryvar obs = bbuobject; // objectset libraryvar arrs = bbuarrayset; // arrayset libraryvar dtt = bbudatetime; // datetime library
The following methods are provided
object.exists
objectset.compact
arrayset.append
datetime.dateToModel
datetime.dateTimeToModel
datetime.modelToDate
datetime.modelToDateTime
object
Library
Provides utility methods for objects.
####exists(obj)Checks if obj
is not undefined
or null
var r0 = ob;var r1 = ob;var r2 = ob; console; // falseconsole; // falseconsole; // true
objectset
Library
Provides utility methods that modify an object.
####objectset.compact(obj)Recursively removes all null
and undefined
values from obj
. No special handling is done for resulting empty objects or arrays
var obj = a: 1 b: null c: d: undefined e: 4 f: g: null ; obscompactobj;console; // {a: 1, c:{e:4}, f:{}}
arrayset
Library
Provides utility methods that modify an array.
#### append(arr, arrToAppend)Appends arrToAppend
elements to arr
var arr = 'a' 'b'; arrs;console; // ['a', 'b', 'c', 'd'];
datetime
Library
Provides conversion methods to/from blue-button-model datetimes from/to ISO datetimes.
#### datetime.dateToModel(d)Converts ISO date d
to blue-button-model datetime
var r0 = dtt;var r1 = dtt;var r2 = dtt;var r3 = dtt; console; // {date: '2014-01-01T00:00:00.000Z', precision: 'year'}console; // {date: '2014-02-01T00:00:00.000Z', precision: 'month'}console; // {date: '2014-02-07T00:00:00.000Z', precision: 'day'}console; // {date: '2014-02-07T00:00:00.000Z', precision: 'day'}
Converts ISO datetime d
to blue-button-model datetime
var r0 = dtt;var r1 = dtt;var r2 = dtt;var r3 = dtt; console; // {date: '2014-01-01T00:00:00.000Z', precision: 'year'}console; // {date: '2014-02-01T00:00:00.000Z', precision: 'month'}console; // {date: '2014-02-07T00:00:00.000Z', precision: 'day'}console; // {date: '2014-02-07T12:45:04.000Z', precision: 'second'}
Millisecond piece is ignored even when it is not zero.
#### datetime.modelToDate(dt)Converts blue-button-model datetime dt
to ISO date
var r0 = dtt;var r1 = dtt;var r2 = dtt;var r3 = dtt; console; // '2014'console; // '2014-02'console; // '2014-02-07'console; // '2014-02-07'
Converts blue-button-model datetime dt
to ISO datetime
var r0 = dtt;var r1 = dtt;var r2 = dtt;var r3 = dtt;var r4 = dtt; console; // '2014'console; // '2014-02'console; // '2014-02-07'console; // '2014-02-07T12:45:04.000Z'console; // '2014-02-07T12:45:04.010Z'
License
Licensed under Apache 2.0.