JSDOC/Packer.js
[app.jsdoc] / File.js
diff --git a/File.js b/File.js
index 549ca94..f7ae90c 100755 (executable)
--- a/File.js
+++ b/File.js
@@ -20,15 +20,22 @@ String  = imports.String.String;
 */
 var File = {
     
+    /**
+     * @static
+     * @type {String} File seperator. (should be dynamic....)
+     */
+     
+    
     SEPARATOR : '/',
 
  // fixme - this needs a bitter location.. 
     // they where in a string class before, but  overriding String methods is not a good normally a good idea..
-    
+      
     /**
-     * rtrim:
+     * Right trim (in here to reduce dependancies)
      * @param {String} s the string to trim
      * @param {String} string to trim off right..
+     * @return {String} the trimmed string
      */
     rtrim : function (s,toTrim) {
         if (s.substr(s.length - toTrim.length) == toTrim) {
@@ -37,12 +44,23 @@ var File = {
    
         return s;
     },
+    /**
+     * Trim a string (in here to reduce dependancies)
+     * @param {String} s the string to trim
+     * @param {String} string to trim off right..
+     * @return {String} the trimmed string
+     */
     trim : function (s,toTrim) {
         var out = this.ltrim(s,toTrim);
         out = this.rtrim(out,toTrim);
         return out;
     },
-    
+    /**
+     * Left Trim a string (in here to reduce dependancies)
+     * @param {String} s the string to trim
+     * @param {String} string to trim off right..
+     * @return {String} the trimmed string
+     */
     ltrim : function (s, toTrim) {
         if (s.substr(0, toTrim.length) == toTrim) {
             return s.slice(toTrim.length);
@@ -50,7 +68,34 @@ var File = {
         
         return s;
     },
+    /**
+     * Get the base name of a path.
+     * @param {String} path
+     * @returns {String} basename
+    */
+    basename : function(path)
+    {
+        return path.split(File.SEPARATOR).pop();
+    },
+    
+    /**
+     * Get the directory name of a path. (could use Glib really)
+     * @param {String} path
+     * @returns {String} dirname
+    */
+    dirname : function(path)
+    {
+       var r = path.split(File.SEPARATOR)
+       r.pop();
+       return r.join(File.SEPARATOR);
+    },
+    
     
+    /**
+     * Join a path with the Correct File seperator (unix only at present...)
+     * Takes a variable number of arguments, and joins them together.
+     * @return {String} the joined path
+     */
     join : function () {
         var out = "";
         for (var i = 0; i < arguments.length; i++) {
@@ -65,23 +110,46 @@ var File = {
             }
         }
         return out;
-    }, 
+    },
+    /**
+     * Read a file and return as string
+     * @param {String} path The file location
+     * @return {String} the joined path
+     */
     read : function (path) {
         var out = {};
         GLib.file_get_contents(path, out, null, null);
         return out['value'];
     },
-
+    /**
+     * Check if a path points to a file.
+     * @param {String} path The location
+     * @return {Boolean} true if it's a file
+     */
     isFile : function (path) {
       return GLib.file_test(path, GLib.FileTest.IS_REGULAR);
     },
+    /**
+     * Check if a path points to a file, directory or link..
+     * @param {String} path The location
+     * @return {Boolean} true if it exists
+     */
     exists : function (path) {
       return GLib.file_test(path, GLib.FileTest.EXISTS);
     },
+    /**
+     * Check if a path points to a directory.
+     * @param {String} path The location
+     * @return {Boolean} true if it's a directory
+     */
     isDirectory : function (path) {
       return GLib.file_test(path, GLib.FileTest.IS_DIR);
     },
-
+    /**
+     * list files in a directory.
+     * @param {String} path The directory
+     * @return {Array} list of files (with full path?)
+     */
     list : function (path) {
         var listing = [];
 
@@ -100,7 +168,11 @@ var File = {
 
         return listing;
     },
-
+    /**
+     * Get the last modification time of a file
+     * @param {String} path The location
+     * @return {Date} when the file was last modified
+     */
     mtime : function (path) {
         var f = Gio.file_new_for_path(String(path));
         var mtime = new GLib.TimeVal();
@@ -110,7 +182,11 @@ var File = {
 
         return new Date(mtime.tv_sec * 1000);
     },
-
+    /**
+     * Resovle the absolute path of a file
+     * @param {String} path The location (relative) to current working directory?
+     * @return {String} the full path
+     */
     canonical : function (path) {
         var f = Gio.file_new_for_path(String(path));
         var can = f.resolve_relative_path('');
@@ -118,9 +194,9 @@ var File = {
     },
     
     /**
-     * write
-     * @arg path {String} File to write to
-     * @arg string {String} Contents of file.
+     * write a string to file
+     * @param {String} pathFile to write to
+     * @param {String} string  Contents of file.
      * 
      */
     write : function (path, string) {
@@ -130,9 +206,9 @@ var File = {
         data_out.close(null);
     },
     /**
-     * append
-     * @arg path {String} File to write to
-     * @arg string {String} string to append to file.
+     * append a string to a file
+     * @param {String} path  File to write to
+     * @param {String}  string string to append to file.
      * 
      */
     append : function (path, string) {
@@ -144,11 +220,8 @@ var File = {
         data_out.close(null);
     },
     /**
-     * remove 
      * Delete a file.
-     * @arg path {String} File to remove
-     * 
-     * 
+     * @param  {String} path  File to remove    
      */
     remove : function (path)
     {
@@ -156,12 +229,11 @@ var File = {
         return f['delete']();
     },
     /**
-     * silentRecursiveCopy
      * copy files recursively from fromDir, silently ignore them if they already exist in toDir
      *        unless you select overwrite..
-     * @arg {String} src source path
-     * @arg {String} dest destination path
-     * @arg {Gio.FileCopyFlags} options (optional)  - use Gio.FileCopyFlags.OVERWRITE to 
+     * @param {String} src source path
+     * @param {String} dest destination path
+     * @param {Gio.FileCopyFlags} options (optional)  - use Gio.FileCopyFlags.OVERWRITE to 
      *      otherwise they will not be copied
      * 
      */
@@ -196,9 +268,8 @@ var File = {
     },
     
     /**
-     * mkdir
      * make a directory..
-     * @arg {String} dstPath directory to make
+     * @param {String} dstPath directory to make
      */
     mkdir : function (destPath) {
         var dest = Gio.file_new_for_path(String(destPath));
@@ -206,10 +277,10 @@ var File = {
         return dest.make_directory(null, null);
     },
     /**
-     * copyFile
-     * @arg {String} src source path
-     * @arg {String} dest destination path
-     * @arg {Gio.FileCopyFlags} options (optional)  - use Gio.FileCopyFlags.OVERWRITE to .. overwrite..
+     * copy a File
+     * @param {String} src source path
+     * @param {String} dest destination path
+     * @param {Gio.FileCopyFlags} options (optional)  - use Gio.FileCopyFlags.OVERWRITE to .. overwrite..
      * 
      */
     copyFile : function (srcPath, destPath, opts) {
@@ -223,30 +294,34 @@ var File = {
         // can be nulled, but not according to the GIR file
         return src.copy(dest, opts);
     },
-
+    /**
+     * recursively list files in a directory.
+     * @param {String} path The directory
+     * @return {Array} list of files (with full path?)
+     */
     recursiveListing : function (dir) {
 
         function recursiveListingInternal(prefix, listing, dir) {
-          var entries = File.list(dir);
-          var next, fullPath;
-
-          for (var index in entries) {
-            next = entries[index];
-            fullPath = File.join(prefix, dir, next);
-
-            if (File.isDirectory(fullPath)) {
-              listing.push(next);
-              listing = listing.concat(recursiveListingInternal(next, [], fullPath));
-            }
-            else {
-              if (prefix) {
-                next = File.join(prefix, next);
+            var entries = File.list(dir);
+            var next, fullPath;
+  
+            for (var index in entries) {
+              next = entries[index];
+              fullPath = File.join(prefix, dir, next);
+  
+              if (File.isDirectory(fullPath)) {
+                listing.push(next);
+                listing = listing.concat(recursiveListingInternal(next, [], fullPath));
+              }
+              else {
+                if (prefix) {
+                  next = File.join(prefix, next);
+                }
+                listing.push(next);
               }
-              listing.push(next);
             }
-          }
-
-          return listing;
+  
+            return listing;
         }
 
         return recursiveListingInternal('', [], dir);