1.0.5 • Published 4 years ago
jrn-common-lib v1.0.5
jrn-common-lib
Simple common library for generic purposes to be used often within a project
Install
npm install jrn-common-lib --save
Usage
//************* IntelliSense may not work
import {JrnCommonUtils} from 'jrn-common-lib'
let x = {name:"alex"}
console.log(JrnCommonUtils.isArray(x)); //false
console.log(JrnCommonUtils.isNotNullOrEmpty(x)); //true
let y = [];
console.log(JrnCommonUtils.isArray(y)); //true
console.log(JrnCommonUtils.isObject(y)); //false
console.log(JrnCommonUtils.isNotNullOrEmpty(y)); //false
let z = "";
console.log(JrnCommonUtils.isArray(z)); //false
console.log(JrnCommonUtils.isObject(z)); //false
console.log(JrnCommonUtils.isNotNullOrEmpty(z)); //false
let a = {};
console.log(JrnCommonUtils.isArray(a)); //false
console.log(JrnCommonUtils.isObject(a)); //true
console.log(JrnCommonUtils.isNotNullOrEmpty(a)); //false
let b = undefined;
console.log(JrnCommonUtils.isArray(b)); //false
console.log(JrnCommonUtils.isObject(b)); //false
console.log(JrnCommonUtils.isNotNullOrEmpty(b)); //false
let c = null;
console.log(JrnCommonUtils.isArray(c)); //false
console.log(JrnCommonUtils.isObject(c)); //true
console.log(JrnCommonUtils.isNotNullOrEmpty(c)); //false
let arrToFilter = [
{name:"name1" , addresses :{id1:"a",id2:"b"}}, {name:"name2" , addresses :{id1:"c",id2:"d"}}, {name:"name1" , addresses :{id1:"a",id2:"b"}}
]
//filter array by specific prop name string
let arrout = JrnCommonUtils.getFilterArrayObjectByPropString(arrToFilter , 'addresses.id2' , 'd');
console.log(arrout);
/*
[
{
"name": "name2",
"addresses": {
"id1": "c",
"id2": "d"
}
}
]
*/
let arrout2 = JrnCommonUtils.getFilterArrayObjectByPropString(arrToFilter , 'name' , 'name1');
console.log(arrout2);
/*
[
{
"name": "name1",
"addresses": {
"id1": "a",
"id2": "b"
}
},
{
"name": "name1",
"addresses": {
"id1": "a",
"id2": "b"
}
}
]
*/
//Return distinct array items
let arrout3 = JrnCommonUtils.getUniqueArrayObjectByPropString(arrToFilter , 'name');
console.log(arrout3);
/*
[
{
"name": "name1",
"addresses": {
"id1": "a",
"id2": "b"
}
},
{
"name": "name2",
"addresses": {
"id1": "c",
"id2": "d"
}
}
]
*/
let regex2:RegExp = /(?<year>\d{4})-(?<month>\d{2})-(?<day>\d{2})/;
let val = '2019-09-20'
const results = JrnCommonUtils.getNamedMatches(val,regex2,'month' , 'day');
console.log(results); output-> ['09' , '20' ]
Functions
//Return distinct items from array
getUniqueArrayObjectByPropString(arr,propName)
//Filter array objects by string prop name and value
getFilterArrayObjectByPropString(arr,propName, propVal)
//check if is an object
isObject(obj)
//check if is string
isString(obj)
//check if is boolean
isBoolean(obj)
//check if is integer
isInteger(obj)
//check if is array
isArray(obj)
//check if is null
isNull(obj)
//check if is undefined
isUndefined(obj)
//check if is an object is empty like {}
isEmptyObject(obj)
//check if an object or array or string IS NOT: null,undefined or empty
isNotNullOrEmpty(obj)
//returns regular expression groups according to the specified names
getNamedMatches(str, pattern, ...named)
Authors
- Alessandro Lippolis
License
This project is licensed under the MIT License