aboutsummaryrefslogtreecommitdiff
path: root/generator/util.js
blob: 85e7ab37fa7e81f2988f0539ff56390d091c8022 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
//Copyright Chris Xiong 2019
//License: Expat (MIT)
module.exports={
	mtime_cmp: function(a, b){ return _mtime_cmp(a, b); },
	htmlescape: function(s){ return _htmlescape(s); }
};
const fs=require('fs');

/*Returns true when file b exists and has a mtime no earlier than file a,
 *false otherwise.
 */
function _mtime_cmp(a,b)
{
	const mtimea=fs.statSync(a).mtimeMs;
	let mtimeb=0;
	try{
		mtimeb=fs.statSync(b).mtimeMs;
	}catch(e){return false};
	return mtimeb>=mtimea;
}
function _htmlescape(s)
{
	return s.replace(/</g, "&lt;")
		.replace(/>/g, "&gt;")
		.replace(/&/g, "&amp;")
		.replace(/"/g, "&quot;")
		.replace(/'/g, "&#39;");
}