checks if the value in array is distinct or not. if left empty will validate the entire array for distinct values.
isDistinct(any[],string?)
isDistinct(["foo","bar"]) //true isDistinct(["foo","bar","foo"]) //false isDistinct(["foo","bar","foo"],"bar") //true
removes dublicate values from array.
removeDuplicate(Array<string>)
removeDuplicate([1,2,3,2,3,1]) // [1,2,3]
gets specific values from Array of objects.
pluck(Array<Object>,String)
let data =[ { name:"foo" , id:1},{name:"bar" , id:2 } ]
console.log(pluck(data,"name")) // ["foo","bar"]
converts array of objects into an object based on key provided.
sort(Array<Object>,String)
let data=[{ name:"foo" , id:1 },{ name:"bar" , id:2 }]
sort(data,"name") // { foo:{ id:1 , name:"foo" }, bar:{ id:2 , name:"bar" } }
merges child object with the parent object.
mergeUp(Object,String)
let data ={ test:22 , foo:"aas" , val:{ foo:"aa" , bar:"bb" } }
mergeUp(data,"val") // { test: 22, foo: 'aa', bar: 'bb' }
mergeUp(data,"val",false) // { test: 22, foo: 'aas', bar: 'bb' }
return an object without specified properties.
exceptObj(Object ,Array<strings> )
let data = { val1 : "22", val2 : "44" }
console,log( exceptObj( data , [ "val1" ] ) ) // { val2 : "44" }
return anything as number useful when you dont know the return type and you want out put to be number.
returnAsInt(any)
returnAsInt("44") //44 returnAsInt(44) //44 returnAsInt({}) //1
Get params from url provided and if left empty will get params from if in dom. used (query-string under the hood)
getParams(String)
let data='example.com?foo=bar'
getParams(data) // { foo : "bar" }
This package supports TreeShanking for esm as well as seprate files for each function so you can use it in backend without bloating your application as well as chose between cjs and esm.
e.g import { exceptObj, returnAsInt } from "js-easify"
or const { returnAsInt } = require( "js-easify" )
e.g import returnAsInt from "js-easify/esm/Int/returnAsInt.js"
or
const returnAsInt =require("js-easify/cjs/Int/returnAsInt.js")