index.js
function generate (opts) {
    var options = opts || {},
        genCount = Math.abs(options.count) >>> 0,
        // min/max word count in a sentence
        minCount = Math.abs(options.minCount) || 5,
        maxCount = Math.abs(options.maxCount) || 20,
        formater = options.format == '\\uXXXX' ? formatOutput : undefined,
        periods = extendPeriod(options.toleratedPeriods || '');

    var avail = 0;
    var genHelper = function (genFn) {
            return formater === undefined ? genFn : function () {
                return formatOutput(genFn.apply(undefined, arguments));
            };
        },
        genWords = genHelper(options.freq === true ? freqUsedWordsGen : wordsGen),
        wordCountFn = function () {
            var count = rand(minCount, maxCount);
            return count >= avail ? avail - 1 : count;
        },
        genPeriod = genHelper(function () {
            return periods[rand(0, periods.length)];
        }),
        genSentences = function (genEachSentenceFn) {
            var gen = {
                text: '',
                total: 0,
                sentenceCount: 0
            };

            while ((avail = genCount - gen.total) > 0) {
                gen.total += genEachSentenceFn(gen);
                gen.sentenceCount++;
            }

            return gen;
        };

    return genSentences(function (gen) {
        var currentWordCount = wordCountFn();

        gen.text += genWords(currentWordCount);
        gen.text += genPeriod();

        return currentWordCount + 1;
    });
}
function generate (opts) {
    var options = opts || {},
        genCount = Math.abs(options.count) >>> 0,
        // min/max word count in a sentence
        minCount = Math.abs(options.minCount) || 5,
        maxCount = Math.abs(options.maxCount) || 20,
        formater = options.format == '\\uXXXX' ? formatOutput : undefined,
        periods = extendPeriod(options.toleratedPeriods || '');

    var avail = 0;
    var genHelper = function (genFn) {
            return formater === undefined ? genFn : function () {
                return formatOutput(genFn.apply(undefined, arguments));
            };
        },
        genWords = genHelper(options.freq === true ? freqUsedWordsGen : wordsGen),
        wordCountFn = function () {
            var count = rand(minCount, maxCount);
            return count >= avail ? avail - 1 : count;
        },
        genPeriod = genHelper(function () {
            return periods[rand(0, periods.length)];
        }),
        genSentences = function (genEachSentenceFn) {
            var gen = {
                text: '',
                total: 0,
                sentenceCount: 0
            };

            while ((avail = genCount - gen.total) > 0) {
                gen.total += genEachSentenceFn(gen);
                gen.sentenceCount++;
            }

            return gen;
        };

    return genSentences(function (gen) {
        var currentWordCount = wordCountFn();

        gen.text += genWords(currentWordCount);
        gen.text += genPeriod();

        return currentWordCount + 1;
    });
}
function generate ( opts ) { var options = opts || { } , genCount = Math . abs ( options . count ) >>> 0 , // min/max word count in a sentence minCount = Math . abs ( options . minCount ) || 5 , maxCount = Math . abs ( options . maxCount ) || 20 , formater = options . format == '\\uXXXX' ? formatOutput : undefined , periods = extendPeriod ( options . toleratedPeriods || '' ) ; var avail = 0 ; var genHelper = function ( genFn ) { return formater === undefined ? genFn : function ( ) { return formatOutput ( genFn . apply ( undefined , arguments ) ) ; } ; } , genWords = genHelper ( options . freq === true ? freqUsedWordsGen : wordsGen ) , wordCountFn = function ( ) { var count = rand ( minCount , maxCount ) ; return count >= avail ? avail - 1 : count ; } , genPeriod = genHelper ( function ( ) { return periods [ rand ( 0 , periods . length ) ] ; } ) , genSentences = function ( genEachSentenceFn ) { var gen = { text : '' , total : 0 , sentenceCount : 0 } ; while ( ( avail = genCount - gen . total ) > 0 ) { gen . total += genEachSentenceFn ( gen ) ; gen . sentenceCount ++ ; } return gen ; } ; return genSentences ( function ( gen ) { var currentWordCount = wordCountFn ( ) ; gen . text += genWords ( currentWordCount ) ; gen . text += genPeriod ( ) ; return currentWordCount + 1 ; } ) ; }
generate random paragraph in Chinese

@param {Object} [opts]
@param {Number} [opts.count] the total word count of the generated paragraph
@param {Boolean} [opts.freq] use frequently used words
@param {String} [opts.format] support '\uXXXX'
@param {String} [opts.toleratedPeriods]
@return {Object}
{String} [text] random text
{Number} [total] text total length
{Number} [sentenceCount] sentence count
@public
generate random paragraph in Chinese