nlp-toolkit
Version:
This module covers some basic nlp principles and implementations. Every implementation in this module is written as stream to only hold that data in memory that is currently processed at any step.
42 lines (32 loc) • 743 B
JavaScript
/**
* Max number of tokens.
*/
;
/**
* MODULES.
*/
var through2 = require('through2');
/**
* VARIABLES.
*/
var DEFAULT_MAX = Infinity;
/**
* FUNCTIONS.
*/
function max(value) {
value = value || DEFAULT_MAX;
return through2.obj(function (chunk, enc, callback) {
var _chunk = (typeof chunk === 'object' && Object.prototype.toString.call(chunk) !== '[object Array]') ? chunk.text : chunk;
if (!_chunk || Object.prototype.toString.call(_chunk) !== '[object Array]') {
return callback(new Error('Chunk is not an array ' + JSON.stringify(chunk)));
}
if (_chunk.length > value) {
return callback();
}
return callback(null, chunk);
});
}
/**
* EXPORTS.
*/
module.exports = max;