index.js
function randstr(options) {
    var opt = _validateOptions(options);
    var from, to;
    if (Array.isArray(opt.length)) {
        _a = opt.length, from = _a[0], to = _a[1];
    }
    else {
        from = to = opt.length;
    }
    var str = '';
    if (0 === to) {
        return str;
    }
    var charsIsString = 'string' === typeof opt.chars;
    var charsLastIndex = charsIsString ? opt.chars.length - 1 : 0;
    var includeControlChars = true === opt.includeControlChars;
    var hasAcceptableFunc = 'function' === typeof opt.acceptable;
    var hasReplacer = 'function' === typeof opt.replacer;
    var max = _randomIntBetween(opt.random, from, to);
    // console.log( 'max', max, 'from', from, 'to', to );
    for (var i = 0, len = 0, charCode = void 0, chr = void 0; i < max && len < max; ++i) {
        if (charsIsString) {
            var index = _randomIntBetween(opt.random, 0, charsLastIndex);
            charCode = opt.chars.charCodeAt(index);
        }
        else {
            charCode = _randomIntBetween(opt.random, opt.chars[0], opt.chars[1]);
        }
        // Non printable?
        if (!includeControlChars && _isControlChar(charCode)) {
            // console.log( 'NOT PRINTABLE!');
            --i; // back to try again
            continue;
        }
        chr = String.fromCharCode(charCode);
        // console.log( 'charCode', charCode, 'char', chr );
        if (hasAcceptableFunc && !opt.acceptable.call(null, chr)) {
            --i; // back to try again
            continue;
        }
        if (hasReplacer) {
            chr = opt.replacer.call(null, chr);
            // console.log( 'char after', chr );
            // Their combined length pass the limit?
            if ((len + chr.length) > max) {
                // console.log( 'greater than max!', 'i', i, 'max', max, 'str', len, 'chr', chr.length );
                --i; // back to try again
                continue;
            }
        }
        str += chr;
        len = str.length;
    }
    return str;
    var _a;
}
function randstr(options) {
    var opt = _validateOptions(options);
    var from, to;
    if (Array.isArray(opt.length)) {
        _a = opt.length, from = _a[0], to = _a[1];
    }
    else {
        from = to = opt.length;
    }
    var str = '';
    if (0 === to) {
        return str;
    }
    var charsIsString = 'string' === typeof opt.chars;
    var charsLastIndex = charsIsString ? opt.chars.length - 1 : 0;
    var includeControlChars = true === opt.includeControlChars;
    var hasAcceptableFunc = 'function' === typeof opt.acceptable;
    var hasReplacer = 'function' === typeof opt.replacer;
    var max = _randomIntBetween(opt.random, from, to);
    // console.log( 'max', max, 'from', from, 'to', to );
    for (var i = 0, len = 0, charCode = void 0, chr = void 0; i < max && len < max; ++i) {
        if (charsIsString) {
            var index = _randomIntBetween(opt.random, 0, charsLastIndex);
            charCode = opt.chars.charCodeAt(index);
        }
        else {
            charCode = _randomIntBetween(opt.random, opt.chars[0], opt.chars[1]);
        }
        // Non printable?
        if (!includeControlChars && _isControlChar(charCode)) {
            // console.log( 'NOT PRINTABLE!');
            --i; // back to try again
            continue;
        }
        chr = String.fromCharCode(charCode);
        // console.log( 'charCode', charCode, 'char', chr );
        if (hasAcceptableFunc && !opt.acceptable.call(null, chr)) {
            --i; // back to try again
            continue;
        }
        if (hasReplacer) {
            chr = opt.replacer.call(null, chr);
            // console.log( 'char after', chr );
            // Their combined length pass the limit?
            if ((len + chr.length) > max) {
                // console.log( 'greater than max!', 'i', i, 'max', max, 'str', len, 'chr', chr.length );
                --i; // back to try again
                continue;
            }
        }
        str += chr;
        len = str.length;
    }
    return str;
    var _a;
}
function randstr ( options ) { var opt = _validateOptions ( options ) ; var from , to ; if ( Array . isArray ( opt . length ) ) { _a = opt . length , from = _a [ 0 ] , to = _a [ 1 ] ; } else { from = to = opt . length ; } var str = '' ; if ( 0 === to ) { return str ; } var charsIsString = 'string' === typeof opt . chars ; var charsLastIndex = charsIsString ? opt . chars . length - 1 : 0 ; var includeControlChars = true === opt . includeControlChars ; var hasAcceptableFunc = 'function' === typeof opt . acceptable ; var hasReplacer = 'function' === typeof opt . replacer ; var max = _randomIntBetween ( opt . random , from , to ) ; // console.log( 'max', max, 'from', from, 'to', to ); for ( var i = 0 , len = 0 , charCode = void 0 , chr = void 0 ; i < max && len < max ; ++ i ) { if ( charsIsString ) { var index = _randomIntBetween ( opt . random , 0 , charsLastIndex ) ; charCode = opt . chars . charCodeAt ( index ) ; } else { charCode = _randomIntBetween ( opt . random , opt . chars [ 0 ] , opt . chars [ 1 ] ) ; } // Non printable? if ( ! includeControlChars && _isControlChar ( charCode ) ) { // console.log( 'NOT PRINTABLE!'); -- i ; // back to try again continue ; } chr = String . fromCharCode ( charCode ) ; // console.log( 'charCode', charCode, 'char', chr ); if ( hasAcceptableFunc && ! opt . acceptable . call ( null , chr ) ) { -- i ; // back to try again continue ; } if ( hasReplacer ) { chr = opt . replacer . call ( null , chr ) ; // console.log( 'char after', chr ); // Their combined length pass the limit? if ( ( len + chr . length ) > max ) { // console.log( 'greater than max!', 'i', i, 'max', max, 'str', len, 'chr', chr.length ); -- i ; // back to try again continue ; } } str += chr ; len = str . length ; } return str ; var _a ; }
Generates a random string according to the given options.

@param options Options
@returns a string
Generates a random string according to the given options .