1.1.0 • Published 7 years ago

general-js v1.1.0

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

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;
1.1.0

7 years ago

1.0.14

8 years ago

1.0.13

8 years ago

1.0.12

8 years ago

1.0.11

8 years ago

1.0.10

8 years ago

1.0.9

8 years ago

1.0.8

8 years ago

1.0.7

8 years ago

1.0.6

8 years ago

1.0.5

8 years ago

1.0.4

8 years ago

1.0.3

8 years ago

1.0.2

8 years ago

1.0.1

8 years ago

1.0.0

8 years ago