1
0
mirror of https://github.com/bitwarden/browser synced 2025-12-23 03:33:54 +00:00

Split jslib into multiple modules (#363)

* Split jslib into multiple modules
This commit is contained in:
Oscar Hinton
2021-06-03 18:58:57 +02:00
committed by GitHub
parent b1d9b84eae
commit 1016bbfb9e
509 changed files with 8838 additions and 1887 deletions

View File

@@ -0,0 +1,34 @@
import * as fs from 'fs';
import * as path from 'path';
import * as readline from 'readline';
export class NodeUtils {
static mkdirpSync(targetDir: string, mode = '700', relative = false, relativeDir: string = null) {
const initialDir = path.isAbsolute(targetDir) ? path.sep : '';
const baseDir = relative ? (relativeDir != null ? relativeDir : __dirname) : '.';
targetDir.split(path.sep).reduce((parentDir, childDir) => {
const dir = path.resolve(baseDir, parentDir, childDir);
if (!fs.existsSync(dir)) {
fs.mkdirSync(dir, mode);
}
return dir;
}, initialDir);
}
static readFirstLine(fileName: string) {
return new Promise<string>((resolve, reject) => {
const readStream = fs.createReadStream(fileName, {encoding: 'utf8'});
const readInterface = readline.createInterface(readStream);
readInterface
.on('line', line => {
readStream.close();
resolve(line);
})
.on('error', err => reject(err));
});
}
// https://stackoverflow.com/a/31394257
static bufferToArrayBuffer(buf: Buffer): ArrayBuffer {
return buf.buffer.slice(buf.byteOffset, buf.byteOffset + buf.byteLength);
}
}