rename,
unlink,
writeFile,
- access
+ access,
+ stat,
+ Stats
} from 'fs'
import * as mkdirp from 'mkdirp'
import * as bcrypt from 'bcrypt'
return join.apply(null, paths)
}
+// Thanks: https://stackoverflow.com/a/12034334
+function escapeHTML (stringParam) {
+ const entityMap = {
+ '&': '&',
+ '<': '<',
+ '>': '>',
+ '"': '"',
+ "'": ''',
+ '/': '/',
+ '`': '`',
+ '=': '='
+ }
+
+ return String(stringParam).replace(/[&<>"'`=\/]/g, s => entityMap[s])
+}
+
function promisify0<A> (func: (cb: (err: any, result: A) => void) => void): () => Promise<A> {
return function promisified (): Promise<A> {
return new Promise<A>((resolve: (arg: A) => void, reject: (err: any) => void) => {
const bcryptHashPromise = promisify2<any, string|number, string>(bcrypt.hash)
const createTorrentPromise = promisify2<string, any, any>(createTorrent)
const rimrafPromise = promisify1WithVoid<string>(rimraf)
+const statPromise = promisify1<string, Stats>(stat)
// ---------------------------------------------------------------------------
export {
isTestInstance,
root,
+ escapeHTML,
promisify0,
promisify1,
bcryptGenSaltPromise,
bcryptHashPromise,
createTorrentPromise,
- rimrafPromise
+ rimrafPromise,
+ statPromise
}