Blue Button Utility
Common utility methods for Amida-Tech repositories
![NPM](https://nodei.co/npm/@hishprorg/perspiciatis-ratione-unde.png)
![Coverage Status](https://coveralls.io/repos/hishprorg/perspiciatis-ratione-unde/badge.png)
This library provides common Javascript utilities that are used in other Amida-Tech libraries.
Quick up and running guide
Prerequisites
- Node.js (v14.19+) and NPM
- Grunt.js
# Install dependencies
npm i
# Install grunt
npm i -g grunt
# Test
grunt
Utilities
You can install using npm and require
to use in node.js
var bbu = require('@hishprorg/perspiciatis-ratione-unde');
var ob = bbu.object;
var obs = bbu.object;
var arrs = bbu.arrayset;
var dtt = bbu.datetime;
The following methods are provided
object
Library
Provides utility methods for objects.
exists(obj)
Checks if obj
is not undefined
or null
var r0 = ob.exists(null);
var r1 = ob.exists(undefined);
var r2 = ob.exists('anything else');
console.log(r0);
console.log(r1);
console.log(r2);
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
}
};
obs.compact(obj);
console.log(obj);
arrayset
Library
Provides utility methods that modify an array.
append(arr, arrToAppend)
Appends arrToAppend
elements to arr
var arr = ['a', 'b'];
arrs.append(arr, ['c', 'd']);
console.log(arr);
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.dateToModel('2014');
var r1 = dtt.dateToModel('2014-02');
var r2 = dtt.dateToModel('2014-02-07');
var r3 = dtt.dateToModel('2014-02-07T12:45:04.000Z');
console.log(r0);
console.log(r1);
console.log(r2);
console.log(r3);
datetime.dateTimeToModel(dt)
Converts ISO datetime d
to blue-button-model datetime
var r0 = dtt.dateTimeToModel('2014');
var r1 = dtt.dateTimeToModel('2014-02');
var r2 = dtt.dateTimeToModel('2014-02-07');
var r3 = dtt.dateTimeToModel('2014-02-07T12:45:04.000Z');
console.log(r0);
console.log(r1);
console.log(r2);
console.log(r3);
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.modelToDate({
date: '2014-01-01T00:00:00.000Z',
precision: 'year'
});
var r1 = dtt.modelToDate({
date: '2014-02-01T00:00:00.000Z',
precision: 'month'
});
var r2 = dtt.modelToDate({
date: '2014-02-07T00:00:00.000Z',
precision: 'day'
});
var r3 = dtt.modelToDate({
date: '2014-02-07T12:45:04.000Z',
precision: 'second'
});
console.log(r0);
console.log(r1);
console.log(r2);
console.log(r3);
datetime.modelToDateTime(dt)
Converts blue-button-model datetime dt
to ISO datetime
var r0 = dtt.modelToDateTime({
date: '2014-01-01T00:00:00.000Z',
precision: 'year'
});
var r1 = dtt.modelToDateTime({
date: '2014-02-01T00:00:00.000Z',
precision: 'month'
});
var r2 = dtt.modelToDateTime({
date: '2014-02-07T00:00:00.000Z',
precision: 'day'
});
var r3 = dtt.modelToDateTime({
date: '2014-02-07T12:45:04.000Z',
precision: 'second'
});
var r4 = dtt.modelToDateTime({
date: '2014-02-07T12:45:04.010Z',
precision: 'second'
});
console.log(r0);
console.log(r1);
console.log(r2);
console.log(r3);
console.log(r4);
License
Licensed under Apache 2.0.