textstat is plugable statistics tool for text, markdown and html.
textstat is built on top of textlint.
- Support text, markdown and html
- Analyze text and show information
- Write statistics rule by JavaScript
- Write plugins by JavaScript
npm install textstat
The same way of textlint.
The difference between textstat and textlint is that textstat
has some built-in rules.
textstat [options] file.md [file.txt] [dir]
Options:
-h, --help Show help.
-c, --config path::String Use configuration from this file or sharable config.
--plugin [String] Specify plugins
--rule [path::String] Set rule package name and set all default rules to off.
--rulesdir [path::String] Set rules from this directory and set all default rules to off.
-f, --format String Use a specific output format.
-v, --version Outputs the version number.
--ext [String] Specify text file extensions.
-o, --output-file path::String Enable report to be written to a file.
--quiet Report errors only. - default: false
--stdin Lint code provided on <STDIN>. - default: false
Example:
$ textstat ja/ESLint/
┌──────────────────────┬─────────────────────┐
│ filePath │ ja/ESLint/README.md │
├──────────────────────┼─────────────────────┤
│ fileSize │ 14.46 kB │
├──────────────────────┼─────────────────────┤
│ number of characters │ 8681 │
├──────────────────────┼─────────────────────┤
│ number of Lines │ 306 │
├──────────────────────┼─────────────────────┤
│ number of Images │ 0 │
├──────────────────────┼─────────────────────┤
│ number of Links │ 22 │
├──────────────────────┼─────────────────────┤
│ number of List Items │ 22 │
├──────────────────────┼─────────────────────┤
│ number of sentences │ 160 │
├──────────────────────┼─────────────────────┤
│ share of code │ 30% │
└──────────────────────┴─────────────────────┘
.textstatrc
is config file that is loaded as YAML, JSON or JS via MoOx/rc-loader.
$ textstat --rule number-of-lines README.md
is equal to
{
"rules": {
"number-of-lines": true
}
}
The config object can define rule's option.
{
"rules": {
"number-of-lines": false, // disable
"very-nice-rule": {
"key": "value"
}
}
}
Pass rule's options("key": "value") to very-nice-rule
.
It mean that use the following format:
{
"rules": {
"<rule-name>": true | false | object
}
}
textstat plugin is a set of rules and rulesConfig or customize parser.
To enable plugin, put the plugin-name
into .textstat
.
// `.textstatrc`
{
"plugins": [
"plugin-name"
],
// overwrite-plugins rules config
// <plugin>/<rule>
"rules": {
"plugin-name/rule-name" : false
}
}
Example
$ npm install textstat-plugin-ja textstat -D
To enable ja
plugin and add to .textstatrc
{
"plugins":[
"ja"
]
}
You can create new rule by JavaScript.
See
- src/rules
- textlint/create-rules.md is of help
- textstat's rule is the same way of textlint.
- The difference between textstat and textlint is that second arguments is a object of
report(node, object)
.
number-of-characters
rule:
export default function (context) {
let { Syntax, getSource, report } = context;
return {
// node's type
// see https://github.com/textlint/textlint/blob/master/docs/txtnode.md
[Syntax.Document](node){
let text = getSource(node);
let charactersCount = text.length;
// report(node, { "key": "value" });
report(node, {
"number of characters": charactersCount
});
}
}
}
Add false
to the rule of .textstatrc
{
"rules": {
"file-size" : false,
"share-of-code" : false
}
}
textstatで使える日本語向けの統計ルール集
$ npm install textstat-plugin-ja textstat -g
$ textstat --plugin ja README.md
npm test
- Fork it!
- Create your feature branch:
git checkout -b my-new-feature
- Commit your changes:
git commit -am 'Add some feature'
- Push to the branch:
git push origin my-new-feature
- Submit a pull request :D
MIT