Talk

cybero's picture
JavaScript String Handling In Quartz Composer - an example

Just a greatly revamped and updated version of the original QC 2 file that was recently posted once I'd done the translation of the QC JavaScript Guide.

All the examples on that guide are simply QC2 compliant, made in the days we used to click a list for input items.

Now variables require full declaration amongst other formatting features, including of course the function statement's format.

Whatever, please find attached a simple example, the code for which I reproduce below, so you can download or copy and paste - it's up to you :-)

var Day = str;
var dateObj = new Date();
 
var str = dateObj.toDateString();
var str8 = dateObj.toTimeString ();
 
var str2 = dateObj.getMonth() + 1;
var str3 = dateObj.getFullYear ();
var str4 = dateObj.getTime();
 
var d = 28;
var m = 1;
var n = dateObj.getDate  ();
var q = dateObj.getTime ();
var o = dateObj.getMonth ();
var p = dateObj.getYear ();
var r = str.charAt (1); 
 
function (__string Day, __string Month, __string Year, __string Clock, __string charOut) main (__number Time[1])
 
{
   var result = new Object();
   if 
   (n < (d))
   {result.Day =  " Date :- " + str +" | Day Number -> "+ n+"  ";}
   else   
   {if (n > (d))
   {result.Day =  " Date :- " +str +" | Day Number -> "+ n + "  ";}
   else
   if (n = (d))
   {result.Day =  " Date :- " + str +" | Day Number -> "+ n + "  ";}
   }
   {result.Month =  " Month Number:- " + str2;}
   {result.Year =  " Year :- " + str3 +" || Year -> "+ str3+"  ";}
   {result.Clock =  " Time :- " + str8;}
   {result.charOut = "Today's lucky letter is :- " + r;}
 
   return result;
}
PreviewAttachmentSize
toDateandTimeStringifelseHandling.qtz8.95 KB

cybero's picture
Strings in JavaScript In Quartz Composer

Following on from my recent post evidencing some rudimentary string handling.

Strings can be letters or numbers and almost any available object within the core classes can become , in effect, an output to be handled as a string.

Strings can also be created within the JavaScript, as well as getting the JavaScript to handle strings of data drawn from 'indigenous' JavaScript objects.

There are some objects that are purely and simply made to provide string data for a given object

They are pretty much a doddle to work with :-)

toDateString
toGMTString
toLocaleDateString
toLocaleString
toLocaleTimeString
toTimeString
toUTCString 

Other in built objects are intended to aid in handling character code & / or string alphanumeric content.

charAt
charCodeAt
fromCharCode
indexOf
lastIndexOf
length

Some of these rely upon RegExp and have not been included in the example file below.

These are the objects that I'm still needing to make work in QC3 JavaScript conformant fashion.

match
replace
search
slice
split
substr
substring
toLowerCase
toUpperCase

The following attached file builds a little upon the ifelse Date Time String handling file.

It's called ALotOfStrings.

Still working on making the QC3 conformant JavaScript do all that RegExp stuff, so expect to see that sometime soon, unless it's a blind alley due to that joining the number of items that didn't seem to be supported / available in QC2, which were :-

$ 1 - $ 9
compile
exec
astIndex
lastMatch
lastParen
leftContext
rightContext

I shall be reworking the example files for the guide to be QC3 conformant.

At present the patches if copied from the QC2 type originals will paste into a QC3 document and will run.

All else is a purely a matter of slight differences between QC2 and QC3 in explicitly formatting and stating code and variables and so forth.

PreviewAttachmentSize
ALotOfStrings.qtz15.88 KB

cybero's picture
RegExp & String Handling: JavaScript In Quartz Composer

Well it's not all of the QC2 RegExp features exemplified, but it does contain quite a few of them.

toUpperCase
toLowerCase
slice
regExp
substring
[code]
 
The rest shall follow.
 
Eventually they shall be available as downloadable snippets from an updated version of the currently posted [guide](http://cybero.co.uk/QuartzComposerJavaScriptGuide-Eng/index.html).
PreviewAttachmentSize
RegExpStrings.qtz9.92 KB