appcenter-cli
Version:
Command line tool for Visual Studio App Center
64 lines (63 loc) • 2.02 kB
JavaScript
;
//
// Parser for the output of the creds.exe helper program.
//
Object.defineProperty(exports, "__esModule", { value: true });
exports.createParsingStream = void 0;
const Pumpify = require("pumpify");
const split = require("split2");
const stream_1 = require("stream");
//
// Regular expression to match the various fields in the input.
//
const fieldRe = /^([^:]+):\s(.*)$/;
//
// Convert space separated pascal caps ("Target Type")
// to camel case no spaces ("targetType"). Used to Convert
// field names to property names.
//
function fieldNameToPropertyName(fieldName) {
const parts = fieldName.split(" ");
parts[0] = parts[0].toLowerCase();
return parts.join("");
}
//
// Simple streaming parser, splits lines, collects them into single objects.
//
class WinCredStoreParsingStream extends stream_1.Transform {
constructor() {
super({ objectMode: true });
this.currentEntry = null;
}
_transform(chunk, encoding, callback) {
const line = chunk.toString();
if (line === "") {
if (this.currentEntry) {
this.push(this.currentEntry);
this.currentEntry = null;
}
return callback();
}
this.currentEntry = this.currentEntry || {};
const match = fieldRe.exec(line);
const key = fieldNameToPropertyName(match[1]);
const value = match[2];
this.currentEntry[key] = value;
return callback();
}
_flush(callback) {
if (this.currentEntry) {
this.push(this.currentEntry);
this.currentEntry = null;
}
callback();
}
}
function createParsingStream() {
return new Pumpify.obj(split(), new WinCredStoreParsingStream());
}
exports.createParsingStream = createParsingStream;
(function (createParsingStream) {
createParsingStream.ParsingStream = WinCredStoreParsingStream;
})(createParsingStream || (createParsingStream = {}));
exports.createParsingStream = createParsingStream;