© 2013 Robert Bost
Author: Robert Bost
Demo: http://bostrt.github.io/wordcount.js/
WordCount.js is a client-side JS and Node.js library that counts bytes, words, lines chars, and calculates the longest line of a file using the HTML5 File API.
bower install wordcount.js
<html>
<head>
<script type="text/javascript" src="wordcount.js"></script>
</head>
<body>
<input type="file" id="input"/>
</body>
</html>
...
WordCount.bytes("input", function(size, file, inputSelector) {
console.log("Number of bytes: " + size);
});
WordCount.chars("input", function(chars) {
console.log("Number of characters: " + chars);
});
npm install -g mocha
mocha
Callbacks are passed into each of WordCount's
functions. Each callback should accept 3 parameters, (1) the value that the
function is calculating or finding, (2) the File object that was uploaded,
(3) and the ID selector of the file input element.
callback(value, file, selector)
When a file is uploaded using the file input element with the given input selector then the number of the bytes in the uploaded file is calculated and then callback is called.
Parameters
selector: String, - The ID selector for a file input element.
callback: Function, - Called when a file has been completely uploaded and bytes have been calculated.
When a file is uploaded using the file input element with the given input selector then the longest line in the file is located and the callback is called.
Parameters
selector: String, - The ID selector for a file input element.
callback: Function, - Called when a file has been completely uploaded and the longest line has been found.
When a file is uploaded using the file input element with the given input selector then the number of words in the file is calculated and the callback is called. A word is a non-zero-length sequence of characters delimited by white space.
Parameters
selector: String, - The ID selector for a file input element.
callback: Function, - Called after a file is available and the number of words have been calculated.
When a file is uploaded using the file input element with the given input selector then the number of chars in the file are calculated and the callback is called.
Parameters
selector: String, - The ID selector for a file input element.
callback: Function, - Called after a file is available and the number of chars in that file have been calculated.
When a file is uploaded using the file input element with the given input selector then the number of lines in the file are calculated and the callback is called.
Parameters
selector: String, - The ID selector for a file input element.
callback: Function, - Called after a file is available and the number of lines in that file have been calculated.