<commit_before>import fs = require('fs');
import path = require('path');
import os = require('os');
import minimatch = require('minimatch');
import util = require('util');
import tcm = require('./taskcommand');
import vm = require('./vault');
import semver = require('semver');
import crypto = require('crypto');

/**
 * Hash table of known variable info. The formatted env var name is the lookup key.
 *
 * The purpose of this hash table is to keep track of known variables. The hash table
 * needs to be maintained for multiple reasons:
 *  1) to distinguish between env vars and job vars
 *  2) to distinguish between secret vars and public
 *  3) to know the real variable name and not just the formatted env var name.
 */
export var _knownVariableMap: { [key: string]: _KnownVariableInfo; } = {};

export var _vault: vm.Vault;

//-----------------------------------------------------
// Validation Checks
//-----------------------------------------------------

// async await needs generators in node 4.x+
if (semver.lt(process.versions.node, '4.2.0')) {
    this.warning('Tasks require a new agent.  Upgrade your agent or node to 4.2.0 or later');
}

//-----------------------------------------------------
// String convenience
//-----------------------------------------------------

export function _startsWith(str: string, start: string): boolean {
    return str.slice(0, start.length) == start;
}

export function _endsWith(str: string, end: string): boolean {
    return str.slice(-end.length) == end;
}

//-----------------------------------------------------
// General Helpers
//-----------------------------------------------------

let _outStream = process.stdout;
let _errStream = process.stderr;

export function _writeLine(str: string): void {
    _outStream.write(str + os.EOL);
}

export function _setStdStream(stdStream): void {
    _outStream = stdStream;
}

export function _setErrStream(errStream): void {
    _errStream = errStream;
}

//-----------------------------------------------------
// Loc Helpers
//-----------------------------------------------------

let _locStringCache: { [key: string]: string } = {};
//let _resourceFile: string;
let _resourceFiles: { [key: string]: string } = {};
let _libResourceFileLoaded: boolean = false;
let _resourceCulture: string = 'en-US';

function _loadResJson(resjsonFile: string): any {
    var resJson: {} = null;
    if (_exist(resjsonFile)) {
        var resjsonContent = fs.readFileSync(resjsonFile, 'utf8').toString();
        // remove BOM
        if (resjsonContent.indexOf('\uFEFF') == 0) {
            resjsonContent = resjsonContent.slice(1);
        }

        try {
            resJson = JSON.parse(resjsonContent);
        }
        catch (err) {
            _debug('unable to parse resjson with err: ' + err.message);
            resJson = null;
        }
    }
    else {
        _debug('.resjson file not found: ' + resjsonFile);
    }

    return resJson;
}

function _loadLocStrings(resourceFile: string, culture: string): { [key: string]: string; } {
    var locStrings: {<commit_msg>Remove commented code.<commit_after>import fs = require('fs');
import path = require('path');
import os = require('os');
import minimatch = require('minimatch');
import util = require('util');
import tcm = require('./taskcommand');
import vm = require('./vault');
import semver = require('semver');
import crypto = require('crypto');

/**
 * Hash table of known variable info. The formatted env var name is the lookup key.
 *
 * The purpose of this hash table is to keep track of known variables. The hash table
 * needs to be maintained for multiple reasons:
 *  1) to distinguish between env vars and job vars
 *  2) to distinguish between secret vars and public
 *  3) to know the real variable name and not just the formatted env var name.
 */
export var _knownVariableMap: { [key: string]: _KnownVariableInfo; } = {};

export var _vault: vm.Vault;

//-----------------------------------------------------
// Validation Checks
//-----------------------------------------------------

// async await needs generators in node 4.x+
if (semver.lt(process.versions.node, '4.2.0')) {
    this.warning('Tasks require a new agent.  Upgrade your agent or node to 4.2.0 or later');
}

//-----------------------------------------------------
// String convenience
//-----------------------------------------------------

export function _startsWith(str: string, start: string): boolean {
    return str.slice(0, start.length) == start;
}

export function _endsWith(str: string, end: string): boolean {
    return str.slice(-end.length) == end;
}

//-----------------------------------------------------
// General Helpers
//-----------------------------------------------------

let _outStream = process.stdout;
let _errStream = process.stderr;

export function _writeLine(str: string): void {
    _outStream.write(str + os.EOL);
}

export function _setStdStream(stdStream): void {
    _outStream = stdStream;
}

export function _setErrStream(errStream): void {
    _errStream = errStream;
}

//-----------------------------------------------------
// Loc Helpers
//-----------------------------------------------------

let _locStringCache: { [key: string]: string } = {};
let _resourceFiles: { [key: string]: string } = {};
let _libResourceFileLoaded: boolean = false;
let _resourceCulture: string = 'en-US';

function _loadResJson(resjsonFile: string): any {
    var resJson: {} = null;
    if (_exist(resjsonFile)) {
        var resjsonContent = fs.readFileSync(resjsonFile, 'utf8').toString();
        // remove BOM
        if (resjsonContent.indexOf('\uFEFF') == 0) {
            resjsonContent = resjsonContent.slice(1);
        }

        try {
            resJson = JSON.parse(resjsonContent);
        }
        catch (err) {
            _debug('unable to parse resjson with err: ' + err.message);
            resJson = null;
        }
    }
    else {
        _debug('.resjson file not found: ' + resjsonFile);
    }

    return resJson;
}

function _loadLocStrings(resourceFile: string, culture: string): { [key: string]: string; } {
    var locStrings: {
{'fraction_non_alphanumeric': 0.2487781036168133, 'fraction_numerical': 0.004561746497230368, 'mean_word_length': 1.9415428845232392, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3899698', 'n_tokens_mistral': 1616, 'n_tokens_neox': 1599, 'n_words': 515}