1.0.9
isNode Returns true or false whether the enviroment is NodeJS
boolean
:
const ig = require('iguana')
iguana = new ig();
console.log(iguana.isNode());
=> true
List class
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, "foo", "bar");
console.log(myList[0]);
=> 1
a List containing all of the elements added at the start of a list
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, "foo", "bar");
myList.push("fizz");
// "fizz" is not printed to the console because it was added to the List after it was defined.
myList.origin.forEach(function(element){ console.log(element) });
=> 1
=> 2
=> "foo"
=> "bar"
This function removes an element from a list
(any)
any
:
void.
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, "foo", "bar");
myList.delete("bar");
myList.forEach(function(element){ console.log(element) });
=> 1
=> 2
=> "foo"
Sets a limit an element can be present in a list and deletes the excess
(element)
any element present in the list
(number)
limit amount, the amount of the element that should be present in the list.
any
:
void.
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, 3, 3, 3, 4);
myList.limit(3, 1);
myList.forEach(function(element){ console.log(element) });
=> 1
=> 2
=> 3
=> 4
Returns the intersection of the two given objects, returns a List of the elements that are commmon in both Objects.
(Object)
a List or an Array to intersect with
any
:
List
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, 3, 4, 6, 8, 10);
let mySecondList = new iguana.List(5, 3, 4, 2, 12)
console.log(myList.intersection(mySecondList))
=> List [3, 4, 2]
Returns a List that contains the elements that are present in one list but not in the other.
(Object)
a List or an Array
any
:
List
const ig = require('iguana')
iguana = new ig();
const iguana = new Iguana();
let A = new iguana.List(10, 20, 30, 40, 80);
let B = new iguana.List(100, 30, 80, 40, 60);
console.log(A.difference(B))
console.log(B.difference(A))
=> List [ 10, 20 ]
=> List [ 100, 60 ]
This function returns a random element from a List.
(number)
optional parameter, if given this function will return a new List with randomized elements this parameter will define the number of elements that will be in the shuffled list.
any
:
List
:
const ig = require('iguana')
iguana = new ig();
let myList = new iguana.List(1, 2, "foo", "bar", "fizz", 3);
console.log(myList.shuffle())
=> "foo"
// If shuffle is given a number as a parameter
// This will return a new a list with 3 random elements from the original list
console.log(myList.shuffle(3))
=> List ["fizz", 1, "bar"]
A useful class for simplifying xmlhttp requests and posts. NOTE: This is not availiable in a NodeJS environment.
(string)
The server or url you will be making your requests or posts to.
let myHttp = new Iguana.HTTP("https://jsonplaceholder.typicode.com/todos/1");
console.log(myHttp.server);
=> https://jsonplaceholder.typicode.com/todos/1
This function performs an asyncronous http get request on the {server}
(object)
optional parameter to attach a header to the request
promise
:
let myHttp = new Iguana.HTTP("https://jsonplaceholder.typicode.com/todos/1");
// This function returns a promise which you can access the data using then
myHttp.request().then(function(data){
console.log(data)
}, function(error){
console.log(error);
})
=> {
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}
// Headers must be placed in a dictionary object.
myHttp.request({'User-Agent': 'Mozilla/5.0'}).then(function(data){
console.log(data)
}, function(error){
console.log(error);
})
=> {
"userId": 1,
"id": 1,
"title": "delectus aut autem",
"completed": false
}