✌ V5 Feature Compilation

##JScript Helper objects Documentation.

###web

Helper methods to upload / download data.

web.Download(url,[regex])
returns url content and optionally returns first group capture of given regex.

web.Upload(url,content)
uploads content to url with POST method.


###file

Helper object to work with files.

file.ReadFromFile(filePath)
returns content of file.

file.WriteToFile(filePath,content)
overwrites file with given content.

file.AppendToFile(filePath,content)
appends content at the end of the file or creates file if not exists.


###DateRange

This is a helper class that contains a date/time range. Do not use directly. We’ll use dt object to create date ranges.

DateRange.Start
Starting date time of the range.

DateRange.End
Ending date time of the range.

DateRange.Days
Returns total day count of range.

DateRange.MonthName
Returns month name for start date


###dt
Contains helper functions to create date ranges (DateRange objects).

dt.Day(day=0)
retuns a singe day range. All ranges starts at 00:00:00 and ends 23:59:59. Use day parameter to add / subtract days. dt.Day() returns today, dt.Day(-1) returns yesterday.

dt.Week(week=0)
returns single week date range. dt.Week() returns this week, dt.Week(-1) returns previous week.

dt.Month(month=0)
returns current Month range. dt.Month(-1) returns previous month.

dt.GetRange(start,end) after [5.1.11]
returns a range from given date strings.
var range = dt.GetRange('1.1.2015','2.2.2015');


###sql

Helper to read SQL script results.

sql.Exec(handlerOrScript,dateRange,[delimiter=‘,’])

Returns a string array (string). You can enter a script handler or SQL Query as handlerOrScript parameter. dateRange used to fill {Start} and {End} parameters of script. Delimiter is used to convert multiple columns to a single string value. Use indexer if query returns multiple rows.

Examples

var query = 'select count (*) from Tickets where Date > \'{Start}\' and Date < \'{End}\';
var yesterdayTicketCount = sql.Exec(query,dt.Day(-1))[0];

query can also be a script handler. It should start with double @@.

var query = '@@TicketCount';
var yesterdayTicketCount = sql.Exec(query,dt.Day(-1))[0];


sql.Query(query)
Provides a fluent interface to construct date ranged sql queries easily.

syntax
sql.Query(handlerOrQuery).[ByWorkPeriod].[Delimit(‘,’)].Range.[First|All]

ByWorkPeriod
Using optional ByWorkPeriod converts date ranges to work period date ranges. For example ByWorkPeriod.ThisWeek aligns ThisWeek range to work period start, end times.

Delimit(‘,’)
Using delimit will configure a delimiter for multi column queries. Optional.

Range
Can be Today,Yesterday,ThisMonth,PreviousMonth,ThisWeek,PreviousWeek.

Also Range(dateRange) can be used to configure custom ranges. For example
sql.Query('@@TicketCount').Range(dt.Day(-2)).First;

First | All | Join()
Method chains can end with First or All. First returns first row. All returns all rows as a string array. Columns are always merged to a single string with delimiter. Join(<delimiter>) joins All values to a comma delimited string.


sql.ExecSql(handlerOrScript)

Executes Query and returns a string array (string). You can enter a script handler or SQL Query as handlerOrScript parameter.


###xml

Allows easy parsing of xml format.

xml.Parse(xmlContent)
Returns a dynamic object that allows you access tag values with properties.

example

var content = '<car><plate>123</plate><color>red</color></car>';
var car = xml.Parse(content);
var carColor = car.color.Value;
var plateNumber = car.plate.Value;

:bulb: hint: You can read tag values with Value.
For example book.author.birthday.Value;

###tag
Helper methods for easy constructing formatted Tile content.

syntax
tag.[tagFunction]

Possible tag functions

Color(color,[content])         
Size(size,[content])           
Font(fontName,[content])  
Bold([content])
ExtraBold([content])
Thin([content])
Italic([content])
Underline([content])
Block([content])
Panel(color,[content])
Linebreak()
Sym(content)
Img(content)  
Add(content)    * does not terminates
Get([content])

Example

<size 36>Header</size>
tag.Size(36,'Header');

You can chain these methods to construct formatted tile content.

<bold><size 36>Header</size></bold>
tag.Bold().Size(36,'Header);

While chaining methods we need to understand how it terminates. General rule is using optional [content] parameter will terminate method chain. In other words returns result.

For Example:

return tag.Bold().Size(36); will return nothing as Size method used without content and it still expects additional methods.

return tag.Bold().Size(36).Color('red'); will still return nothing.

We can terminate it by using Get(content) method or by using Color method’s optional content parameter.

return tag.Bold().Size(36).Color('red','Hello');
or
return tag.Bold().Size(36).Color('red').Get('Hello');

Both Produces:
<bold><size 36><color red>Hello</color></size></bold>

:information_source: If content parameter used in a method, chain terminates.

Methods that accepts optional content parameter listed as content parameter in square brackets. For example Bold([content]) means content parameter is optional. You can terminate chain by using content parameter or skip it to add more methods. But for Img(content) method content parameter is not optional. So using that method will immediately terminate chain.

:warning: add(content) method is an exception here. Content parameter is not optional but it does not terminates because it can be used to append non tag related content. For example tag.Add('hello').Add('world').Get(); will produce hello world.

It is possible to concat strings at the end of methods. tag.Bold('Hello') + ' World' will produce <bold>Hello</bold> World.

2 Likes