Methods

SPArrayChunk

(source code)
SPArrayChunk(b, e)
Permits to cut an array into smaller blocks

Parameters:

Array
b
The array to split
Number
e
The size of each block

Returns:

Array
An array that contains several arrays with the required size

SPArrayForEach

(source code)
SPArrayForEach()
Array.forEach polyfill for IE8 (source : https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/forEach)

SPArrayIndexOf

(source code)
SPArrayIndexOf()
Array.indexOf polyfill for IE8

SPExtend

(source code)
SPExtend(deep, objectDestination, objectSource)
It will clone an object (see )

Parameters:

Boolean
deep Optional, Default: false
If we want a deep clone
Object
objectDestination
The object that will be extended
Object
objectSource
The object the copy

SPIsArray

(source code)
SPIsArray()
Return true when the arg is an array

decode_b64

(source code)
decode_b64(toDecode)
Permits to decode a Base 64 string

Parameters:

String
toDecode
It's the Base 64 string to decode

Returns:

String
The decoded string

encode_b64

(source code)
encode_b64(toEncode)
Permits to encode in Base 64

Parameters:

String
toEncode
It's the string to encode into Base 64

Returns:

String
The encoded string

getLookup

(source code)
getLookup(text)
Split the ID and Value

Parameters:

String
text
The string to retrieve data

Returns:

Object
.id returns the ID, and .value returns the value

Example:

$SP().getLookup("328;#Foo"); // --> {id:328, value:"Foo"}

getURL

(source code)
getURL()
Return the current base URL website

Returns:

String
The current base URL website

regionalDateFormat

(source code)
regionalDateFormat(callback)
Provide the Date Format based on the user regional settings (YYYY for 4-digits Year, YY for 2-digits day, MM for 2-digits Month, M for 1-digit Month, DD for 2-digits day, D for 1-digit day) -- it's using the DatePicker iFrame (so an AJAX request)

Parameters:

Function
callback Optional
It will pass the date format

Example:

// you'll typically need that info when parsing a date from a Date Picker field from a form
// we suppose here you're using momentjs
// eg. we want to verify start date is before end date
var startDate = $SP().formfields("Start Date").val();
var endDate = $SP().formfields("End Date").val();
$SP().regionalDateFormat(function(dateFormat) {
  // if the user settings are on French, then dateFormat = "DD/MM/YYYY"
  if (moment(startDate, dateFormat).isAfter(moment(endDate, dateFormat))) {
    alert("StartDate must be before EndDate!")
  }
})

// Here is also an example of how you can parse a string date
// -> https://gist.github.com/Aymkdn/b17903cf7786578300f04f50460ebe96

regionalSettings

(source code)
regionalSettings(callback)
Find the region settings (of the current user) defined with _layouts/regionalsetng.aspx?Type=User (lcid, cultureInfo, timeZone, calendar, alternateCalendar, workWeek, timeFormat..)

Parameters:

Function
callback Optional
A function with one paramater that contains the parameters returned from the server

Example:

$SP().regionalSettings(function(region) {
  if (typeof region === "string") {
    // something went wrong
    console.log(region); // returns the error
  } else {
    // show the selected timezone, and the working days
    console.log("timeZone: "+region.timeZone);
    console.log("working days: "+region.workWeek.days.join(", "))
  }
})

toCurrency

(source code)
toCurrency(number, decimal, sign)
It will return a number with commas, currency sign and a specific number of decimals

Parameters:

Number|String
number
The number to format
Number
decimal Optional, Default: -1
The number of decimals (use -1 if you want to have 2 decimals when there are decimals, or no decimals if it's .00)
String
sign Optional, Default: '$'
The currency sign to add

Returns:

String
The converted number

Example:

$SP().toCurrency(1500000); // --> $1,500,000
$SP().toCurrency(1500000,2,''); // --> 1,500,000.00

toDate

(source code)
toDate(textDate, forceUTC)
Change a Sharepoint date (as a string) to a Date Object

Parameters:

String
textDate
the Sharepoint date string
Boolean
forceUTC Optional, Default: false
Permits to force the reading of the date in UTC

Returns:

Date
the equivalent Date object for the Sharepoint date string passed

Example:

$SP().toDate("2012-10-31T00:00:00").getFullYear(); // 2012

toSPDate

(source code)
toSPDate(dateObject, includeTime)
Change a Date object into a Sharepoint date string

Parameters:

Date
dateObject
The Date object you want to convert
Date
includeTime Optional, Default: false
By default the time is not returned (if the time appears then the WHERE clause will do a time comparison)

Returns:

String
the equivalent string for the Date object passed

Example:

$SP().toSPDate(new Date(2012,9,31), true); // --> "2012-10-31 00:00:00"
$SP().toSPDate(new Date(2012,9,31)); // --> "2012-10-31"

toXSLString

(source code)
toXSLString(text)
Change a string into a XSL format string

Parameters:

String
text
The string to change

Returns:

String
the XSL version of the string passed

Example:

$SP().toXSLString("Big Title"); // --> "Big_x0020_Title"

workflowStatusToText

(source code)
workflowStatusToText(code)
Return the text related to a workflow status code

Parameters:

String|Number
code
This is the code returned by a workflow

Example:

$SP().workflowStatusToText(2); // -> "In Progress"