123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- var libpath = require( 'path' ),
- fs = require( 'fs' );
-
- var ValidIDChars = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
- function IsInstanceID( potentialInstanceID ) {
- if ( potentialInstanceID.match(/^[0-9A-Za-z]{16}$/) ) {
- return true;
- }
- return false;
- }
- function GenerateInstanceID( ) {
- var text = "";
-
- for( var i=0; i < 16; i++ )
- text += ValidIDChars.charAt( Math.floor( Math.random( ) * ValidIDChars.length ) );
- return text;
- }
- function JoinPath( /* arguments */ ) {
- var result = "";
- if ( arguments.length > 0 ) {
- if ( arguments[ 0 ] ) {
- result = arguments[ 0 ];
- }
- for ( var index = 1; index < arguments.length; index++ ) {
- var newSegment = arguments[ index ];
- if ( newSegment == undefined ) {
- newSegment = "";
- }
- if ( ( newSegment[ 0 ] == "/" ) && ( result[ result.length - 1 ] == "/" ) ) {
- result = result + newSegment.slice( 1 );
- } else if ( ( newSegment[ 0 ] == "/" ) || ( result[ result.length - 1 ] == "/" ) ) {
- result = result + newSegment;
- } else {
- result = result + "/" + newSegment;
- }
-
- }
- }
- return result;
- }
- function IsDirectory( path ) {
- var seperatorFixedPath = path.replace( /\//g, libpath.sep );
- if ( ! fs.existsSync( seperatorFixedPath ) ) {
- return false;
- }
- return fs.statSync( seperatorFixedPath ).isDirectory();
- }
- function IsFile( path ) {
- var seperatorFixedPath = path.replace( /\//g, libpath.sep );
- if ( ! fs.existsSync( seperatorFixedPath ) ) {
- return false;
- }
- return fs.statSync( seperatorFixedPath ).isFile();
- }
- function GenerateSegments( argument ) {
- var result = argument.split("/");
- if ( result.length > 0 ) {
- if ( result[ 0 ] == "" ) {
- result.shift();
- }
- }
- if ( result.length > 0 ) {
- if ( result[ result.length - 1 ] == "" ) {
- result.pop();
- }
- }
- return result;
- }
- exports.JoinPath = JoinPath;
- exports.IsDirectory = IsDirectory;
- exports.IsFile = IsFile;
- exports.IsInstanceID = IsInstanceID;
- exports.GenerateSegments = GenerateSegments;
- exports.GenerateInstanceID = GenerateInstanceID;
|