puvox-library 1.0.33 → 1.0.35
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/library_standard.js +82 -1
 - package/package.json +1 -1
 
    
        package/library_standard.js
    CHANGED
    
    | 
         @@ -1008,11 +1008,12 @@ const puvox_library = 
     | 
|
| 
       1008 
1008 
     | 
    
         
             
            			return result;
         
     | 
| 
       1009 
1009 
     | 
    
         
             
            		},
         
     | 
| 
       1010 
1010 
     | 
    
         
             
            		daysBetween(a, b, utc = true){
         
     | 
| 
      
 1011 
     | 
    
         
            +
            			// https://stackoverflow.com/a/15289883/2377343
         
     | 
| 
       1011 
1012 
     | 
    
         
             
            			const _MS_PER_DAY = 1000 * 60 * 60 * 24;
         
     | 
| 
       1012 
1013 
     | 
    
         
             
            			let d1, d2;
         
     | 
| 
       1013 
1014 
     | 
    
         
             
            			// Discard the time and time-zone information.
         
     | 
| 
       1014 
1015 
     | 
    
         
             
            			if (utc) {
         
     | 
| 
       1015 
     | 
    
         
            -
            				d1 = Date.UTC(a. 
     | 
| 
      
 1016 
     | 
    
         
            +
            				d1 = Date.UTC(a.getUTCFullYear(), a.getUTCMonth(), a.getUTCDate());
         
     | 
| 
       1016 
1017 
     | 
    
         
             
            				d2 = Date.UTC(b.getUTCFullYear(), b.getUTCMonth(), b.getUTCDate());
         
     | 
| 
       1017 
1018 
     | 
    
         
             
            			} else {
         
     | 
| 
       1018 
1019 
     | 
    
         
             
            				d1 = Date.UTC(a.getFullYear(), a.getMonth(), a.getDate());
         
     | 
| 
         @@ -1067,6 +1068,86 @@ const puvox_library = 
     | 
|
| 
       1067 
1068 
     | 
    
         
             
            	},
         
     | 
| 
       1068 
1069 
     | 
    
         | 
| 
       1069 
1070 
     | 
    
         | 
| 
      
 1071 
     | 
    
         
            +
            	// https://stackoverflow.com/a/7924240/2377343 (has better performance than (ch.match(/\n/g) || []).length  or ch.split('\n').length - 1 )
         
     | 
| 
      
 1072 
     | 
    
         
            +
            	occurences_amount(string, subString, allowOverlapping) {
         
     | 
| 
      
 1073 
     | 
    
         
            +
            		string += "";
         
     | 
| 
      
 1074 
     | 
    
         
            +
            		subString += "";
         
     | 
| 
      
 1075 
     | 
    
         
            +
            		if (subString.length <= 0) return (string.length + 1);
         
     | 
| 
      
 1076 
     | 
    
         
            +
            		var n = 0, pos = 0, step = allowOverlapping ? 1 : subString.length;
         
     | 
| 
      
 1077 
     | 
    
         
            +
            		while (true) {
         
     | 
| 
      
 1078 
     | 
    
         
            +
            			pos = string.indexOf(subString, pos);
         
     | 
| 
      
 1079 
     | 
    
         
            +
            			if (pos >= 0) { ++n; pos += step; } else break;
         
     | 
| 
      
 1080 
     | 
    
         
            +
            		}
         
     | 
| 
      
 1081 
     | 
    
         
            +
            		return n;
         
     | 
| 
      
 1082 
     | 
    
         
            +
            	},
         
     | 
| 
      
 1083 
     | 
    
         
            +
            	
         
     | 
| 
      
 1084 
     | 
    
         
            +
            	// startReadStream(__dirname + '/aa.csv', ()=>{});
         
     | 
| 
      
 1085 
     | 
    
         
            +
            	async readLineByLine (filePath, callback, linesSize = 10000, delimiterN = true) {
         
     | 
| 
      
 1086 
     | 
    
         
            +
            		// https://stackoverflow.com/questions/6156501/read-a-file-one-line-at-a-time-in-node-js
         
     | 
| 
      
 1087 
     | 
    
         
            +
            		// https://stackoverflow.com/questions/31479379/nodejs-read-very-large-file10gb-process-line-by-line-then-write-to-other-fil
         
     | 
| 
      
 1088 
     | 
    
         
            +
            		// https://stackoverflow.com/questions/7545147/nodejs-synchronization-read-large-file-line-by-line
         
     | 
| 
      
 1089 
     | 
    
         
            +
            		// https://stackoverflow.com/questions/16010915/parsing-huge-logfiles-in-node-js-read-in-line-by-line
         
     | 
| 
      
 1090 
     | 
    
         
            +
            		// calblack format: callback(linesArray, isLastChunk)
         
     | 
| 
      
 1091 
     | 
    
         
            +
            		let resolver = null;
         
     | 
| 
      
 1092 
     | 
    
         
            +
            		let rejector = null;
         
     | 
| 
      
 1093 
     | 
    
         
            +
            		const prom = new Promise((resolve, reject) => {
         
     | 
| 
      
 1094 
     | 
    
         
            +
            			resolver = resolve;
         
     | 
| 
      
 1095 
     | 
    
         
            +
            			rejector = reject;
         
     | 
| 
      
 1096 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1097 
     | 
    
         
            +
            		let buffer = '';
         
     | 
| 
      
 1098 
     | 
    
         
            +
            		const readStream = fs.createReadStream(filePath);
         
     | 
| 
      
 1099 
     | 
    
         
            +
            		let collectedLines = [];
         
     | 
| 
      
 1100 
     | 
    
         
            +
            		readStream.on('data', async function(chunk) {
         
     | 
| 
      
 1101 
     | 
    
         
            +
            			var lines = (buffer + chunk).split(/\n/g);
         
     | 
| 
      
 1102 
     | 
    
         
            +
            			buffer = lines.pop();
         
     | 
| 
      
 1103 
     | 
    
         
            +
            			collectedLines = collectedLines.concat(lines);
         
     | 
| 
      
 1104 
     | 
    
         
            +
            			const length = collectedLines.length;
         
     | 
| 
      
 1105 
     | 
    
         
            +
            			if (length > linesSize) {
         
     | 
| 
      
 1106 
     | 
    
         
            +
            				const remnant = collectedLines.splice(linesSize);
         
     | 
| 
      
 1107 
     | 
    
         
            +
            				await callback(collectedLines, false);
         
     | 
| 
      
 1108 
     | 
    
         
            +
            				collectedLines = remnant;
         
     | 
| 
      
 1109 
     | 
    
         
            +
            			}
         
     | 
| 
      
 1110 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1111 
     | 
    
         
            +
            		readStream.on('end', async function() {
         
     | 
| 
      
 1112 
     | 
    
         
            +
            			collectedLines = collectedLines.concat([buffer]);
         
     | 
| 
      
 1113 
     | 
    
         
            +
            			await callback(collectedLines, true);
         
     | 
| 
      
 1114 
     | 
    
         
            +
            			resolver();
         
     | 
| 
      
 1115 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1116 
     | 
    
         
            +
            		readStream.on('error', function() {
         
     | 
| 
      
 1117 
     | 
    
         
            +
            			rejector();
         
     | 
| 
      
 1118 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1119 
     | 
    
         
            +
            		return prom;
         
     | 
| 
      
 1120 
     | 
    
         
            +
            	},
         
     | 
| 
      
 1121 
     | 
    
         
            +
            	async linesAmountInFile(filePath, delimiterN = true) {
         
     | 
| 
      
 1122 
     | 
    
         
            +
            		const self = this;
         
     | 
| 
      
 1123 
     | 
    
         
            +
            		// calblack format: callback(linesArray, isLastChunk)
         
     | 
| 
      
 1124 
     | 
    
         
            +
            		let resolver = null;
         
     | 
| 
      
 1125 
     | 
    
         
            +
            		let rejector = null;
         
     | 
| 
      
 1126 
     | 
    
         
            +
            		const prom = new Promise((resolve, reject) => {
         
     | 
| 
      
 1127 
     | 
    
         
            +
            			resolver = resolve;
         
     | 
| 
      
 1128 
     | 
    
         
            +
            			rejector = reject;
         
     | 
| 
      
 1129 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1130 
     | 
    
         
            +
            		let buffer = '';
         
     | 
| 
      
 1131 
     | 
    
         
            +
            		const readStream = fs.createReadStream(filePath);
         
     | 
| 
      
 1132 
     | 
    
         
            +
            		let linesAmount = 0;
         
     | 
| 
      
 1133 
     | 
    
         
            +
            		readStream.on('data', async function(chunk) {
         
     | 
| 
      
 1134 
     | 
    
         
            +
            			const ch = chunk + '';
         
     | 
| 
      
 1135 
     | 
    
         
            +
            			const curLenth = self.helpers.occurences_amount(ch, '\n');
         
     | 
| 
      
 1136 
     | 
    
         
            +
            			linesAmount = linesAmount + curLenth;
         
     | 
| 
      
 1137 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1138 
     | 
    
         
            +
            		readStream.on('end', async function() {
         
     | 
| 
      
 1139 
     | 
    
         
            +
            			resolver(linesAmount);
         
     | 
| 
      
 1140 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1141 
     | 
    
         
            +
            		readStream.on('error', function() {
         
     | 
| 
      
 1142 
     | 
    
         
            +
            			rejector();
         
     | 
| 
      
 1143 
     | 
    
         
            +
            		});
         
     | 
| 
      
 1144 
     | 
    
         
            +
            		return prom;
         
     | 
| 
      
 1145 
     | 
    
         
            +
            	},
         
     | 
| 
      
 1146 
     | 
    
         
            +
             
     | 
| 
      
 1147 
     | 
    
         
            +
             
     | 
| 
      
 1148 
     | 
    
         
            +
             
     | 
| 
      
 1149 
     | 
    
         
            +
             
     | 
| 
      
 1150 
     | 
    
         
            +
             
     | 
| 
       1070 
1151 
     | 
    
         
             
            	oneSpace(cc){
         
     | 
| 
       1071 
1152 
     | 
    
         
             
            		return cc.replace(/\s\s+/g, ' ');
         
     | 
| 
       1072 
1153 
     | 
    
         
             
            	},
         
     |