Skip to content

Documentation

portapipe edited this page Mar 14, 2016 · 6 revisions

Basics

//The main class is WAYS so every tool you want to use MUST be prefixed with:
WAYS.toolName()

//A 'objForDemo' var will be used for every example
var objForDemo = {1:"Hello",2:"World"};



Loop

WAYS.loop(obj,callback(key,value));

// example
WAYS.loop({1:"Hello",2:"World"},function(key,value){
    console.log("Key is "+key+" and value "+value);
}

localStorage - Persistent Data

These tools will save PERMANENTLY the data you're passing into the browser memory. It acts like a database but it's limited in MB. It use the "localStorage" introduced with HTML5. You can save/load/clear any kind of data there, from object to array and any "simple" data like booleans, strings, numbers...

save

Save any kind of data (object, array, numbers, boolean... really any data). Saving data on the same key will overwrite the existing one.

WAYS.save(key,anyDataType);

// example
WAYS.save("My Cool Data",objForDemo);

load

Return the data you've stored into the key you're going to pass. The data type will be the same as the original one! If the data with the key you're passing is not set, undefined is returned.

WAYS.load(key);

// example
WAYS.load("My Cool Data");

clear / remove

Clear (remove) the data saved with that key. 'undefined' will be returned if you load the data with that key

WAYS.clear(key);
WAYS.remove(key); //is the same of clear, just an alias

// example
WAYS.clear("My Cool Data");

Date

timeToDate

Return an object with all the data you can hope from a timestamp you'll pass:

  • timestamp
  • milliseconds
  • seconds
  • minutes
  • day
  • dayString //you can set this in your language with setDayString
  • dayOfWeek
  • month
  • monthString //you can set this in your language with setMonthString
  • year
WAYS.timeToDate(timestamp);

// example
var myDate = WAYS.timeToDate(1457970651923);
console.log(myDate.day); //will print out '14' that is the day of the timestamp passed

dateToTime

Return the same of timeToDate but instead of passing a timestamp you have to pass a regular date. SO it return an object containing all the data regarding date.

WAYS.dateToTime(regularDate);

// example
WAYS.dateToTime('Aug 9, 1995'); //Return an object containing all the date data

date

Return the same of timeToDate but instead of passing a timestamp you don't have to pass nothing. So it return an object containing all the data regarding the actual date. NOW!

WAYS.date();

// example
console.log( WAYS.date().year ); //Return 2016 because today is the year 2016

dayString

Return all the day name (Monday, Tuesday...). You can translate that with setDayString (explained just below)

WAYS.dayString;

// example
var days = WAYS.dayString;
console.log(days[6]); //return 'Saturday'

setDayString

Set the name of the days. This will change the names on the timeToDate, dateToTime and date too!

WAYS.setDayString(obj);

// example
//Italian Translation
var days = { 1:"Lunedì", 2:"Martedì", 3:"Mercoledì", 4:"Giovedì", 5:"Venerdì", 6:"Sabato", 7:"Domenica" };
WAYS.setDayString(days);
console.log( WAYS.date().dayString ); //will print out the actual day (today is monday (n.1) so 'Lunedì')

monthString

Return all the month name (January, February...). You can translate that with setMonthString (explained just below)

WAYS.monthString;

// example
var month = WAYS.monthString;
console.log(month[6]); //return 'June'

setMonthString

Set the name of the days. This will change the names on the timeToDate, dateToTime and date too!

WAYS.setMonthString(obj);

// example
// Italian Translation
var monthList = { 1:"Gennaio", 2:"Febbraio", 3:"Marzo", 4:"Aprile", 5:"Maggio", 6:"Giugno", 7:"Luglio", 8:"Agosto", 9:"Settembre", 10:"Ottobre", 11:"Novembre", 12:"Dicembre" };
WAYS.setMonthString(monthList);
console.log( WAYS.date().monthString ); //will print the actual month translated (now is April (n.4) so "Aprile")