2.1.0 • Published 3 years ago
@romchik38/dtbase v2.1.0
Dtbase gets an array of objects, do something with them and return result.
Call:
- dtbase({ methodName, fn, source, options })
Arguments
- methodName - name of the method (string).
- fn - a function that will compare an object with a condition
- source - array of objects(array)
- options - some options for methods(object)
Methods:
- select - compare with a condition and return selection of items
Result
- All methods return an array of objects. object, object2 ...
Fn
- async function
- arguments:
- item - object
- return:
- object -if it meets a conditions
- null - if not.
Source
- an array of objects
Options
- some options for methods
Expamle
const dtbase = require('@romchik38/dtbase');
//@romchik38/dtbase@2.0.0
const age = async item => {
try {
const age = parseInt(item['age'], 10);
if (typeof age === 'number' && age > 21) return item;
else return null;
} catch (err) {
throw new Error(err);
}
};
const arr = [
{"name": "ser", "lastname": "rom", "age": "20"},
{"name": "dim", "lastname": "fan", "age": "25"},
{"name": "zin", "lastname": "opr", "age": "18"}
];
const result = dtbase({
methodName: 'select',
fn: age,
source: arr,
options: {},
});
result.then(data => {
console.log({ data });
}).catch(err => {
console.log('error from catch', err);
});