What the scripts do
|
|
|
A variety of scripts, each with full documentations, examples, and the test forms to get acquainted with their workings and being thus able to use them with full confidence.
Some may require an intensive use of the test forms to be grasped, but anyway the good news is that whenever you have a task in mind and you want to know how one of these scripts properly behaves, just run the test form with different options until you find the pattern that suits your need; the syntax inspectors are even to show to you how the invoking of the script would appear.
THE TEST FORMS
|
|
All the documentations and test forms for these scripts
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
THE VECTORIALIZER |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ITS CODEZ:
/
/
/
/
/
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
WHAT IT DOES: |
When you have an Object, it holds its properties and each of them has a value. None the less, these properties inside the object are not arranged like an Array which as such can be addressed by numerical indexes, but conversely they are arranged as associative arrays whose indexes, being associative, are not numbers but literals.
None the less, you may want to use a function tailored to manipulate numerically indexed arrays in order to manipulate the values held by the properties of this object, and then you want to be able to reassign to the properties of the object the new values reshaped by the process they underwent by some other script tailored to handle numerically indexed arrays.
The vectorializer can:
- Given an Object as unique argument, unfolds both the names of the properties and their values and returns them as an array of two entries where:
vectorializer(ObjectArg)[] is a numerical array whose each entry is the name of a property.
vectorializer(ObjectArg)[] is a numerical array whose each entry is the value of the respective property name at the respective numerical array index on the previously generated array.
Therefore you can now manipulate the yielded array of values, which is:
vectorializer(ObjectArg)[]
- Given an Object and a second parameter ehich is an array whose each entry is a name of a property in the object, it does the same as above but collects only those properties whose name matches with one of the names passed in the second argument array.
- Given an Object and two more arguments for an overall of three arguments, it rolls back: the latest two arguments must be two arrays, the first holding names of the properties, the second an array holding the values (arguably manipulated as in #1): the vectorializer would therefore assign to the property in the Object the corresponding values in the array of values.
You can manipulate the array of values but if it gets increased or shrinks, the roll back would not match. manipulate with scripts that work on arrays without altering the length of the manipulated array.
If so, this script is a great avenue to (re)use scripts tailored to tackle numerically indexed arrays on associative arrays without having to conceive a brand new script for the different type of indexing.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ARGS.: |
/
/
/
/
/
NOTES: |
- object: an object.
- names: a numerically indexed array of Strings which are the names of the properties you want ant to selectively extract. If no such arguments, extracts all the properties from the object.
- values: if this third argument is present, must be a numerically indexed array as well and hold values to be reassigned to the Object.
|
The length of the array passed as names rules when rolling back: this means that if the length of the values array is inferior or higher than the length of the values array, only as many properties values in the values array as many entries in the names array are, will be reassigned to Object with the new values.
An example:
given an object named foo:
var unfolded=vectorializer(foo)
Now unfolded holds two entries, the first an array of all names the second an array of all values. You could have limited the amount of extracted names and corresponding values by passing as second argument an array of property names to pinpoint.
Now you can manipulate the values with some subroutine such as, say, myfooFunc()
var newValues=myfooFunc(unfolded[])
To roll back: reassign to foo object itself if you want, for when rolling back (which in the script is deduced by the fact as many as 3 arguments are passed) the vectorializer returns again an array of two entries, but this time the first is the reshaped Object
foo=vectorializer( foo, unfold[], unfold[] )[]
Note that vectorializer returns an array of two entries in any case, but if it rolls back, the first entry is an Object; the second, in the roll back case, would be another array whose length is either zero if the passed values and names arrays where identical in length, or an array whose length is 1 if the two names and values argument array lengths mismatched, to flag something might be gone wrong.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
THE ARRAY SWAPPER |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ITS CODEZ:
/
/
/
/
/
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
WHAT IT DOES: |
Like the name suggests, the script swaps the entries in an array.
An analogous function that, among many things, can swap is the Array master: the arrayMaster swaps following precisely pinpointed couples, whereas the arraySwapper swaps following a predefined pattern until the end of the array is attained.
The test form is here particularly useful for there are a great variety of possible patterns that can be defined and you can test them in order to find (also peeking at the syntax inspector field in the test form) the type of arguments combinations that relinquish your desired combination of swappings.
Another very interesting script to rearrange an array after a pattern (but not directly focused on swaps) is the Leap Loop.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
/
/
/
/
/
NOTES: |
/
/
/
/
/
ARGUMENTS: |
The only thing which should really be understood is that offset and range would not change during the process if no offsetPlus and/or rangePlus is passed.
Since many combinations are possible, use the test form. I suggest first to envision a type of swapping (starting with the simplest ones) you may want to perform, and arrange the arguments until you find what logics in the syntax reproduce your intentions.
|
- array: the input array which must be swapped.
- offset: the index (starting with zero) the swapping process must start at.
- range: the subsequent entry after offset which must be grabbed to perform the swap.
- offsetPlus: the increase that the offset position must jump to after the first swap and for all the subsequent ones until the end of the array is reached.
- rangePlus: the increase the range must jump by after the first swap has been performed, and so on.
- untilOffsetIs: if passed, can determine whether the swappings must stop before the offset position has reached the end of the array (that is, you can prematurely stop it): if it is set and no offsetPlus is set, then offsetPlus automatically defaults to 1 at least.
- untilRangeIs: if passed, can determine whether the swappings must stop before the range position has reached the end of the array (that is, you can prematurely stop it): if it is set and no rangePlus is set, then rangePlus automatically defaults to 1 at least.
- fromOriginal: if not set (default) the swappings would swap on the last saved conformation instead of insisting on the non-varying input array. if set to 1 or more, it will perform the swaps on the original array. You may see for more on this, the comment at bottom of the Array master file, where it is documented what is meant by swapping on the last saved conformations. Anyway you don't have to bother with that if you prefer so, for the default is the more logical.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
THE SELECT DATA |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ITS CODEZ:
/
/
/
/
/
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
WHAT IT DOES: |
Actually you can find some more utilities meant to manipulate select form menus in the miscella #1 file.
This selectData function returns an Array of 6 entries, each of which is an Array itself:
- selectData(args)[]: an array of all the values of the options in the select menu.
- selectData(args)[]: an array of all the texts of the options in the select menu.
- selectData(args)[]: an array of all the indexes of the options in the select menu.
- selectData(args)[]: If the action argument (see further on) is set as 2 or as a String, it is an array carrying all the values of the options that were not either selected (action=2) or did not match with the String (if action was a string)
- selectData(args)[]: If the action argument (see further on) is set as 2 or as a String, it is an array carrying all the texts of the options that were not either selected (action=2) or did not match with the String (if action was a string)
- selectData(args)[]: If the action argument (see further on) is set as 2 or as a String, it is an array carrying all the indexes of the options that were not either selected (action=2) or did not match with the String (if action was a string)
You can get these arrays as arrays holding:
- All the options data.
- Only the selected options (either single or multiple selections) data.
- Only those carrying a specified string of text:
- Either in the values (additionally you can specify whether such search has to be case insensitive or not; defaults to case sensitive)
- Or in the texts (additionally you can specify whether such search has to be case insensitive or not; defaults to case sensitive)
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
/
/
/
/
/
NOTES: |
/
/
/
/
/
ARGUMENTS: |
The only thing to keep in mind is that if the select menu is a select menu whose size is equal to one (that is, you can see only one scrollable options instead than a list of a few scrollable options), the first of these options appears being consodered by the browsers as selected anyway, even if no such specification has been set in the html tag and even if no actual selection on such first option has been performed by the user: I argue it is meant to deliver to the server some data anyway.
Last but not least, if the function finds no matches (like when it scans for selected options or texts), it returns anyway an output Array of 6 entries, but the first three entries are arrays whose length is zero.
|
- menu: the menu object as a path reference such as:
document.formName.selectName
If by chance you pass only the name of the select as a string, the script will try to guess whether such a select with such a name is available in the first form (if any) of the document.
- action: if it is not set, the script would collect values/texts/indexes from all the available options.
- action=0 or 1: collects all.
- action=2: collects only the options which have been selected.
- action="String": the script argues you want to search for options carrying such text: you have therefore to define the following parameters. if you don't, the script would search for such text in the values, and would perform a case sensitive search.
All these searches look strictly for the type of texts which have been passed, so if by chance you add a space, and such a space is not in the value or in the searched texts, the script would detect no match: almost a match means no match.
- action=Array: behaves as if they were a list of strings, applying the rules mentioned for the strings, and it will look for all the texts or values in the available options that match with the entries of the action array: this is, in other words, a search for multiple entries! You can therefore search for many different data, by passing action as an Array: example:
new Array("Hallo 1", "Hallo 2")
- searchWhere:
- 0 or 1: search in the values of the option.
- 2: search in the texts of the options.
- caseInsensitive: if set to 1, performs the search case insensitive.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
THE ARRAY CLEANSER |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ITS CODEZ:
/
/
/
/
/
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
WHAT IT DOES: |
Given an input array and a subsequent list of data, finds those entries in the input array which are identical to such data and removes them, returning a brand new array from where all such items have been eliminated.
The difference with the unset is twofold:
- The unset has one disadvantage: can eliminate only one instance at a time, whereas with the arrayCleanser you can issue a whole list of items to delete.
- The unset has one advantage: can eliminate also selective indexes (that is, referring the array by index instead than by value), and can work also on associative arrays (that is, non numerically but literal indexed arrays).
Also, and more precisely, the returned data is an array of two entries. So:
- arrayCleanser[] holds the returned newly produced array
- arrayCleanser[] holds an... associative array whose each index is the value (String, Number, Object, Boolean, doesn't matter: it is stored indeed as an index of this secondly produced output) of a replaced item (instance, you want to delete all those entries in this Array which hold the Boolean false: if and only if such a value has been detected in within the input array, then the output would carry as arrayCleanser[] an associative array one of whose indexes will really be: false! Such entry
arrayCleanser[][false]
is an array itself, whose each entry is the numerical index of the original input array where the replacement happened, and therefore the length of such an array can also reveal how many replacements for that given instance have been performed in the original input).
So if you have in the list of your item to delete something like "foofoo", which is obviously a String, well if you do something like:
var myvar=arrayCleanser(anArray, "foofoo", optionalMore)
well now you can find that:
myVar[0] is your newly produced array without the "foofoo" entries, and the existance of a:
myVar[1]["foofoo"]
is the flag that some "foofoo" has been found indeed, and its length
myVar[1]["foofoo"].length
tells you how many times it has been found. And if you loop it, can even tell in what positions of the original.
Since the original isn't affected, it can also be a way to find the numerical indexes of the positions of a given entry inside an Array!
Remember that to scan associative array you use for-in loops.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ARGS.: |
/
/
/
/
/
NOTES: |
input: the input array. if none, the script returns false.
All the subsequent arguments are the entries to delete.
|
You can pass the entries you want to delete either as one single array argument after the input, or as a list of items separated by a comma (accepts whatever type of data type!), or ev a mix of arrays and single data. If it doesn't detect entries to delete at all, returns a double entry array whose first entry is the original input array, and the second entry an empty Object to keep data type compatibility with the associative Array it would have returned if it would have found matches to delete.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
|
 |
 |
 |
 |
|
/
/
/
/
/
THE ARRAY DOUBLER |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ITS CODEZ:
/
/
/
/
/
|
|
|
 |
 |
 |
 |
 |
|
/
/
/
/
/
WHAT IT DOES: |
Given an input Array, it can:
- Eliminate all the entries which are not single (same values hold by multiple entries, that is)
- Eliminate only those doubles which are in a list
- Eliminate only those doubles which are not in a list
In all cases what happens is that only one item of the defined entry is left.
Returns an Array of two entries where the first is the reshaped object, the second is an associative array whose each entry is an array whose length measures how many instances have been found for each type, and in such array each entry flags the index of the position where such entry was eliminated (reports all the positions: the one each instance is taken from is, arguably enough, the first listed). For more on this procedure, please refer to the What it Does section for the script above.
It may be useful to repeat that to scan associative array you use for-in loops.
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
/
/
/
/
/
ARGS.: |
/
/
/
/
/
NOTES: |
input: the input array. if none, the script returns false.
how:
- If zero, just eliminates all the doubles
- If zero and countables argument is present, it eliminates only those doubles which are in the countables list.
- If number 1 and countables argument is present, it eliminates only those doubles which are not in the countables list.
All the subsequent optional arguments are the entries to include into countables.
|
You can pass the entries you want to countables either as one single array argument after the input, or as a list of items separated by a comma (accepts whatever type of data type!), or even a mix of arrays and single data. If it doesn't detect entries to countables at all, returns a double entry array whose first entry is the original input array, and the second entry an empty Object to keep data type compatibility with the associative Array it would have returned if it would have found matches to delete.
If you want to pass the countables but not to set the how argument, you have to pass it anyway. Examples of the 3 possible statements:
- arrayDoubler(INPUT)
- arrayDoubler(INPUT, 0, ARRAYs)
- arrayDoubler(INPUT, 1, ARRAYs)
As usual, arrayDoubler(INPUT)[] is the main object you arguably want, and is an array.
arrayDoubler(INPUT)[] is an associative array as stated before. Each literal index of it, holds a numerical array (see above).
|
 |
 |
 |
 |
 |
 |
 |
 |
 |
 |
|
|
|
|
 |
 |
 |
 |
 |
|