<commit_before>var Utils = require('./utils');
var path = require('path');
var fs = require('fs');
var AsposeStorage = require('./aspose-storage');

function AsposePdf(config) {
	this.appSID = config.appSID;
	this.appKey = config.appKey;
	this.baseURI = config.baseURI;
	
	this.str_uri_folder = this.baseURI + 'storage/folder';
	this.str_uri_file = this.baseURI + 'storage/file';
	this.str_uri_exist = this.baseURI + 'storage/exist';
	this.str_uri_disc = this.baseURI + 'storage/disc';
}
<commit_msg>Updated Pdf Module<commit_after>var Utils = require('./utils');
var path = require('path');
var fs = require('fs');
var AsposeStorage = require('./aspose-storage');

function AsposePdf(config) {
	this.appSID = config.appSID;
	this.appKey = config.appKey;
	this.baseURI = config.baseURI;
	
	this.str_uri_folder = this.baseURI + 'storage/folder';
	this.str_uri_file = this.baseURI + 'storage/file';
	this.str_uri_exist = this.baseURI + 'storage/exist';
	this.str_uri_disc = this.baseURI + 'storage/disc';
}

/* Text Editing Methods */

AsposePdf.prototype.replaceText = function(fileName,oldText,newText,regularExpression,pageNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	oldText = typeof oldText !== 'undefined' ? oldText : '';
	newText = typeof newText !== 'undefined' ? newText : '';
	regularExpression = typeof regularExpression !== 'undefined' ? regularExpression : false;
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	if(oldText === 0){
		throw new Error('search text not defined.');
	}
	
	if(newText === 0){
		throw new Error('replace text not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName;
	
	if(pageNumber > 0){
		strURI = strURI + '/pages/' + pageNumber + '/replaceText';
	} else {
		strURI = strURI + '/replaceText';
	}
	
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	var json_data = {'OldValue':oldText,'NewValue':newText,'Regex':regularExpression};
	
	var appSID = this.appSID;
	var appKey = this.appKey;
	var baseURI = this.baseURI;
	
	Utils.ProcessCommand('POST',signedURI,json_data,function(data){
		var asposeStorage = new AsposeStorage({'appSID':appSID,'appKey':appKey,'baseURI':baseURI});
		if(data.Status === 'OK'){
			asposeStorage.getFile(fileName, '', function(data){
				
				if(typeof callback === 'function'){
					callback.call(null,data);
				}
			});
		} else {
			throw new Error(data.Message);
		}
	});
};

AsposePdf.prototype.getTextFormat = function(fileName,pageNumber,fragmentNumber,segmentNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	fragmentNumber = typeof fragmentNumber !== 'undefined' ? fragmentNumber : 0;
	segmentNumber = typeof segmentNumber !== 'undefined' ? segmentNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	if(pageNumber === 0){
		throw new Error('page number not defined.');
	}
	
	if(fragmentNumber === 0){
		throw new Error('fragment number not defined.');
	}
	
	if(segmentNumber === 0){
		throw new Error('segment number not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/fragments/' + fragmentNumber + '/segments/' + segmentNumber + '/textformat';
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	Utils.ProcessCommand('GET',signedURI,'',function(data){
		if(typeof callback === 'function'){
			if(data.Status === 'OK'){
				callback.call(null,data.TextFormat);
			} else {
				throw new Error(data.Status);
			}
		}
	});
};

AsposePdf.prototype.getSegmentCount = function(fileName,pageNumber,fragmentNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	fragmentNumber = typeof fragmentNumber !== 'undefined' ? fragmentNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	if(pageNumber === 0){
		throw new Error('page number not defined.');
	}
	
	if(fragmentNumber === 0){
		throw new Error('fragment number not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/fragments/' + fragmentNumber;
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	Utils.ProcessCommand('GET',signedURI,'',function(data){
		if(typeof callback === 'function'){
			if(data.Status === 'OK'){
				callback.call(null,data.TextItems.List.length);
			} else {
				throw new Error(data.Status);
			}
		}
	});
};

AsposePdf.prototype.getFragmentCount = function(fileName,pageNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	if(pageNumber === 0){
		throw new Error('page number not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName + '/pages/' + pageNumber + '/fragments';
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	Utils.ProcessCommand('GET',signedURI,'',function(data){
		if(typeof callback === 'function'){
			if(data.Status === 'OK'){
				callback.call(null,data.TextItems.List.length);
			} else {
				throw new Error(data.Status);
			}
		}
	});
};

AsposePdf.prototype.getTextItems = function(fileName,pageNumber,fragmentNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	fragmentNumber = typeof fragmentNumber !== 'undefined' ? fragmentNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName + '/pages';
	if(pageNumber > 0){
		if(fragmentNumber > 0){
			strURI = strURI + '/' + pageNumber + '/fragments/' + fragmentNumber;
		} else {
			strURI = strURI + '/' + pageNumber;
		}
	}
	strURI = strURI + '/TextItems';
	
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	Utils.ProcessCommand('GET',signedURI,'',function(data){
		if(typeof callback === 'function'){
			if(data.Status === 'OK'){
				var rawText = '';
				data.TextItems.List.forEach(function(item,index){
					rawText = rawText + item.Text;
				});
				
				callback.call(null,rawText);
			} else {
				throw new Error(data.Status);
			}
		}
	});
};

AsposePdf.prototype.getText = function(fileName,pageNumber,callback){
	
	fileName = typeof fileName !== 'undefined' ? fileName : '';
	pageNumber = typeof pageNumber !== 'undefined' ? pageNumber : 0;
	
	if(fileName === ''){
		throw new Error('Filename not defined.');
	}
	
	var strURI = this.baseURI + 'pdf/' + fileName + '/pages';
	if(pageNumber > 0){
		strURI = strURI + '/' + pageNumber + '/TextItems';
	} else {
		strURI = strURI + '/TextItems';
	}
	var signedURI = Utils.Sign(strURI,this.appSID,this.appKey);
	
	Utils.ProcessCommand('GET',signedURI,'',function(data){
		if(typeof callback === 'function'){
			if(data.Status === 'OK'){
				var rawText = '';
				data.TextItems.List.forEach(function(item,index){
					rawText = rawText + item.Text;
				});
				
				callback.call(null,rawText);
			} else {
				throw new Error(data.Status);
			}
		}
	});
};

{'fraction_non_alphanumeric': 0.16832366749516708, 'fraction_numerical': 0.0030378348522507597, 'mean_word_length': 4.24475018102824, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1953076', 'n_tokens_mistral': 2557, 'n_tokens_neox': 2330, 'n_words': 484}