Here's one I use (although not tested in this format) to throw all the junk
out off encoded url's, AND remove the + signs from the string.

/**
 * unEscape()
 * Returns the string unEscaped, i.e. all the \ + codes out, like standard
unescape, but also replace + with space
 */
String.prototype.unEscape = function() {
    return unescape(String(this).replace(/\+/g, " "))
}

You've a nice collection, but I wouldn't know what was available if I didn't
use it regularly, I don't suppose some documentation, with an index and
examples would be on the cards?

On the otherhand, after everyone has added their favorite short-cut, this
will be one long file to download if you need one line of code, but I guess
it's up to the user to take what they need at the time.

Cheers,
Richard Bennett

[EMAIL PROTECTED]
www.richardinfo.com
(Everything running on, and ported to the 19/12/2000 snapshot of DynAPI2)
visit the DynAPI homepage (and FAQ) ::
http://dynapi.sourceforge.net/dynapi/index.php?menu=1
Browse (and search) the mailinglist here:
http://www.mail-archive.com/index.php3?hunt=dynapi


----- Original Message -----
From: "Marc van Leeuwen" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, April 03, 2001 9:27 AM
Subject: [Dynapi-Dev] Javascript Extension File


> As promised a few days ago (by Jordi mainly), here is the code I can
> contribute to the javascript extension file(tm):
>
> I copy the text into the message, as I personnaly HATE attachments for
this
> kind of short text. It will also be easyier to comment/modify/reply.
> However, if you (i.e. people on the list) prefer it sent as attachment,
> just tell me.
>
> Please also note that the comments used are NOT easily
parsable/strippable,
> as proposed earlyier on the list, by using '/*---' or the like one-line
> comments. I'll write in another post maybe some clues about comment
> stripping. The comments given can also be much reworked, if they sound too
> 'French' or 'Dutch', or simply are incomplete
> Also sorry fot the tabbing, but I usually use small tabs, 3 or 4 in my
files...
>
> Not all of the stuff is "own made", some ((un)shift, push, pop, splice)
> comes from webreference.com (see previous posting from Joachim Lundgren,
> msg ref [EMAIL PROTECTED]), The trim string
> methods/function are mostly from him too.
>
> If you want to see this content in a NICE 'colorized' way, point to:
> http://www.japiesoft.com/DynAPI/Javascript_Extension_File.html (ThanX
SciTE !)
>
> Ready ? Here it goes:
>
>
>
> // -----------------------------------------------------
> // Array
Functions ----------------------------------------------------------
> // -----------------------------------------------------
>
> /**
>   * isArray(aVar)
>   * Returns true if the argument passed is a Javascript Array.
>   */
> function isArray(aVar) {
> return  (aVar && (typeof(aVar) == 'object') && (aVar.constructor ==
Array));
> }
>
>
>
> /**
>   * toString()
>   * Returns a String containing the Array as if it where written in a
> declaration (can someone correct this please ?).
>   * Example: ['foo', 'bar']
>   */
> Array.prototype.toString = function() {
> return '['+this.join(', ')+']';
> }
>
>
> // --------------------------------------------
> // -------- from webreference.com, column 31 to 33
> // (I HAVE NOT TESTED IT !)
> // --------------------------------------------
> if(!Array.prototype.shift) {
> Array.prototype.shift = function() {
>          firstElement = this[0];
>          this.reverse();
>          this.length = Math.max(this.length-1,0);
>          this.reverse();
>          return firstElement;
>      }
> }
>
> if(!Array.prototype.unshift) {
> Array.prototype.unshift = function() {
>          this.reverse();
>          for(var i=arguments.length-1; i>=0; i--){
>              this[this.length] = arguments[i];
>          }
>          this.reverse();
>          return this.length
>      }
> }
>
> if (Array.prototype.push && ([0].push(true)==true))
>          Array.prototype.push = null;
> if(!Array.prototype.push) {
>      Array.prototype.push = function() {
>          for(i=0;i<arguments.length;i++){
>              this[this.length] = arguments[i];
>          }
>          return this.length;
>      }
> }
> if(!Array.prototype.pop) {
>      Array.prototype.pop = function() {
>          lastElement = this[this.length-1];
>          this.length = Math.max(this.length-1,0);
>          return lastElement;
>      }
> }
>
> if(Array.prototype.splice && typeof([0].splice(0))=="number")
>      Array.prototype.splice = null;
> if(!Array.prototype.splice) {
> Array.prototype.splice = function(ind,cnt){
>          if(arguments.length == 0) return ind;
>          if(typeof(ind) != "number") ind = 0;
>          if(ind < 0) ind = Math.max(0,this.length + ind);
>          if(ind > this.length) {
>              if(arguments.length > 2) ind = this.length;
>              else return [];
>          }
>          if(arguments.length < 2) cnt = this.length-ind;
>          cnt = (typeof(cnt) == "number") ? Math.max(0,cnt) : 0;
>          removeArray = this.slice(ind,ind+cnt);
>          endArray = this.slice(ind+cnt);
>          this.length = ind;
>          for(var i=2;i<arguments.length;i++){
>              this.push(arguments[i]);
>          }
>          for(var i=0;i<endArray.length;i++){
>              this.push(endArray[i]);
>          }
>          return removeArray;
>      }
> }
>
>
>
>
>
>
>
>
> /**
>   * contains(element)
>   * Returns 'true' if the Array contains the element 'element', false
> otherwise.
>   * Note: uses push() and pop()
>   */
> Array.prototype.contains = function(element) {
> this.push(element); // we add the element searched at the beginning
> var i = 0;
> while (this[i++] != element); // we go forth in the array until found.
> var result = (i!=this.length); // but is it the element we placed ?
> this.pop(); // anyway, we must remove what we added.
> return result;
> }
>
>
> /**
>   * getUnique()
>   * Returns the array whithout any duplicate, in the same order
>   * Note: uses push()
>   */
> Array.prototype.getUnique = function() {
> var check = [];
> var res = [];
> for (var i = 0; i < this.length; i++) {
> var indice = "test"+this[i];
> if (!check[indice]) { // if this[i] has not already been added
> check[indice] = true; // we mark this element as added
> res.push(this[i]); // and we add the element
> }
> }
> return res;
> }
>
>
>
> // -----------------------------------------------------
> // String
Functions ----------------------------------------------------------
> // Mostly come from Joachim Lundgren, again....
> // -----------------------------------------------------
> /**
>   * trim(side)
>   *  Trims the 'left' or the 'right' of the String, or both if 'side' is
> nor 'left', nor 'right'
>   * Courtesy
>   */
> String.prototype.trim = function(side) {
>      switch(side) {
>          case "left":
>              return this.replace(/^\s+/, "");
>          case "right":
>              return this.replace(/\s+$/, "");
>          default:
>              return this.replace(/^\s+|\s+$/g, "");
>      }
> }
>
>
> String.Trim  = function(str) { return str.toString().trim();        }
> String.LTrim = function(str) { return str.toString().trim("left");  }
> String.RTrim = function(str) { return str.toString().trim("right"); }
>
> // These are for VBScript-feeling
> function Trim(str)  { return str.toString().trim(); }
> function LTrim(str) { return str.toString().trim("left"); }
> function RTrim(str) { return str.toString().trim("right"); }
>
>
>
> /**
>   * escape()
>   * Returns the string escaped, i.e. all the ' and " get a backslash
before it
>   * NOTE: I do not remember if this worked. As far as I remember, I had
> strange behaviour (both in NS and IE) if you put '" or "' at the end of a
> String and use this method.
>   */
> String.prototype.escape = function() {
> return this.replace(/'/g, "\\\'").replace(/"/g, '\\\"');
> }
>
>
>
> /**
>   * toFirstUppercase()
>   * Returns the String with the first character uppercase, the remaining
> part lowercase
>   */
> String.prototype.toFirstUppercase = function() {
> return this.substr(0,1).toUpperCase()+this.substr(1).toLowerCase();
> }
>
>
> For the interested, among the few ones that read this post till the end, I
> also can contribute a fonction that parses an url and returns a table
> comparable to what PHP brings in the  HTTP_GET_VARS.
> I also have some functions (and help) to handle "global vars", i.e.
get/set
> for variables that can be used in a framed site, thus with different
documents.
> If there is some interest, mail me, as these kind of functions are not
> really useful for the DynAPI (I think, except maybe for server-side
> interactivity (sorry I haven'r read ALL the posts about it))
>
>
> _______________________________________________
> Dynapi-Dev mailing list
> [EMAIL PROTECTED]
> http://lists.sourceforge.net/lists/listinfo/dynapi-dev
>


_______________________________________________
Dynapi-Dev mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/dynapi-dev

Reply via email to