GithubHelp home page GithubHelp logo

helpers's Introduction

NodeJs Helper

basic set of helpers to make coding a bit easier

Installation

npm i js-easify

Usage

Array

isDistinct

checks if the value in array is distinct or not. if left empty will validate the entire array for distinct values. isDistinct(any[],string?)

e.g

isDistinct(["foo","bar"]) //true isDistinct(["foo","bar","foo"]) //false isDistinct(["foo","bar","foo"],"bar") //true

removeDuplicate

removes dublicate values from array. removeDuplicate(Array<string>)

e.g

removeDuplicate([1,2,3,2,3,1]) // [1,2,3]

pluck

gets specific values from Array of objects. pluck(Array<Object>,String)

e.g

let data =[ { name:"foo" , id:1},{name:"bar" , id:2 } ] console.log(pluck(data,"name")) // ["foo","bar"]

Object

sort

converts array of objects into an object based on key provided. sort(Array<Object>,String)

e.g

let data=[{ name:"foo" , id:1 },{ name:"bar" , id:2 }]

sort(data,"name") // { foo:{ id:1 , name:"foo" }, bar:{ id:2 , name:"bar" } }

mergeUp

merges child object with the parent object. mergeUp(Object,String)

e.g

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' }

exceptObj

return an object without specified properties. exceptObj(Object ,Array<strings> )

e.g

let data = { val1 : "22", val2 : "44" }

console,log( exceptObj( data , [ "val1" ] ) ) // { val2 : "44" }

Int

returnAsInt

return anything as number useful when you dont know the return type and you want out put to be number. returnAsInt(any)

e.g

returnAsInt("44") //44 returnAsInt(44) //44 returnAsInt({}) //1

Url

getParams

Get params from url provided and if left empty will get params from if in dom. used (query-string under the hood) getParams(String)

e.g

let data='example.com?foo=bar'

getParams(data) // { foo : "bar" }

ESM and CJS support

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" )

//Or

e.g import returnAsInt from "js-easify/esm/Int/returnAsInt.js" or const returnAsInt =require("js-easify/cjs/Int/returnAsInt.js")

helpers's People

Contributors

adeelasd avatar dependabot[bot] avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.