simpu

1.1.3 • Public • Published

SIMPU

Change the way you code!

I add more than 7 functions every week. You can send me your idea at livrang.contact@gmail.com and if i like it then i will add it and write you name in this module.

It is a module which have mostly used functions and it contains all of the functions you actually need to build anything. In future we will ad more functions.

About

Hi! I am Mridul and I am 15 years old .I have been coding from past 4 years in js. I mastered javascript and have some of the amazing modules which will help you in coding.

Download

You can download it using this command using your cli

npm i simpu

Documentation

var  im  =  require("simpu");

im([1,2,3,4]).chunk(2); // [12,34]

basic

The basic is simple you only have to write it like that:

im( element ).function(parameter)

Properties

Type

im( ele ).type

The best thing is that it return as string, number, object, array, null, NaN, undefined

Example :

im(null).type  // "null"

im(NaN).type  // "NaN"

im(undefined).type  // "undefined"

im(12).type  // "number"

im("Mridul").type  // "string"

im([1,2,3]).type  // "array"

im({name : "Mridul", country : "India"}).type  // "object"

elem

It returns your elem but completely new. It means that if you change the value of your variable in elem then it will not change the previous variable's value.

im( ele ).elem;

For example:

var x = [1,2,3,4];
var y = x;
y[2] = 10;
console.log(x) // 1,2,10,4
//You can see it changes the value of x too
var x = [1,2,3,4];
var y = im(x).elem;
y[2] = 10;
console.log(x) //[1,2,3,4]

elesEqual

Checks whether all the elements of array are equal or not.

im( array ).elesEqual

For example :

im([2,2,2,2]).elesEqual // true
im([1,2,3,4]).elesEqual // false

flatten

It flattens the array completely.

im( array ).flatten

For Example :

im([1,2,3,[4,5,6,[7,8]]]).flatten; // [1,2,3,4,5,6,7,8]

allDifferent

It checks that whether all elements in an array are different

im( array ).allDifferent

For Example :

im([1,2,3]).allDifferent; // true
im([1,2,2]).allDifferent; // flase

elesSum

It will the sum of all eles in an array

im( array ).elesSum

For Example :

im([1,2,3]).elesSum; // 6
im([4,5,6]).elesSum; // 15

getStart

It will return first element from the array

im( array ).getStart

For Example :

im([1,2,3]).getStart; // 1
im([4,5,6]).getStart; // 4

getLast

It will return last element from the array

im( array ).getLast

For Example :

im([1,2,3]).getLast; // 3
im([4,5,6]).getLast; // 6

Functions

rand

im( range ).rand( length )

range

It is in the form of array. That array can be 1 dimensional or 2 dimensional

the best part is that you can even use alphabets as well as numbers .Firstly let us start with 1d array so let's see an example :

im([1,10]).rand(); //any random number between 0 - 10

im(["a","z"]).rand(); //any random alphabet from a to z

im(["A","Z"]).rand(); //any random alphabet between A to Z

You can use length also

im([1,10]).rand(2) //any random between 1 - 10 with length 2 ex: 52

im([1,10]).rand(3) //any random between 1 - 10 with length 3 ex: 934

im([1,10]).rand(4) //any random between 1 - 10 with length 4 ex: 2398

2d array for rand

im([[1,10],[90,100]]).rand(); // any random no. between 1-10 or 90-100

im([["a","z"],["A","Z"]]).rand(); // any random alphabet a - z or A - Z

im([[0,10],["a","z"]]).rand(); // any random item between 0-10 or a-z

diffRand

return random value which does not exixts in the array provided

im( arr ).diffRand( range , length )

The range and length is same as in rand.

Example :

im([1,2,5,3]).diffRand([1,10]) //random number between 1 - 10 except 1,2,5,3

randItem

return random item from an array or random item form an object.

im( ele ).randItem( between );

ele

ele can be an array or can be any object

Example:

im(["a","b","c","d"]).randItem(1,3); // returns random element between 1, 3

im(1,2,3,4).randItem(); //return random element

im({name : "Mridul", country : "India"}).randItem() // return random property but as an array

curry

It will convert any function into a curry.

For example :

add( a , b , c );

will be converted to :

add( a )( b )( c )

im( function ).curry();

function

function can be any function

Example:

function  sum(a,b,c){
return  a  +  b  +  c;
}

sum(2,3,4); // 9
var  cur  =  im(sum).curry();

cur(2)(3)(4); //9

equalTo

Check whether given items are equal or not.

im( ele1 ).equalTo( ele2 )

Best Part

The best part is that it not only checks numbers or strings but it also checks for arrays and objects.

! Important

It not only matches the elements of object but it also checks order so if elements are in different order then it will return false. For Examle :

im({name : "mridul"}).equalTo({name : "mridul"}); // true
im([1,2,3]).equalTo([1,2,3]) // true

deepLoop

Loop through an array but by ignoring all the dimensions.I mean it will flatten it and then loop throung it.

im( multi dimensional array ).deepLoop( func )

Best Part

The best part is that you don't have to worry about dimensions.

For Examle :

im([1,2,[3,4,5,[6,7,8,[9,10,11]]]]).deepLoop((val,ind,array)=>{
    console.log(val ** 2);
})

getNth

It will return the Nth element form the array.

im( array ).getNth( n )

For Example :

im([9,2,4,10,3]).getNth(3)

putNth

It will put the value in nth position in an array.

im( array ).putNth( value , n )

For example :

var arr = [1,2,3,4];
im(arr).putNth(10,2)
console.log(arr); // [1,2,10,3,4]

putEnd

It will put the value in end of array.

im( array ).putEnd( value )

For Example :

var arr = [1,2,3,4];
im(arr).putEnd(5);
console.log(arr) // [1,2,3,4,5]

putStart

It will put the value in start of array.

im( array ).putStart( value );

For Example :

var arr = [2,3,4,5];
im(arr).putStart(1);
console.log(arr); //[1,2,3,4,5]

rmStart

It will remove first element from the array.

im( array ).rmStart()

var arr = [1,2,3,4,5];
im(arr).rmStart();

rmEnd

It will remove last element from the array.

im( array ).rmENd()

var arr = [1,2,3,4,5];
im(arr).rmEnd();

rmNTh

It will remove Nth element from the array.

im( array ).rmNth( n )

var arr = [1,2,3,4,5];
im(arr).rmNth(2);

shuffle

It will shuffle the elements of an array.

im( array ).shuffle();

var arr = [1,2,3,4,5];
console.log(im(arr).shuffle());

times

It will run a function number of times you specified.

im( function ).times( times );

function log(){
    console.log(`Hello`);
}
im(log).times(4);
// Hello, Hello, Hello, Hello

objToArr

It will convert object to array.

im( object ).objToArr()

For Example :

var obj = {name : "mridul"};
console.log(im(obj).objToArr());

arrToObj

It will convert array to object.

im( object ).arrToObj()

For Example :

var arr = [["name","mridul"]];
console.log(im(arr).arrToObj());

debounce

Debouncing is a programming practice used to ensure that time-consuming tasks do not fire so often, that it stalls the performance of the web page. In other words, it limits the rate at which a function gets invoked

im( function ).deboucne( timeout )

chunk

Chunking means dividing an array into small chunks/parts.

im( arr ).chunk( size )

var arr = [1,2,3,4,5]
im(arr).chunk(2) // [[1,2],[3,4],[5]]

del

It will delete elements of second array from first array.

im( arr 1 ).del( array 2 )

var arr = [1,2,3,4,5];
var arr2 = [2,4,5];
im(arr).del(arr2) // [1,3]

wait

It will wait for sometime and then run that function.

im( func ).wait( time )

function add(a, b){
    return a + b;
}
im(add).wait(5000) // run function after 5 seconds

containShuffled

It will check that whether an array contains shuffled array of array provided.

im( array ).containShuffled( value )

var arr = [[1,2,3],[2,3,4]];
im(arr).containShuffled([2,3,1]) // true because arr contains [1,2,3] which is shuffled form of [2,3,1]

containSame

It will check that whether an array contains same element as you given or not.

im( array ).containShuffled( value )

var arr = [1,2,3,4];
im(arr).containSame(2) //true

deleteSame

It will delete all occurences of same element.

im( array ).deleteShuffled()

var arr = [1,2,2,3,4,1,1,2,2];
im(arr).deleteSame() //[1,2,3,4]

deleteShuffled

It will delete all elements which are in shuffled form. !Important it will delete the main value also.

im( array ).deleteShuffled();

var arr = [[1,2,3],[4,5,6],[3,1,2]];
im(arr).deleteShuffled(); // [[4,5,6]
//it delete all shuffled elements

Tips

#Tip 1

firstly assign a function variable to element and then apply functions.

For example :

var arr = [1,2,3,4];
var imarr = im(arr);

imarr.putEnd(5);

Contact

I add more than 4 functions every week. You can send me your idea at livrang.contact@gmail.com and if i like it then i will add it and write you name in this module.

Package Sidebar

Install

npm i simpu

Weekly Downloads

0

Version

1.1.3

License

MIT

Unpacked Size

62 kB

Total Files

9

Last publish

Collaborators

  • lmodules