SaaS allows you to write more powerful webscale applications by offloading trivial tasks to our server.
The SaaS API is free to use for personal and commercial purposes.
To use the API, download SaaS.js
and include in your website header.
That's it. All functionality is exposed through the global SAAS
property.
Usage is simple:
await SAAS.math.round(0.123456, 3); //Result is 0.123
Our API is simple to use even without the aid of SaaS.js
.
We accept multipart/form-data
and application/x-www-form-urlencoded
.
Each request has at least 1 parameter, the mode
parameter.
Any mode specific parameters are used alphabetically in ascending order.
Example: A mode that needs 4 additional parameters will use a,b,c,d
.
The additional parameters must be valid JSON.
a="5"
will assign 5 as string, a=5
will assign 5 as integer.
The result will be a JSON structure with these properties:
success
: true, if the API call was successful, false otherwiseres
: If successful, contains the resultmsg
: If failed, might contain an error message
Mode: lt
, lte
, gt
, gte
Parameters: 2
Result: (bool) (a [op] b)
Details:
Operator is as follows:
Mode: eq
Parameters: 2
Result: {lose:(bool)a==b,strict:(bool)a===b}
Details:
Compares the two parameters for equality.
Once with type coercion where necessary and once without.
This function will recursively process arrays or array like objects.
This means it will consider a={test:[1,2,3]} b={test:[1,2,3]}
equal
Mode: floor
, ceil
Parameters: 1
Result: floor(a)
or ceil(a)
Mode: round
Parameters: 2
Result: round(a,b)
Details:
Rounds a
to b
number of decimal digits.
Uses the widely used method of rounding X.5 up.
Mode: add
, sub
, mul
, div
, mod
, pow
Parameters: 2
Result: a [op] b
Details:
Operator is as follows:
Mode: sqrt
Parameters: 1
Result: op(a)
Details:
Operator is as follows:
Mode: rnd
Parameters: 0
Result: rnd()
Details:
Returns a random number in the range 0 <= x < 1
Mode: crnd
Parameters: 1
Result: crypto_rnd(a)
Details:
Returns the given number of cryptographically safe randon numbers.
Maximum count is 100000.
Range 0 <= x <= 255
Mode: sr
, sl
Parameters: 2
Result: a [op] b
Details:
Shifts a
by b
digits into the given direction.
Interprets the parameters as 64 bit integers.
Operator is as follows:
Mode: band
, bor
, bxor
Parameters: 2
Result: a [op] b
Details:
Interprets the parameters as 64 bit integers.
Operator is as follows:
Mode: bnot
Parameters: 1
Result: [op]a
Details:
Interprets the parameter as 64 bit integer.
Operator is as follows:
Mode: concat
Parameters: 2
Result: a [concat] b
Details:
Works with both parameters being strings or both parameter being array like objects or objects.
Duplicate keys in two objects will keep the last occurance only.
Plain arrays will be concatenated by putting the elements from the second array after the first one:
[1,2]+[2,3]=[1,2,2,3]
Mode: substr
Parameters: 2 or 3
Result: substr(a,b[,c])
Details:
Returns the string a
beginning at offset b
with c
bytes in length.
If c
is not given, will return everything until the end.
b
can be negative to interpret it as an offset from the string end rather than the start.
If the offset is beyond the string length, will return an empty string
c
can be negative to interpret it as how many characters before the end to stop.
If it's 0, it will return an empty string. If it's set in a way to exceed the string length, it's clamped down.
Mode: join
Parameters: 2
Result: join(a,b)
Details:
Joins elements of array a
with the given string b
.
b
can be of any length, including being an empty string.
Will return an empty string if a
has no elements.
Mode: split
Parameters: 2
Result: split(a,b)
Details:
Splits string a
at every character sequence b
.
Returns an array with a
as single entry if b
can't be found.
Splits the string into individual characters if b
is an empty string.
Mode: match
Parameters: 2/3
Result: match(a,b)
/match_all(a,b)
.
c
is an optional boolean (default:false) that ca nbe used to cause global matching.
The result will be an array of all matches. It's unset if no match was found.
For single matches (c=false
) The first entry is the complete match,
all other entries are the capture groups.
For global matches (c=true
) The first entry is an array of all complete matches,
all other entries are arrays of the capture groups.
Details:
matches string a
against regular expression (PCRE) b
.
Mode: noop
Parameters: 0
Result: "noop"
Details:
Does nothing. Usable to check API availability
Mode: time
Parameters: 0/1/2
Result: unix_time()
/format_time(a,unix_time())
/format_time(a,b)
Details:
Without any arguments, returns current unix timestamp (seconds since 1970-01-01 00:00:00 UTC).
With one argument, returns the current unix timestamp formatted as string.
With two arguments, returns the given unix timestamp (b
) formatted as string.
Formats for a
:
Mode: date
Parameters: 1/2
Result: date_parse_to_timestamp(a)
/date_parse_to_timestamp(a,b)
Details:
Parses common english formats of a date into a unix timestamp.
Working examples:
b
is given.
This has no effect when absolute timestamps are parsed.
Mode: push
Parameters: 2
Result: a[a.length]=b
Details:
Treats the array a
as a stack and pushes a new element b
onto it and returns the new array
Mode: pop
Parameters: 1
Result: {"value": pop(a), "array": a}
Details:
Removes the top (last) element from array a
and returns the new array and value.
Works with objects too, but will discard the key.
Mode: shift
Parameters: 1
Result: {"value": shift(a), "array": a}
Details:
Removes the bottom (first) element from array a
and returns the new array and value.
Works with objects too, but will discard the key.
Mode: parse
Parameters: 1
Result: JSON(a)
Details:
Parses the given argument into a JSON object
Mode: guid
Parameters: 0
Result: guid()
Details:
Returns a version 4 Guid (also known as UUID) using a cryptographically secure random number generator.