Skip to content

martinjay180/GeneralJS

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

50 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

GeneralJS Build Status

A general purpose JavaScript library.

Strings

format

"This is pretty {0}".format("cool");

log

var user = "John Doe";
user.log();
user.log("Current User");
=> John Doe
=> Current User: John Doe

toInt(fallback)

"123".toInt();
"123a".toInt(3);

reverse

"test".reverse();

Output:

tset

Boolean

flip

var test = true;
test.flip();

Helpful when making a toggle function:

<button ng-click="displayStuff.flip()"></button>

log

var active = true;
active.log();
active.log("Active");
=> true
=> Active : true

Array

last

The last function will return the last item in the array.

var arr = [ 'one', 'two', 'three' ];
arr.last();
=> 'three'

log

var arr = [ 'one', 'two', 'three' ];
arr.log();
arr.log("Message");
=> [ 'one', 'two', 'three' ]
=> Message: [ 'one', 'two', 'three' ]

asArray

This function will return the passed object as an array. Useful when objects or arrays can be supplied.

var a = 1;
var b = [1,2,3];
Array.asArray(a);
Array.asArray(b);
=> [1];
=> [1,2,3];

Object

getValue

This function will test if an object has a property and return it. It can also take in compound properties (i.e. find property recursively). Will return fallBack value if no matches are made and false if no matches and no fallBack.

var obj = {'a': { 'b' : { 123 } }, 'b' : 2, 'c' : 3};
obj.getValue("c");
=> 3;    
obj.getValue("d",4);
=> 4;
obj.getValue("a.b");
=> 123;

About

A general purpose JavaScript library.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published