├── .travis.yml ├── packages ├── @textstat │ ├── textstat-view │ │ ├── public │ │ │ ├── _redirects │ │ │ ├── favicon.ico │ │ │ ├── manifest.json │ │ │ └── index.html │ │ ├── src │ │ │ ├── react-app-env.d.ts │ │ │ ├── context │ │ │ │ ├── StatContext.ts │ │ │ │ ├── LocalStore.ts │ │ │ │ └── GistStore.ts │ │ │ ├── helper │ │ │ │ └── trim-common-prefix.ts │ │ │ ├── App.css │ │ │ ├── index.css │ │ │ ├── pages │ │ │ │ ├── textstat-rule-number-of-characters.tsx │ │ │ │ ├── index.tsx │ │ │ │ └── textstat-rule-document-dependency.tsx │ │ │ ├── AppMenu.css │ │ │ ├── index.tsx │ │ │ ├── components │ │ │ │ ├── DocumentDependencyView │ │ │ │ │ ├── DocumentDependencyView.tsx │ │ │ │ │ └── generate.ts │ │ │ │ └── NumberOfCharactersView │ │ │ │ │ └── NumberOfCharactersView.tsx │ │ │ ├── AppMenu.tsx │ │ │ └── App.tsx │ │ ├── tsconfig.json │ │ ├── LICENSE │ │ ├── CHANGELOG.md │ │ ├── package.json │ │ ├── README.md │ │ └── .gitignore │ ├── textstat-tester │ │ ├── test │ │ │ ├── mocha.opts │ │ │ └── tsconfig.json │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── LICENSE │ │ ├── package.json │ │ └── src │ │ │ └── textstat-tester.ts │ ├── to-non-cyclic │ │ ├── test │ │ │ ├── mocha.opts │ │ │ └── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── tsconfig.json │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── to-non-cyclic.ts │ ├── kernel │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ ├── rule │ │ │ │ └── textstat-rule-example.ts │ │ │ └── TextstatKernel-test.ts │ │ ├── src │ │ │ ├── index.ts │ │ │ ├── ResultValidator.ts │ │ │ └── type.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── package.json │ │ └── README.md │ ├── rule-context │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ └── Localize-test.ts │ │ ├── tsconfig.json │ │ ├── src │ │ │ ├── index.ts │ │ │ ├── preset.ts │ │ │ ├── report-type.ts │ │ │ └── Localize.ts │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── LICENSE │ │ └── package.json │ ├── textstat-rule-document-dependency │ │ ├── test │ │ │ ├── snapshots │ │ │ │ ├── no-link │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ │ └── from-to-link │ │ │ │ │ ├── input.md │ │ │ │ │ ├── a.md │ │ │ │ │ ├── b.md │ │ │ │ │ └── output.json │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ └── textstat-rule-document-dependency-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── package.json │ │ └── src │ │ │ └── index.ts │ ├── textstat-rule-preset-standard │ │ ├── test │ │ │ ├── mocha.opts │ │ │ └── tsconfig.json │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── README.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── textstat-rule-preset-standard.ts │ │ └── package.json │ ├── textstat-rule-filesize │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── snapshots │ │ │ │ ├── en │ │ │ │ │ └── 100kb │ │ │ │ │ │ ├── input.md │ │ │ │ │ │ └── output.json │ │ │ │ └── ja │ │ │ │ │ └── 100kb │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ ├── tsconfig.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── src │ │ │ └── index.ts │ │ └── package.json │ ├── textstat-rule-number-of-images │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── snapshots │ │ │ │ └── 5 │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ ├── tsconfig.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── index.ts │ │ ├── README.md │ │ └── package.json │ ├── textstat-rule-number-of-links │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ ├── snapshots │ │ │ │ └── 5 │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── index.ts │ │ ├── README.md │ │ └── package.json │ ├── textstat-rule-number-of-list-items │ │ ├── test │ │ │ ├── snapshots │ │ │ │ └── 5 │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── index.ts │ │ ├── README.md │ │ └── package.json │ ├── textstat-rule-tateishi-level │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── tsconfig.json │ │ │ ├── index-test.ts │ │ │ └── snapshots │ │ │ │ └── simple │ │ │ │ └── output.json │ │ ├── src │ │ │ ├── sentence-util.ts │ │ │ └── tateishi.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ └── package.json │ ├── textstat-rule-number-of-characters │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── snapshots │ │ │ │ └── 100 │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ ├── tsconfig.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── index.ts │ │ ├── README.md │ │ └── package.json │ ├── textstat-rule-number-of-paragraphs │ │ ├── test │ │ │ ├── mocha.opts │ │ │ ├── snapshots │ │ │ │ └── 5 │ │ │ │ │ ├── input.md │ │ │ │ │ └── output.json │ │ │ ├── tsconfig.json │ │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── src │ │ │ └── index.ts │ │ ├── README.md │ │ └── package.json │ └── textstat-rule-number-of-sentences │ │ ├── test │ │ ├── mocha.opts │ │ ├── snapshots │ │ │ └── 10 │ │ │ │ ├── input.md │ │ │ │ └── output.json │ │ ├── tsconfig.json │ │ └── index-test.ts │ │ ├── tsconfig.json │ │ ├── CHANGELOG.md │ │ ├── LICENSE │ │ ├── README.md │ │ ├── src │ │ └── index.ts │ │ └── package.json └── textstat │ ├── test │ ├── mocha.opts │ └── tsconfig.json │ ├── src │ ├── index.ts │ ├── formatter │ │ ├── textstat-formatter-json.ts │ │ ├── index.ts │ │ └── textstat-formatter-csv.ts │ ├── cli.ts │ └── textstat.ts │ ├── tsconfig.json │ ├── bin │ └── cmd.js │ ├── README.md │ ├── LICENSE │ ├── CHANGELOG.md │ └── package.json ├── .netlify └── state.json ├── tools ├── resources │ ├── typescript.mocha.opts │ ├── test.tsconfig.json │ ├── package.json │ ├── tsconfig.json │ └── textstat.readme.template ├── add-prettier.sh ├── index.sh ├── add-prettier.js ├── add-new-rule.sh └── node.js.sh ├── lerna.json ├── netlify.toml ├── tsconfig.json ├── tsconfig.base.json ├── LICENSE ├── package.json ├── .gitignore ├── CHANGELOG.md └── README.md /.travis.yml: -------------------------------------------------------------------------------- 1 | sudo: false 2 | language: node_js 3 | node_js: "stable" 4 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/public/_redirects: -------------------------------------------------------------------------------- 1 | /* /index.html 200 2 | -------------------------------------------------------------------------------- /.netlify/state.json: -------------------------------------------------------------------------------- 1 | { 2 | "siteId": "a43e015d-f0ac-471d-9dc1-2fbcb82642ec" 3 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | -------------------------------------------------------------------------------- /tools/resources/typescript.mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node/register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/textstat/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 20000 3 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/no-link/input.md: -------------------------------------------------------------------------------- 1 | # NO LINK 2 | 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/react-app-env.d.ts: -------------------------------------------------------------------------------- 1 | /// 2 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/from-to-link/input.md: -------------------------------------------------------------------------------- 1 | [a](./a.md) 2 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/from-to-link/a.md: -------------------------------------------------------------------------------- 1 | [input](./input.md) 2 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/from-to-link/b.md: -------------------------------------------------------------------------------- 1 | [b -> input](./input.md) 2 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/test/snapshots/5/input.md: -------------------------------------------------------------------------------- 1 | - 1 2 | - 2 3 | - 3 4 | - 4 5 | - 5 6 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/test/mocha.opts: -------------------------------------------------------------------------------- 1 | --require ts-node-test-register 2 | --timeout 10000 3 | -------------------------------------------------------------------------------- /packages/textstat/src/index.ts: -------------------------------------------------------------------------------- 1 | import * as cli from "./cli"; 2 | import * as textstat from "./textstat"; 3 | 4 | export { cli, textstat }; 5 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/src/index.ts: -------------------------------------------------------------------------------- 1 | export { TextstatKernel } from "./TextstatKernel"; 2 | export { TextstatMessage, TextstatResult } from "./type"; 3 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/textlint/textstat/HEAD/packages/@textstat/textstat-view/public/favicon.ico -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/test/snapshots/5/input.md: -------------------------------------------------------------------------------- 1 | This is 1. 2 | 3 | This is 2. 4 | 5 | This is 3. 6 | 7 | This is 4. 8 | 9 | This is 5. 10 | -------------------------------------------------------------------------------- /tools/resources/test.tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false 5 | }, 6 | "include": [ 7 | "**/*" 8 | ] 9 | } -------------------------------------------------------------------------------- /lerna.json: -------------------------------------------------------------------------------- 1 | { 2 | "lerna": "2.5.1", 3 | "packages": [ 4 | "packages/*", 5 | "packages/@textstat/*" 6 | ], 7 | "version": "0.8.0", 8 | "npmClient": "yarn", 9 | "useWorkspaces": true 10 | } 11 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/snapshots/en/100kb/input.md: -------------------------------------------------------------------------------- 1 | 0123456789 2 | 0123456789 3 | 0123456789 4 | 0123456789 5 | 0123456789 6 | 0123456789 7 | 0123456789 8 | 0123456789 9 | 0123456789 10 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/snapshots/ja/100kb/input.md: -------------------------------------------------------------------------------- 1 | 0123456789 2 | 0123456789 3 | 0123456789 4 | 0123456789 5 | 0123456789 6 | 0123456789 7 | 0123456789 8 | 0123456789 9 | 0123456789 10 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/test/snapshots/100/input.md: -------------------------------------------------------------------------------- 1 | 0123456789 2 | 0123456789 3 | 0123456789 4 | 0123456789 5 | 0123456789 6 | 0123456789 7 | 0123456789 8 | 0123456789 9 | 0123456789. 10 | -------------------------------------------------------------------------------- /tools/resources/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "directories": { 3 | "test": "test" 4 | }, 5 | "author": "azu", 6 | "license": "MIT", 7 | "files": [ 8 | "bin/", 9 | "lib/", 10 | "src/" 11 | ] 12 | } 13 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/textstat/src/formatter/textstat-formatter-json.ts: -------------------------------------------------------------------------------- 1 | import { TextstatResult } from "@textstat/kernel/lib/src"; 2 | 3 | export const format = (results: TextstatResult[]) => { 4 | return JSON.stringify(results); 5 | }; 6 | -------------------------------------------------------------------------------- /netlify.toml: -------------------------------------------------------------------------------- 1 | [build] 2 | command = "yarn run bootstrap && yarn run netlify" 3 | publish = "packages/@textstat/textstat-view/build" 4 | 5 | [build.environment] 6 | NODE_VERSION = "--lts=dubnium" 7 | YARN_VERSION = "1.12.3" 8 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/test/snapshots/5/input.md: -------------------------------------------------------------------------------- 1 | ![image](./image.png) 2 | ![image](./image.jpg) 3 | ![image](./image.jpeg) 4 | ![image](./image.gid) 5 | ![image](./image.move) 6 | 7 | THIS is [link](./img/img.png) 8 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/test/snapshots/10/input.md: -------------------------------------------------------------------------------- 1 | This is 1. This is 1-1. 2 | 3 | This is 2. This is 2-1. 4 | 5 | This is 3. This is 3-1. 6 | 7 | This is 4. This is 4-1. 8 | 9 | This is 5. This is 5-1. 10 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": ["**/*"] 8 | } 9 | -------------------------------------------------------------------------------- /packages/textstat/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": [ 8 | "../src/**/*", 9 | "./**/*" 10 | ] 11 | } -------------------------------------------------------------------------------- /tools/add-prettier.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | declare scriptDir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) 4 | declare currentDir=$(pwd) 5 | 6 | yarn add prettier --dev --pure-lockfile --prefer-offline 7 | node "${scriptDir}/add-prettier.js" "${currentDir}/package.json" 8 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/test/snapshots/5/input.md: -------------------------------------------------------------------------------- 1 | ![image](./image.move) 2 | 3 | [link](https://example.com/a) 4 | [link](https://example.com/b) 5 | [link](https://example.com/c) 6 | [link](https://example.com/d) 7 | [link](https://example.com/e) 8 | -------------------------------------------------------------------------------- /tools/resources/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/" 5 | }, 6 | "include": [ 7 | "src/**/*" 8 | ], 9 | "exclude": [ 10 | ".git", 11 | "node_modules" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": [ 8 | "../src/**/*", 9 | "./**/*" 10 | ] 11 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "outDir": "../out", 5 | "declaration": false, 6 | "noEmit": true 7 | }, 8 | "include": ["../src/**/*", "./**/*"] 9 | } 10 | -------------------------------------------------------------------------------- /tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | // THIS FILE IS FOR IDE/EDITOR 3 | "extends": "./tsconfig.base.json", 4 | "compilerOptions": { 5 | "noEmit": true 6 | }, 7 | "include": [ 8 | "src/**/*" 9 | ], 10 | "exclude": [ 11 | ".git", 12 | "node_modules" 13 | ] 14 | } 15 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/" 5 | }, 6 | "include": [ 7 | "src/**/*" 8 | ], 9 | "exclude": [ 10 | ".git", 11 | "node_modules" 12 | ] 13 | } 14 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/test/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../tsconfig.json", 3 | "compilerOptions": { 4 | "declaration": false, 5 | "noEmit": true 6 | }, 7 | "include": [ 8 | "../src/**/*", 9 | "./**/*" 10 | ] 11 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/context/StatContext.ts: -------------------------------------------------------------------------------- 1 | import { createContext } from "react"; 2 | import { getStore } from "./LocalStore"; 3 | 4 | const defaultValue = { 5 | input: "", 6 | results: [] 7 | }; 8 | const defaultState = getStore(defaultValue); 9 | export const StatContext = createContext(defaultState); 10 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/helper/trim-common-prefix.ts: -------------------------------------------------------------------------------- 1 | const commonPathPrefix = require("common-path-prefix"); 2 | export const trimCommonPrefix = (items: string[]): string[] => { 3 | const prefix: string = commonPathPrefix(items); 4 | return items.map(item => item.replace(prefix, "").replace(/\/README.md$/, "")); 5 | }; 6 | -------------------------------------------------------------------------------- /tools/index.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | declare scriptDir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) 4 | declare ruleName=$1 5 | echo "Create ${ruleName}" 6 | 7 | mkdir -p "${scriptDir}/../packages/@textstat/${ruleName}" 8 | cd "${scriptDir}/../packages/@textstat/${ruleName}/" 9 | NPM_SCOPE=@textstat bash "${scriptDir}/add-new-rule.sh" 10 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/src/sentence-util.ts: -------------------------------------------------------------------------------- 1 | import { splitAST, Syntax } from "sentence-splitter"; 2 | import { TxtParentNode } from "@textlint/ast-node-types"; 3 | 4 | export const getSentences = (node: TxtParentNode) => { 5 | return splitAST(node).children.filter(node => { 6 | return node.type === Syntax.Sentence; 7 | }); 8 | }; 9 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/" 5 | }, 6 | "references": [ 7 | { 8 | "path": "../rule-context/tsconfig.json" 9 | } 10 | ], 11 | "include": [ 12 | "src/**/*" 13 | ], 14 | "exclude": [ 15 | ".git", 16 | "node_modules" 17 | ] 18 | } 19 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/to-non-cyclic 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/public/manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | "short_name": "textstat-viewer", 3 | "name": "textstat-viewer", 4 | "icons": [ 5 | { 6 | "src": "favicon.ico", 7 | "sizes": "64x64 32x32 24x24 16x16", 8 | "type": "image/x-icon" 9 | } 10 | ], 11 | "start_url": ".", 12 | "display": "standalone", 13 | "theme_color": "#000000", 14 | "background_color": "#ffffff" 15 | } 16 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/src/index.ts: -------------------------------------------------------------------------------- 1 | // rule 2 | export { 3 | TextstatRuleMeta, 4 | TextstatRuleSharedDependencies, 5 | TextstatRuleReporter, 6 | TextstatKernelFilterRule, 7 | TextstatKernelRule 8 | } from "./report-type"; 9 | // preset 10 | export { isTextstatRulePresetFactory, TextstatRulePreset, TextstatRulePresetFactory } from "./preset"; 11 | // Localization 12 | export { Localize, LocaleTag } from "./Localize"; 13 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/App.css: -------------------------------------------------------------------------------- 1 | html, 2 | body, 3 | #root, 4 | .App, 5 | .App-main { 6 | width: 100%; 7 | height: 100%; 8 | margin: 0; 9 | padding: 0; 10 | } 11 | 12 | .App { 13 | display: flex; 14 | } 15 | 16 | .App-header { 17 | padding: 1rem; 18 | } 19 | 20 | .App-main { 21 | padding: 1rem 0; 22 | } 23 | 24 | .App-input { 25 | width: 100%; 26 | height: 5em; 27 | } 28 | 29 | .App-input:focus { 30 | height: 50em; 31 | } 32 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/index.css: -------------------------------------------------------------------------------- 1 | body { 2 | margin: 0; 3 | padding: 0; 4 | font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Oxygen", "Ubuntu", "Cantarell", "Fira Sans", 5 | "Droid Sans", "Helvetica Neue", sans-serif; 6 | -webkit-font-smoothing: antialiased; 7 | -moz-osx-font-smoothing: grayscale; 8 | } 9 | 10 | code { 11 | font-family: source-code-pro, Menlo, Monaco, Consolas, "Courier New", monospace; 12 | } 13 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/", 5 | "composite": true 6 | }, 7 | "references": [ 8 | { 9 | "path": "../rule-context/tsconfig.json" 10 | }, 11 | { 12 | "path": "../kernel/tsconfig.json" 13 | } 14 | ], 15 | "include": [ 16 | "src/**/*" 17 | ], 18 | "exclude": [ 19 | ".git", 20 | "node_modules" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-tateish-level", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-tateish-level", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/pages/textstat-rule-number-of-characters.tsx: -------------------------------------------------------------------------------- 1 | // pages/reference.js 2 | import * as React from "react"; 3 | import { StatContext } from "../context/StatContext"; 4 | import { NumberOfCharactersView } from "../components/NumberOfCharactersView/NumberOfCharactersView"; 5 | 6 | export default function TextstatRuleNumberOfCharacters() { 7 | return {({ results }) => }; 8 | } 9 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-images", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-images", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-links", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-links", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-sentences", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-sentences", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/", 5 | "composite": true 6 | }, 7 | "references": [ 8 | { 9 | "path": "../rule-context/tsconfig.json" 10 | }, 11 | { 12 | "path": "../textstat-tester/tsconfig.json" 13 | } 14 | ], 15 | "include": [ 16 | "src/**/*" 17 | ], 18 | "exclude": [ 19 | ".git", 20 | "node_modules" 21 | ] 22 | } 23 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-characters", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-characters", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-list-items", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-list-items", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-number-of-paragraphs", () => { 6 | runTest(path.join(__dirname, "snapshots"), { 7 | rules: [ 8 | { 9 | ruleId: "textstat-rule-number-of-paragraphs", 10 | rule: rule 11 | } 12 | ] 13 | }); 14 | }); 15 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../textstat-tester/tsconfig.json" 14 | } 15 | ], 16 | "include": [ 17 | "src/**/*" 18 | ], 19 | "exclude": [ 20 | ".git", 21 | "node_modules" 22 | ] 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/kernel 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/kernel 17 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/AppMenu.css: -------------------------------------------------------------------------------- 1 | .AppMenu { 2 | display: flex; 3 | flex-direction: column; 4 | justify-content: space-between; 5 | width: 150px; 6 | border-right: 1px solid #d7dbdd; 7 | background-color: #fcfdfd; 8 | padding: 10px; 9 | list-style: none; 10 | } 11 | 12 | .AppMenu-listItem { 13 | cursor: pointer; 14 | padding: 5px 10px; 15 | color: #16a2d7; 16 | font-size: 14px; 17 | } 18 | 19 | .AppMenu-listItem.is-current { 20 | background-color: #eef3f5; 21 | border-radius: 4px; 22 | } 23 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | 3 | "extends": "../../../tsconfig.base.json", 4 | "compilerOptions": { 5 | "outDir": "./lib/", 6 | "composite": true 7 | }, 8 | "references": [ 9 | { 10 | "path": "../rule-context/tsconfig.json" 11 | }, 12 | { 13 | "path": "../kernel/tsconfig.json" 14 | }, 15 | { 16 | "path": "../textstat-tester/tsconfig.json" 17 | } 18 | ], 19 | "include": [ 20 | "src/**/*" 21 | ], 22 | "exclude": [ 23 | ".git", 24 | "node_modules" 25 | ] 26 | } 27 | -------------------------------------------------------------------------------- /packages/textstat/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "extends": "../../tsconfig.base.json", 3 | "compilerOptions": { 4 | "outDir": "./lib/", 5 | "composite": true 6 | }, 7 | "references": [ 8 | { 9 | "path": "../@textstat/rule-context/tsconfig.json" 10 | }, 11 | { 12 | "path": "../@textstat/kernel/tsconfig.json" 13 | }, 14 | { 15 | "path": "../@textstat/textstat-rule-preset-standard/tsconfig.json" 16 | } 17 | ], 18 | "include": [ 19 | "src/**/*" 20 | ], 21 | "exclude": [ 22 | ".git", 23 | "node_modules" 24 | ] 25 | } 26 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "target": "es5", 4 | "lib": [ 5 | "es7", 6 | "dom" 7 | ], 8 | "allowJs": false, 9 | "skipLibCheck": false, 10 | "esModuleInterop": true, 11 | "allowSyntheticDefaultImports": true, 12 | "strict": true, 13 | "forceConsistentCasingInFileNames": true, 14 | "module": "esnext", 15 | "moduleResolution": "node", 16 | "resolveJsonModule": true, 17 | "isolatedModules": true, 18 | "noEmit": true, 19 | "jsx": "preserve" 20 | }, 21 | "include": [ 22 | "src" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /packages/textstat/src/formatter/index.ts: -------------------------------------------------------------------------------- 1 | import { TextstatResult } from "@textstat/kernel"; 2 | import * as CSVFormatter from "./textstat-formatter-csv"; 3 | import * as JSONFormatter from "./textstat-formatter-json"; 4 | 5 | export type FormatterType = "csv" | "json"; 6 | 7 | export function format(results: TextstatResult[], type: FormatterType): string { 8 | switch (type) { 9 | case "csv": 10 | return CSVFormatter.format(results); 11 | case "json": 12 | return JSONFormatter.format(results); 13 | default: 14 | throw new Error(`Formatter type: ${type} is undefined`); 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/context/LocalStore.ts: -------------------------------------------------------------------------------- 1 | const KEY = "textstat-viewer"; 2 | 3 | export function getStore(defaultValue: T): T { 4 | if (!!process.env.REACT_APP_NAVI) { 5 | return defaultValue; 6 | } 7 | const value = localStorage.getItem(KEY); 8 | if (!value) { 9 | return defaultValue; 10 | } 11 | try { 12 | return JSON.parse(value); 13 | } catch (error) { 14 | return defaultValue; 15 | } 16 | } 17 | 18 | export function saveStore(value: any) { 19 | if (!!process.env.REACT_APP_NAVI) { 20 | return; 21 | } 22 | localStorage.setItem(KEY, JSON.stringify(value)); 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/index.tsx: -------------------------------------------------------------------------------- 1 | // index.js 2 | import * as React from "react"; 3 | import * as ReactDOM from "react-dom"; 4 | import * as Navi from "navi"; 5 | import pages from "./pages/index"; 6 | import App from "./App"; 7 | import { unregister } from "./serviceWorker"; 8 | 9 | async function main() { 10 | let navigation = Navi.createBrowserNavigation({ pages }); 11 | // Wait until async content is ready, or has failed. 12 | await navigation.steady(); 13 | 14 | ReactDOM.render(, document.getElementById("root")); 15 | } 16 | 17 | Navi.app({ 18 | pages, 19 | main, 20 | exports: App 21 | }); 22 | unregister(); 23 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/textstat-rule-document-dependency-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | const glob = require("glob"); 6 | describe("textstat-rule-document-dependency", () => { 7 | const snapshotDir = path.join(__dirname, "snapshots"); 8 | runTest(snapshotDir, { 9 | rules: [ 10 | { 11 | ruleId: "textstat-rule-document-dependency", 12 | rule: rule 13 | } 14 | ], 15 | sharedDeps: { 16 | filePathList: glob.sync(`${snapshotDir}/**/*.md`) 17 | } 18 | }); 19 | }); 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/src/tateishi.ts: -------------------------------------------------------------------------------- 1 | /* 2 | http://doksyo-tek.hatenablog.com/entry/2015/05/19/104050 3 | RS:評価 4 | 1s:文の平均の長さ(文字数) 5 | 1a:アルファベット連の平均の長さ(文字数) 6 | 1h:ひらがな連の平均の長さ(文字数) 7 | 1c:漢字連の平均の長さ(文字数) 8 | 1k:カタカナ連の平均の長さ(文字数) 9 | cp:句点あたりの読点の数 10 | */ 11 | export function elevateTateishi({ 12 | sentence, 13 | alphabet, 14 | hiragana, 15 | kanji, 16 | katakana, 17 | cp 18 | }: { 19 | sentence: number; 20 | alphabet: number; 21 | hiragana: number; 22 | kanji: number; 23 | katakana: number; 24 | cp: number; 25 | }) { 26 | return ( 27 | -0.12 * sentence + -1.37 * alphabet + 7.4 * hiragana + -23.18 * kanji + -5.4 * katakana + -4.67 * cp + 115.79 28 | ); 29 | } 30 | -------------------------------------------------------------------------------- /tsconfig.base.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | "outDir": "________RENAMED_______", 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "newLine": "LF", 7 | "target": "es5", 8 | "sourceMap": true, 9 | "declaration": true, 10 | "jsx": "preserve", 11 | "lib": [ 12 | "es2017", 13 | "dom" 14 | ], 15 | "strict": true, 16 | "noUnusedLocals": true, 17 | "noUnusedParameters": true, 18 | "noImplicitReturns": true, 19 | "noFallthroughCasesInSwitch": true, 20 | "esModuleInterop": true, 21 | /* monorepo */ 22 | "composite": true 23 | }, 24 | "include": [ 25 | "src/**/*" 26 | ], 27 | "exclude": [ 28 | ".git", 29 | "node_modules" 30 | ] 31 | } 32 | -------------------------------------------------------------------------------- /packages/textstat/src/cli.ts: -------------------------------------------------------------------------------- 1 | import { report } from "./textstat"; 2 | import { format, FormatterType } from "./formatter"; 3 | 4 | const osLocale = require("os-locale"); 5 | 6 | export interface RunOptions { 7 | locale: string; 8 | format: FormatterType; 9 | globPatterns: string[]; 10 | } 11 | 12 | export async function run(options: RunOptions) { 13 | const locale = options.locale ? options.locale : (osLocale.sync() as string); 14 | return report({ 15 | locale, 16 | globPatterns: options.globPatterns 17 | }).then(results => { 18 | if (options.format) { 19 | return format(results, options.format); 20 | } else { 21 | return format(results, "json"); 22 | } 23 | }); 24 | } 25 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/rule-context 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/rule-context 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/rule-context 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-tester 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-tester 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-tester 25 | -------------------------------------------------------------------------------- /tools/add-prettier.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | "use strict"; 3 | const fs = require("fs"); 4 | const path = require("path"); 5 | const arg = process.argv[2]; 6 | const pkgPath = path.resolve(process.cwd(), arg); 7 | const pkg = require(pkgPath); 8 | const addPrettier = pkg => { 9 | const oldScripts = pkg.scripts || {}; 10 | const scripts = Object.assign({}, oldScripts, { 11 | prettier: 'prettier --write "**/*.{js,jsx,ts,tsx,css}"' 12 | }); 13 | const prettier = { 14 | singleQuote: false, 15 | printWidth: 120, 16 | tabWidth: 4 17 | }; 18 | return Object.assign({}, pkg, { 19 | scripts, 20 | prettier 21 | }); 22 | }; 23 | const newPkg = addPrettier(pkg); 24 | fs.writeFileSync(pkgPath, JSON.stringify(newPkg, null, 2), "utf-8"); 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-filesize 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-filesize 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-filesize 25 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/src/preset.ts: -------------------------------------------------------------------------------- 1 | import { TextlintRuleOptions } from "@textlint/kernel"; 2 | import { TextstatRuleMeta, TextstatRuleReporter } from "./report-type"; 3 | /** 4 | * Textstat Rule preset 5 | */ 6 | export type TextstatRulePreset = { 7 | rules: { 8 | [index: string]: { 9 | meta: TextstatRuleMeta; 10 | report: TextstatRuleReporter; 11 | }; 12 | }; 13 | rulesConfig: { [index: string]: TextlintRuleOptions | boolean }; 14 | }; 15 | 16 | export type TextstatRulePresetFactory = { 17 | // TODO: support option 18 | createPreset: () => TextstatRulePreset; 19 | }; 20 | 21 | export function isTextstatRulePresetFactory(v: any): v is TextstatRulePresetFactory { 22 | return typeof v === "object" && v.createPreset === "function"; 23 | } 24 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/snapshots/en/100kb/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-filesize", 6 | "message": "File size", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "message": "File size", 13 | "range": [ 14 | 0, 15 | 99 16 | ], 17 | "details": [ 18 | { 19 | "name": "File size", 20 | "value": 99 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/100kb/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-tateish-level 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-tateish-level 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-tateish-level 25 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/src/ResultValidator.ts: -------------------------------------------------------------------------------- 1 | import { TextstatMessage, TextstatResult } from "./type"; 2 | 3 | export const validateResult = (result: any): result is TextstatResult => { 4 | result.messages.forEach((message: TextstatMessage, index: number) => { 5 | if (!message.data) { 6 | throw new Error(`result[${index}].data is not defined.\n` + JSON.stringify(result, null, 4)); 7 | } 8 | if (!Array.isArray(message.data.range)) { 9 | throw new Error(`result[${index}].data.range is not defined.\n` + JSON.stringify(result, null, 4)); 10 | } 11 | if (!Array.isArray(message.data.details)) { 12 | throw new Error(`result[${index}].data.details is not defined\n` + JSON.stringify(result, null, 4)); 13 | } 14 | }); 15 | return true; 16 | }; 17 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-links 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-links 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-links 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-preset-standard 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-preset-standard 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-preset-standard 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/snapshots/ja/100kb/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-filesize", 6 | "message": "ドキュメントのファイルサイズ", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "message": "ドキュメントのファイルサイズ", 13 | "range": [ 14 | 0, 15 | 99 16 | ], 17 | "details": [ 18 | { 19 | "name": "ファイルサイズ", 20 | "value": 99 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/100kb/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-images 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-images 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-images 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-document-dependency 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-document-dependency 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-document-dependency 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-characters 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-characters 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-characters 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-list-items 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-list-items 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-list-items 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-paragraphs 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-paragraphs 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-paragraphs 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-sentences 9 | 10 | 11 | 12 | 13 | 14 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 15 | 16 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-sentences 17 | 18 | 19 | 20 | 21 | 22 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 23 | 24 | **Note:** Version bump only for package @textstat/textstat-rule-number-of-sentences 25 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/test/snapshots/simple/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-tateish-level", 6 | "message": "読みやすさの偏差値", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 30357 15 | ], 16 | "message": "読みやすさの偏差値", 17 | "details": [ 18 | { 19 | "name": "偏差値(平均50、標準偏差10、高いほど読みやすい)", 20 | "value": 110 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/simple/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/test/snapshots/5/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-links", 6 | "message": "Number of links in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 174 15 | ], 16 | "message": "Number of links in the document", 17 | "details": [ 18 | { 19 | "name": "Number of Links", 20 | "value": 5 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/5/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/test/snapshots/5/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-images", 6 | "message": "Number of images in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 143 15 | ], 16 | "message": "Number of images in the document", 17 | "details": [ 18 | { 19 | "name": "Number of images", 20 | "value": 5 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/5/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/test/snapshots/5/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-list-items", 6 | "message": "Number of list items in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 20 15 | ], 16 | "message": "Number of list items in the document", 17 | "details": [ 18 | { 19 | "name": "Number of list items", 20 | "value": 5 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/5/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/test/snapshots/5/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-paragraphs", 6 | "message": "Number of paragraphs in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 59 15 | ], 16 | "message": "Number of paragraphs in the document", 17 | "details": [ 18 | { 19 | "name": "Number of paragraphs", 20 | "value": 5 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/5/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/test/snapshots/10/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-sentences", 6 | "message": "Number of sentences in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "range": [ 13 | 0, 14 | 124 15 | ], 16 | "message": "Number of sentences in the document", 17 | "details": [ 18 | { 19 | "name": "Number of sentences", 20 | "value": 10 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/10/input.md" 27 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/test/snapshots/100/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-number-of-characters", 6 | "message": "Number of characters in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "message": "Number of characters in the document", 13 | "range": [ 14 | 0, 15 | 100 16 | ], 17 | "details": [ 18 | { 19 | "name": "Number of characters", 20 | "value": 100 21 | } 22 | ] 23 | } 24 | } 25 | ], 26 | "filePath": "/100/input.md" 27 | } -------------------------------------------------------------------------------- /packages/textstat/bin/cmd.js: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env node 2 | const meow = require("meow"); 3 | const run = require("../lib/src/cli").run; 4 | 5 | const cli = meow( 6 | ` 7 | Usage 8 | $ textstat 9 | 10 | Options 11 | --locale specify locale string like "en" 12 | 13 | Examples 14 | $ textstat /path/to/README.md 15 | $ textstat "./**/*.md" 16 | `, 17 | { 18 | flags: { 19 | locale: { 20 | type: "string" 21 | } 22 | }, 23 | autoHelp: true, 24 | autoVersion: true 25 | } 26 | ); 27 | 28 | if (cli.input.length === 0) { 29 | cli.showHelp(); 30 | } 31 | run({ 32 | globPatterns: cli.input, 33 | locale: cli.flags.locale 34 | }) 35 | .then(output => { 36 | console.log(output); 37 | }) 38 | .catch(error => { 39 | console.error(error); 40 | process.exit(1); 41 | }); 42 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/test/index-test.ts: -------------------------------------------------------------------------------- 1 | import * as path from "path"; 2 | import { runTest } from "@textstat/textstat-tester"; 3 | import * as rule from "../src/index"; 4 | 5 | describe("textstat-rule-filesize", () => { 6 | describe("en", () => { 7 | runTest(path.join(__dirname, "snapshots/en"), { 8 | rules: [ 9 | { 10 | ruleId: "textstat-rule-filesize", 11 | rule: rule 12 | } 13 | ] 14 | }); 15 | }); 16 | describe("ja", () => { 17 | runTest(path.join(__dirname, "snapshots/ja"), { 18 | rules: [ 19 | { 20 | ruleId: "textstat-rule-filesize", 21 | rule: rule 22 | } 23 | ], 24 | sharedDeps: { 25 | locale: "ja" 26 | } 27 | }); 28 | }); 29 | }); 30 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/tsconfig.json: -------------------------------------------------------------------------------- 1 | { 2 | "compilerOptions": { 3 | /* Basic Options */ 4 | "module": "commonjs", 5 | "moduleResolution": "node", 6 | "newLine": "LF", 7 | "outDir": "./lib/", 8 | "target": "es5", 9 | "sourceMap": true, 10 | "declaration": true, 11 | "jsx": "preserve", 12 | "lib": [ 13 | "es2017", 14 | "dom" 15 | ], 16 | /* Strict Type-Checking Options */ 17 | "strict": true, 18 | /* Additional Checks */ 19 | "noUnusedLocals": true, 20 | /* Report errors on unused locals. */ 21 | "noUnusedParameters": true, 22 | /* Report errors on unused parameters. */ 23 | "noImplicitReturns": true, 24 | /* Report error when not all code paths in function return a value. */ 25 | "noFallthroughCasesInSwitch": true 26 | /* Report errors for fallthrough cases in switch statement. */ 27 | }, 28 | "include": [ 29 | "src/**/*" 30 | ], 31 | "exclude": [ 32 | ".git", 33 | "node_modules" 34 | ] 35 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/context/GistStore.ts: -------------------------------------------------------------------------------- 1 | export function fetchGistContent(gistId: string) { 2 | const API_ENDPOINT = `https://api.github.com/gists/${gistId}`; 3 | return fetch(API_ENDPOINT) 4 | .then(response => { 5 | return response.json(); 6 | }) 7 | .then(json => { 8 | const files: { [index: string]: { language: string; content: string } } = json.files; 9 | const fileNames = Object.keys(files); 10 | if (fileNames.length === 1) { 11 | return files[fileNames[0]].content; 12 | } else if (fileNames.length > 1) { 13 | const jsonFile = fileNames.find(fileName => files[fileName].language === "json"); 14 | if (!jsonFile) { 15 | throw new Error("Does not found json file"); 16 | } 17 | return files[jsonFile].content; 18 | } 19 | throw new Error("The gist does not have a file"); 20 | }); 21 | } 22 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/no-link/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-document-dependency", 6 | "message": "Dependency links in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "message": "Dependency links in the document", 13 | "range": [ 14 | 0, 15 | 11 16 | ], 17 | "details": [ 18 | { 19 | "name": "To Links", 20 | "value": [] 21 | }, 22 | { 23 | "name": "From Links", 24 | "value": [] 25 | } 26 | ] 27 | } 28 | } 29 | ], 30 | "filePath": "/no-link/input.md" 31 | } -------------------------------------------------------------------------------- /packages/textstat/README.md: -------------------------------------------------------------------------------- 1 | # textstat 2 | 3 | textstat is statistic engine for text documents. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install textstat 10 | 11 | ## Usage 12 | 13 | - [ ] Write usage instructions 14 | 15 | ## Changelog 16 | 17 | See [Releases page](https://github.com/textlint/textstat/releases). 18 | 19 | ## Running tests 20 | 21 | Install devDependencies and Run `npm test`: 22 | 23 | npm i -d && npm test 24 | 25 | ## Contributing 26 | 27 | Pull requests and stars are always welcome. 28 | 29 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 30 | 31 | 1. Fork it! 32 | 2. Create your feature branch: `git checkout -b my-new-feature` 33 | 3. Commit your changes: `git commit -am 'Add some feature'` 34 | 4. Push to the branch: `git push origin my-new-feature` 35 | 5. Submit a pull request :D 36 | 37 | ## Author 38 | 39 | - [github/azu](https://github.com/azu) 40 | - [twitter/azu_re](https://twitter.com/azu_re) 41 | 42 | ## License 43 | 44 | MIT © azu 45 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/src/type.ts: -------------------------------------------------------------------------------- 1 | import { TextlintResult } from "@textlint/kernel"; 2 | 3 | export interface TextstatMessage { 4 | // See src/shared/type/MessageType.js 5 | // Message Type 6 | type: string; 7 | // Rule Id 8 | ruleId: string; 9 | message: string; 10 | // optional data 11 | data: { 12 | message: string; 13 | range: [number, number]; 14 | details: { 15 | name: string; 16 | value: any; 17 | }[]; 18 | }; 19 | // FixCommand is not defined in stat 20 | fix?: undefined; 21 | // location info 22 | // Text -> AST TxtNode(0-based columns) -> textlint -> TextlintMessage(**1-based columns**) 23 | line: number; // start with 1 24 | column: number; // start with 1 25 | // indexed-location 26 | index: number; // start with 0 27 | // Severity Level 28 | // See src/shared/type/SeverityLevel.js 29 | severity: number; 30 | } 31 | 32 | export interface TextstatResult extends TextlintResult { 33 | filePath: string; 34 | messages: TextstatMessage[]; 35 | } 36 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/rule-context 2 | 3 | RuleContext for textstat. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/rule-context 10 | 11 | ## Usage 12 | 13 | - [ ] Write usage instructions 14 | 15 | ## Changelog 16 | 17 | See [Releases page](https://github.com/textlint/textstat/releases). 18 | 19 | ## Running tests 20 | 21 | Install devDependencies and Run `npm test`: 22 | 23 | npm i -d && npm test 24 | 25 | ## Contributing 26 | 27 | Pull requests and stars are always welcome. 28 | 29 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 30 | 31 | 1. Fork it! 32 | 2. Create your feature branch: `git checkout -b my-new-feature` 33 | 3. Commit your changes: `git commit -am 'Add some feature'` 34 | 4. Push to the branch: `git push origin my-new-feature` 35 | 5. Submit a pull request :D 36 | 37 | ## Author 38 | 39 | - [github/azu](https://github.com/azu) 40 | - [twitter/azu_re](https://twitter.com/azu_re) 41 | 42 | ## License 43 | 44 | MIT © azu 45 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-tester 2 | 3 | Test framework for textstat rules. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-tester 10 | 11 | ## Usage 12 | 13 | - [ ] Write usage instructions 14 | 15 | ## Changelog 16 | 17 | See [Releases page](https://github.com/textlint/textstat/releases). 18 | 19 | ## Running tests 20 | 21 | Install devDependencies and Run `npm test`: 22 | 23 | npm i -d && npm test 24 | 25 | ## Contributing 26 | 27 | Pull requests and stars are always welcome. 28 | 29 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 30 | 31 | 1. Fork it! 32 | 2. Create your feature branch: `git checkout -b my-new-feature` 33 | 3. Commit your changes: `git commit -am 'Add some feature'` 34 | 4. Push to the branch: `git push origin my-new-feature` 35 | 5. Submit a pull request :D 36 | 37 | ## Author 38 | 39 | - [github/azu](https://github.com/azu) 40 | - [twitter/azu_re](https://twitter.com/azu_re) 41 | 42 | ## License 43 | 44 | MIT © azu 45 | -------------------------------------------------------------------------------- /packages/textstat/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-preset-standard 2 | 3 | Standard Presets. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-preset-standard 10 | 11 | ## Usage 12 | 13 | - [ ] Write usage instructions 14 | 15 | ## Changelog 16 | 17 | See [Releases page](https://github.com/textlint/textstat/releases). 18 | 19 | ## Running tests 20 | 21 | Install devDependencies and Run `npm test`: 22 | 23 | npm i -d && npm test 24 | 25 | ## Contributing 26 | 27 | Pull requests and stars are always welcome. 28 | 29 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 30 | 31 | 1. Fork it! 32 | 2. Create your feature branch: `git checkout -b my-new-feature` 33 | 3. Commit your changes: `git commit -am 'Add some feature'` 34 | 4. Push to the branch: `git push origin my-new-feature` 35 | 5. Submit a pull request :D 36 | 37 | ## Author 38 | 39 | - [github/azu](https://github.com/azu) 40 | - [twitter/azu_re](https://twitter.com/azu_re) 41 | 42 | ## License 43 | 44 | MIT © azu 45 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/LICENSE: -------------------------------------------------------------------------------- 1 | Copyright (c) 2018 azu 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy 4 | of this software and associated documentation files (the "Software"), to deal 5 | in the Software without restriction, including without limitation the rights 6 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 7 | copies of the Software, and to permit persons to whom the Software is 8 | furnished to do so, subject to the following conditions: 9 | 10 | The above copyright notice and this permission notice shall be included in all 11 | copies or substantial portions of the Software. 12 | 13 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 14 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 15 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 16 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 17 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 18 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 19 | SOFTWARE. 20 | -------------------------------------------------------------------------------- /packages/textstat/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | **Note:** Version bump only for package textstat 9 | 10 | 11 | 12 | 13 | 14 | ## [0.7.1](https://github.com/textlint/textstat/compare/v0.7.0...v0.7.1) (2018-12-13) 15 | 16 | 17 | ### Bug Fixes 18 | 19 | * **textstat:** fix return value ([634efe3](https://github.com/textlint/textstat/commit/634efe3)) 20 | 21 | 22 | 23 | 24 | 25 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 26 | 27 | 28 | ### Bug Fixes 29 | 30 | * **stat:** fix test ([c47c6bf](https://github.com/textlint/textstat/commit/c47c6bf)) 31 | 32 | 33 | ### Features 34 | 35 | * **textstat:** add index to textstat ([dcb751a](https://github.com/textlint/textstat/commit/dcb751a)) 36 | 37 | 38 | 39 | 40 | 41 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 42 | 43 | **Note:** Version bump only for package textstat 44 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/test/Localize-test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from "assert"; 2 | import { Localize } from "../src"; 3 | 4 | const messages = { 5 | simple: { 6 | en: "message", 7 | ja: "メッセージ" 8 | }, 9 | template: "index is {{index}}" 10 | }; 11 | describe("Localize", function() { 12 | it("should return en message by default", () => { 13 | const { t } = new Localize(messages); 14 | assert.strictEqual(t("simple"), messages.simple.en); 15 | }); 16 | it("should return ja message for ja-JP", () => { 17 | const { t } = new Localize(messages, "ja-JP"); 18 | assert.strictEqual(t("simple"), messages.simple.ja); 19 | }); 20 | it("should return js message by locale option", () => { 21 | const { t } = new Localize(messages, "ja"); 22 | assert.strictEqual(t("simple"), messages.simple.ja); 23 | }); 24 | it("should return template message ", () => { 25 | const { t } = new Localize(messages); 26 | assert.strictEqual( 27 | t("template", { 28 | index: 10 29 | }), 30 | `index is 10` 31 | ); 32 | }); 33 | }); 34 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/components/DocumentDependencyView/DocumentDependencyView.tsx: -------------------------------------------------------------------------------- 1 | import React from "react"; 2 | import Plot from "react-plotly.js"; 3 | import { DocumentDependencyViewProps, generateGraphData } from "./generate"; 4 | 5 | export function DocumentDependencyView(props: DocumentDependencyViewProps) { 6 | const { nodes, source, target, value } = generateGraphData(props); 7 | const trace = { 8 | type: "sankey", 9 | orientation: "h", 10 | node: { 11 | pad: 10, 12 | thickness: 30, 13 | line: { 14 | color: "black", 15 | width: 4 16 | }, 17 | label: nodes.map(node => node.name) 18 | }, 19 | link: { 20 | source: source, 21 | target: target, 22 | value: value 23 | } 24 | }; 25 | return ( 26 | 37 | ); 38 | } 39 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: {}, 7 | messages: { 8 | message: { 9 | en: "Number of links in the document", 10 | ja: "ドキュメント中のリンク数" 11 | }, 12 | "Number of Links": { 13 | en: "Number of Links", 14 | ja: "リンク数" 15 | } 16 | } 17 | }; 18 | export const report: TextstatRuleReporter = function(context, _options, deps) { 19 | const { Syntax, report } = context; 20 | const { t } = new Localize(meta.messages, deps.locale); 21 | let count = 0; 22 | return { 23 | [Syntax.Document]() { 24 | count = 0; 25 | }, 26 | [Syntax.Link]() { 27 | count++; 28 | }, 29 | [Syntax.Document + ":exit"](node) { 30 | report(node, { 31 | range: node.range, 32 | message: t("message"), 33 | details: [ 34 | { 35 | name: t("Number of Links"), 36 | value: count 37 | } 38 | ] 39 | }); 40 | } 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: {}, 7 | messages: { 8 | message: { 9 | en: "Number of images in the document", 10 | ja: "ドキュメント中の画像数" 11 | }, 12 | "Number of images": { 13 | en: "Number of images", 14 | ja: "画像数" 15 | } 16 | } 17 | }; 18 | export const report: TextstatRuleReporter = function(context, _options, deps) { 19 | const { Syntax, report } = context; 20 | const { t } = new Localize(meta.messages, deps.locale); 21 | let count = 0; 22 | return { 23 | [Syntax.Document]() { 24 | count = 0; 25 | }, 26 | [Syntax.Image]() { 27 | count++; 28 | }, 29 | [Syntax.Document + ":exit"](node) { 30 | report(node, { 31 | range: node.range, 32 | message: t("message"), 33 | details: [ 34 | { 35 | name: t("Number of images"), 36 | value: count 37 | } 38 | ] 39 | }); 40 | } 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/test/rule/textstat-rule-example.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: { 7 | description: "example rule", 8 | homepage: "https://github.com/textlint/textstat" 9 | }, 10 | messages: { 11 | message: { 12 | en: "Number of characters of the document", 13 | ja: "ドキュメントの文字数" 14 | }, 15 | "Number of characters": { 16 | en: "Number of characters", 17 | ja: "ドキュメントの文字数" 18 | } 19 | } 20 | }; 21 | 22 | export const report: TextstatRuleReporter = function(context, _options, deps) { 23 | const { Syntax, report, getSource } = context; 24 | const { t } = new Localize(meta.messages, deps.locale); 25 | return { 26 | [Syntax.Document](node) { 27 | const text = getSource(node); 28 | report(node, { 29 | message: t("message"), 30 | range: node.range, 31 | details: [ 32 | { 33 | name: t("Number of characters"), 34 | value: text.length 35 | } 36 | ] 37 | }); 38 | } 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-filesize 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-filesize 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/filesize": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/filesize README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: {}, 7 | messages: { 8 | message: { 9 | en: "Number of characters in the document", 10 | ja: "ドキュメント中の文字数" 11 | }, 12 | "Number of characters": { 13 | en: "Number of characters", 14 | ja: "文字数" 15 | } 16 | } 17 | }; 18 | export const report: TextstatRuleReporter = function(context, _options, deps) { 19 | const { Syntax, getSource, report } = context; 20 | const { t } = new Localize(meta.messages, deps.locale); 21 | return { 22 | [Syntax.Document](node) { 23 | const text = getSource(node); 24 | if (!text) { 25 | return; 26 | } 27 | const charactersCount = text.length; 28 | report(node, { 29 | message: t("message"), 30 | range: node.range, 31 | details: [ 32 | { 33 | name: t("Number of characters"), 34 | value: charactersCount 35 | } 36 | ] 37 | }); 38 | } 39 | }; 40 | }; 41 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: {}, 7 | messages: { 8 | message: { 9 | en: "Number of list items in the document", 10 | ja: "ドキュメント中の箇条書きの個数" 11 | }, 12 | "Number of list items": { 13 | en: "Number of list items", 14 | ja: "箇条書きの個数" 15 | } 16 | } 17 | }; 18 | export const report: TextstatRuleReporter = function(context, _options, deps) { 19 | const { Syntax, report } = context; 20 | const { t } = new Localize(meta.messages, deps.locale); 21 | let count = 0; 22 | return { 23 | [Syntax.Document]() { 24 | count = 0; 25 | }, 26 | [Syntax.ListItem]() { 27 | count++; 28 | }, 29 | [Syntax.Document + ":exit"](node) { 30 | report(node, { 31 | range: node.range, 32 | message: t("message"), 33 | details: [ 34 | { 35 | name: t("Number of list items"), 36 | value: count 37 | } 38 | ] 39 | }); 40 | } 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | 5 | export const meta = { 6 | docs: {}, 7 | messages: { 8 | message: { 9 | en: "Number of paragraphs in the document", 10 | ja: "ドキュメント中のパラグラフ数" 11 | }, 12 | "Number of paragraphs": { 13 | en: "Number of paragraphs", 14 | ja: "パラグラフ数" 15 | } 16 | } 17 | }; 18 | export const report: TextstatRuleReporter = function(context, _options, deps) { 19 | const { Syntax, report } = context; 20 | const { t } = new Localize(meta.messages, deps.locale); 21 | let count = 0; 22 | return { 23 | [Syntax.Document]() { 24 | count = 0; 25 | }, 26 | [Syntax.Paragraph]() { 27 | count++; 28 | }, 29 | [Syntax.Document + ":exit"](node) { 30 | report(node, { 31 | range: node.range, 32 | message: t("message"), 33 | details: [ 34 | { 35 | name: t("Number of paragraphs"), 36 | value: count 37 | } 38 | ] 39 | }); 40 | } 41 | }; 42 | }; 43 | -------------------------------------------------------------------------------- /tools/resources/textstat.readme.template: -------------------------------------------------------------------------------- 1 | # <%= name %> 2 | 3 | <%= description %> 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install <%= name %> 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "<%= name.replace("textstat-rule-", "") %>": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule <%= name.replace("textstat-rule-", "") %> README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](<%= bugs.url.replace(/\/issues$/, "") %>/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](<%= bugs.url %>). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | <%= license || licenses.join(', ') %> © <%= author.name %> 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-tateish-level 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-tateish-level 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/tateish-level": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/tateish-level README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-links 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-links 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-links": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-links README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-images 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-images 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-images": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-images README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-document-dependency 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-document-dependency 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/document-dependency": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/document-dependency README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-sentences 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-sentences 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-sentences": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-sentences README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-characters 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-characters 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-characters": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-characters README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-list-items 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-list-items 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-list-items": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-list-items README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat-rule-number-of-paragraphs 2 | 3 | Report file size 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/textstat-rule-number-of-paragraphs 10 | 11 | ## Usage 12 | 13 | Via `.textstatrc`(Recommended) 14 | 15 | ```json 16 | { 17 | "rules": { 18 | "@textstat/number-of-paragraphs": true 19 | } 20 | } 21 | ``` 22 | 23 | Via CLI 24 | 25 | ``` 26 | textlint --rule @textstat/number-of-paragraphs README.md 27 | ``` 28 | 29 | 30 | ## Changelog 31 | 32 | See [Releases page](https://github.com/textlint/textstat/releases). 33 | 34 | ## Running tests 35 | 36 | Install devDependencies and Run `npm test`: 37 | 38 | npm i -d && npm test 39 | 40 | ## Contributing 41 | 42 | Pull requests and stars are always welcome. 43 | 44 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 45 | 46 | 1. Fork it! 47 | 2. Create your feature branch: `git checkout -b my-new-feature` 48 | 3. Commit your changes: `git commit -am 'Add some feature'` 49 | 4. Push to the branch: `git push origin my-new-feature` 50 | 5. Submit a pull request :D 51 | 52 | ## Author 53 | 54 | - [github/azu](https://github.com/azu) 55 | - [twitter/azu_re](https://twitter.com/azu_re) 56 | 57 | ## License 58 | 59 | MIT © azu 60 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/to-non-cyclic 2 | 3 | Convert node list to non-cyclic node list. 4 | 5 | ## Install 6 | 7 | Install with [npm](https://www.npmjs.com/): 8 | 9 | npm install @textstat/to-non-cyclic 10 | 11 | ## Usage 12 | 13 | ```ts 14 | import { toNonCyclic } from "@textstat/to-non-cyclic" 15 | /** 16 | * Convert link node list to non-cyclic node list 17 | * If the node is cyclic, Add "[Cyclic]*" suffix to node's target 18 | * @param linkNodes 19 | */ 20 | export function toNonCyclic(linkNodes: T[]): T[]; 21 | ``` 22 | 23 | ## Changelog 24 | 25 | See [Releases page](https://github.com/textlint/textstat/releases). 26 | 27 | ## Running tests 28 | 29 | Install devDependencies and Run `npm test`: 30 | 31 | npm i -d && npm test 32 | 33 | ## Contributing 34 | 35 | Pull requests and stars are always welcome. 36 | 37 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 38 | 39 | 1. Fork it! 40 | 2. Create your feature branch: `git checkout -b my-new-feature` 41 | 3. Commit your changes: `git commit -am 'Add some feature'` 42 | 4. Push to the branch: `git push origin my-new-feature` 43 | 5. Submit a pull request :D 44 | 45 | ## Author 46 | 47 | - [github/azu](https://github.com/azu) 48 | - [twitter/azu_re](https://twitter.com/azu_re) 49 | 50 | ## License 51 | 52 | MIT © azu 53 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import * as fs from "fs"; 4 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 5 | 6 | // const fileSize = require("filesize"); 7 | export const meta = { 8 | docs: {}, 9 | messages: { 10 | message: { 11 | en: "File size", 12 | ja: "ドキュメントのファイルサイズ" 13 | }, 14 | "File size": { 15 | en: "File size", 16 | ja: "ファイルサイズ" 17 | } 18 | } 19 | }; 20 | 21 | export const report: TextstatRuleReporter = function(context, _options, deps) { 22 | const { Syntax, getFilePath, report } = context; 23 | const { t } = new Localize(meta.messages, deps.locale); 24 | return { 25 | [Syntax.Document](node) { 26 | const filePath = getFilePath(); 27 | if (!filePath) { 28 | return; 29 | } 30 | const stats = fs.statSync(filePath); 31 | const fileSizeInBytes = stats["size"]; 32 | report(node, { 33 | message: t("message"), 34 | range: node.range, 35 | details: [ 36 | { 37 | name: t("File size"), 38 | value: fileSizeInBytes 39 | } 40 | ] 41 | }); 42 | } 43 | }; 44 | }; 45 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * **view:** fix file name ([5d3b34d](https://github.com/textlint/textstat/commit/5d3b34d)) 12 | * **view:** fix name ([dc39e1c](https://github.com/textlint/textstat/commit/dc39e1c)) 13 | * **view:** simplify dependency condition ([5a8140a](https://github.com/textlint/textstat/commit/5a8140a)) 14 | 15 | 16 | ### Features 17 | 18 | * **view:** add FileSize view ([16345af](https://github.com/textlint/textstat/commit/16345af)) 19 | * **view:** add textstat-rule-number-of-characters ([e2e7e5f](https://github.com/textlint/textstat/commit/e2e7e5f)) 20 | * **view:** call unregister ([c401752](https://github.com/textlint/textstat/commit/c401752)) 21 | * **view:** reverse option ([51b3715](https://github.com/textlint/textstat/commit/51b3715)) 22 | * **view:** support gist? query parameter ([14fb8e7](https://github.com/textlint/textstat/commit/14fb8e7)) 23 | 24 | 25 | 26 | 27 | 28 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 29 | 30 | 31 | ### Bug Fixes 32 | 33 | * **view:** update title ([47bdf4c](https://github.com/textlint/textstat/commit/47bdf4c)) 34 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/pages/index.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { createPage, createSwitch } from "navi"; 3 | 4 | export default createSwitch({ 5 | paths: { 6 | "/": createPage({ 7 | title: "textstat-viewer", 8 | content: ( 9 |
10 |
    11 |
      Fill "State" with JSON string of textstat
    12 |
      Select a view from menu sidebar
    13 |
14 |

Also support ?gist=gistID

15 |

16 | Example: 17 | 18 | https://textstat-viewer.netlify.com/?gist=3216e61067d0239ed0fd71af0af18fe3 19 | 20 |

21 |
22 | ) 23 | }), 24 | "/textstat-rule-document-dependency": createPage({ 25 | title: "textstat-rule-document-dependency", 26 | getContent: () => import("./textstat-rule-document-dependency") 27 | }), 28 | "/textstat-rule-number-of-characters": createPage({ 29 | title: "textstat-rule-number-of-characters", 30 | getContent: () => import("./textstat-rule-number-of-characters") 31 | }) 32 | } 33 | }); 34 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/src/textstat-rule-preset-standard.ts: -------------------------------------------------------------------------------- 1 | export function createPreset(_options = {}) { 2 | return { 3 | rules: { 4 | "textstat-rule-filesize": require("@textstat/textstat-rule-filesize"), 5 | "textstat-rule-document-dependency": require("@textstat/textstat-rule-document-dependency"), 6 | "textstat-rule-number-of-characters": require("@textstat/textstat-rule-number-of-characters"), 7 | "textstat-rule-number-of-images": require("@textstat/textstat-rule-number-of-images"), 8 | "textstat-rule-number-of-links": require("@textstat/textstat-rule-number-of-links"), 9 | "textstat-rule-number-of-list-items": require("@textstat/textstat-rule-number-of-list-items"), 10 | "textstat-rule-number-of-paragraphs": require("@textstat/textstat-rule-number-of-paragraphs"), 11 | "textstat-rule-number-of-sentences": require("@textstat/textstat-rule-number-of-sentences") 12 | }, 13 | rulesConfig: { 14 | "textstat-rule-filesize": true, 15 | "textstat-rule-document-dependency": true, 16 | "textstat-rule-number-of-characters": true, 17 | "textstat-rule-number-of-images": true, 18 | "textstat-rule-number-of-links": true, 19 | "textstat-rule-number-of-list-items": true, 20 | "textstat-rule-number-of-paragraphs": true, 21 | "textstat-rule-number-of-sentences": true 22 | } 23 | }; 24 | } 25 | -------------------------------------------------------------------------------- /tools/add-new-rule.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # variable 3 | declare scriptDir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) 4 | declare currentDir=$(pwd) 5 | declare dirName=$(basename "${currentDir}") 6 | declare currentDirName=$(basename "${currentDir}") 7 | 8 | # dependecy script 9 | # https://github.com/zeke/npe 10 | if !type npe >/dev/null 2>&1; then 11 | npm install npe --global 12 | fi 13 | sh ${scriptDir}/node.js.sh 14 | 15 | function echo_message(){ 16 | echo "\033[31m=>\033[0m \033[036m$1\033[0m" 17 | } 18 | # Install 19 | echo_message "npm install" 20 | yarn add --dev --pure-lockfile \ 21 | typescript \ 22 | mocha \ 23 | @types/node \ 24 | @types/mocha \ 25 | cross-env \ 26 | ts-node 27 | 28 | sh ${scriptDir}/add-prettier.sh 29 | 30 | # Copy config 31 | echo_message "Copy .tsconfig.json" 32 | cp ${scriptDir}/resources/tsconfig.json ./ 33 | cp ${scriptDir}/resources/test.tsconfig.json ./test/tsconfig.json 34 | cp ${scriptDir}/resources/typescript.mocha.opts ./test/mocha.opts 35 | # Edit package.json 36 | ## Add script 37 | echo_message "Add npm run-script" 38 | npe scripts.build "cross-env NODE_ENV=production tsc --build" 39 | npe scripts.watch "tsc --build --watch" 40 | npe scripts.prepublish "npm run --if-present build" 41 | npe scripts.test "mocha \"test/**/*.ts\"" 42 | npe main "lib/${currentDirName}/src/index.js" 43 | npe types "lib/${currentDirName}/src/index.d.ts" 44 | sort-package-json 45 | # create README 46 | rm README.md 47 | pkg-to-readme --template "${scriptDir}/resources/textstat.readme.template" -o ./README.md 48 | # git 49 | git add . 50 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "author": "azu", 3 | "license": "MIT", 4 | "name": "textstat", 5 | "version": "1.0.0", 6 | "description": "textstat analyze text and summarize data.", 7 | "scripts": { 8 | "clean": "lerna run clean && lerna clean --yes", 9 | "test": "lerna run test", 10 | "updateSnapshot": "UPDATE_SNAPSHOT=1 lerna run test", 11 | "build": "lerna run build --ignore @textstat/textstat-view", 12 | "netlify": "lerna run build --scope @textstat/textstat-view", 13 | "bootstrap": "lerna bootstrap && yarn run build", 14 | "publish": "lerna publish --conventional-commits", 15 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"" 16 | }, 17 | "keywords": [ 18 | "textlint", 19 | "textstat" 20 | ], 21 | "private": true, 22 | "devDependencies": { 23 | "husky": "^1.3.1", 24 | "lerna": "^3.13.1", 25 | "lint-staged": "^8.1.4", 26 | "prettier": "^1.16.4" 27 | }, 28 | "prettier": { 29 | "printWidth": 120, 30 | "tabWidth": 4 31 | }, 32 | "lint-staged": { 33 | "*.{js,jsx,ts,tsx,css}": [ 34 | "prettier --write", 35 | "git add" 36 | ] 37 | }, 38 | "workspaces": { 39 | "packages": [ 40 | "packages/*", 41 | "packages/@textstat/*" 42 | ], 43 | "nohoist": [ 44 | "**/@types/mocha", 45 | "**/@types/mocha/**", 46 | "**/@types/jest", 47 | "**/@types/jest/**" 48 | ] 49 | }, 50 | "husky": { 51 | "hooks": { 52 | "post-commit": "git reset", 53 | "pre-commit": "lint-staged" 54 | } 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/pages/textstat-rule-document-dependency.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import { StatContext } from "../context/StatContext"; 3 | import { DocumentDependencyView } from "../components/DocumentDependencyView/DocumentDependencyView"; 4 | 5 | export class TextstatRuleDocumentDependency extends React.Component { 6 | state = { 7 | reverse: false 8 | }; 9 | 10 | private onChangeCheckbox = () => { 11 | this.setState({ 12 | reverse: !this.state.reverse 13 | }); 14 | }; 15 | 16 | render() { 17 | return ( 18 | 19 | {({ results }) => { 20 | return ( 21 |
22 | 28 | 29 | 30 |
31 | ); 32 | }} 33 |
34 | ); 35 | } 36 | } 37 | 38 | export default function() { 39 | return ; 40 | } 41 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/src/index.ts: -------------------------------------------------------------------------------- 1 | // LICENSE : MIT 2 | "use strict"; 3 | import { Localize, TextstatRuleReporter } from "@textstat/rule-context"; 4 | import { splitAST, Syntax as SentenceSyntax } from "sentence-splitter"; 5 | 6 | export const meta = { 7 | docs: {}, 8 | messages: { 9 | message: { 10 | en: "Number of sentences in the document", 11 | ja: "ドキュメント中のセンテンス数" 12 | }, 13 | "Number of sentences": { 14 | en: "Number of sentences", 15 | ja: "センテンス数" 16 | } 17 | } 18 | }; 19 | export const report: TextstatRuleReporter = function(context, _options, deps) { 20 | const { Syntax, report } = context; 21 | const { t } = new Localize(meta.messages, deps.locale); 22 | let count = 0; 23 | return { 24 | [Syntax.Document]() { 25 | count = 0; 26 | }, 27 | [Syntax.Paragraph](node) { 28 | const sentences = splitAST(node as any).children.filter(node => { 29 | return node.type === SentenceSyntax.Sentence; 30 | }); 31 | count += sentences.length; 32 | }, 33 | [Syntax.Document + ":exit"](node) { 34 | report(node, { 35 | range: node.range, 36 | message: t("message"), 37 | details: [ 38 | { 39 | name: t("Number of sentences"), 40 | value: count 41 | } 42 | ] 43 | }); 44 | } 45 | }; 46 | }; 47 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/AppMenu.tsx: -------------------------------------------------------------------------------- 1 | import { NavConsumer, NavLink } from "react-navi"; 2 | import classnames from "classnames"; 3 | import * as React from "react"; 4 | import "./AppMenu.css"; 5 | 6 | export const AppMenu = () => { 7 | const menus = [ 8 | { 9 | title: "Top", 10 | path: "/" 11 | }, 12 | { 13 | title: "Number of characters", 14 | path: "/textstat-rule-number-of-characters/" 15 | }, 16 | { 17 | title: "document-dependency", 18 | path: "/textstat-rule-document-dependency/" 19 | } 20 | ]; 21 | return ( 22 | 23 | {({ url }) => { 24 | return ( 25 |
    26 | {menus.map(menu => { 27 | const isCurrentPath = url.pathname == menu.path; 28 | return ( 29 |
  • 35 | {menu.title} 36 |
  • 37 | ); 38 | })} 39 |
40 | ); 41 | }} 42 |
43 | ); 44 | }; 45 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/to-non-cyclic", 3 | "version": "0.8.0", 4 | "description": "Convert node list to non-cyclic node list.", 5 | "keywords": [ 6 | "util" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/to-non-cyclic/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/to-non-cyclic.js", 20 | "types": "lib/to-non-cyclic.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc -p .", 31 | "clean": "rimraf lib/", 32 | "prepublish": "npm run --if-present build", 33 | "test": "mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc -p . --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "devDependencies": { 43 | "@types/mocha": "^5.2.6", 44 | "@types/node": "^11.9.6", 45 | "cross-env": "^5.2.0", 46 | "mocha": "^6.0.2", 47 | "prettier": "^1.16.4", 48 | "rimraf": "^2.6.3", 49 | "ts-node": "^8.0.2", 50 | "ts-node-test-register": "^8.0.0", 51 | "typescript": "^3.3.3333" 52 | }, 53 | "publishConfig": { 54 | "access": "public" 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/rule-context", 3 | "version": "0.8.0", 4 | "description": "RuleContext for textstat.", 5 | "keywords": [ 6 | "textstat" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/rule-context/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 33 | "watch": "tsc --build --watch" 34 | }, 35 | "prettier": { 36 | "printWidth": 120, 37 | "tabWidth": 4 38 | }, 39 | "dependencies": { 40 | "@textlint/kernel": "^3.1.4", 41 | "lodash.template": "^4.4.0" 42 | }, 43 | "devDependencies": { 44 | "@types/lodash.template": "^4.4.4", 45 | "@types/mocha": "^5.2.6", 46 | "@types/node": "^11.9.6", 47 | "cross-env": "^5.1.3", 48 | "mocha": "^6.0.2", 49 | "prettier": "^1.16.4", 50 | "ts-node": "^8.0.2", 51 | "ts-node-test-register": "^8.0.0", 52 | "typescript": "^3.3.3333" 53 | }, 54 | "publishConfig": { 55 | "access": "public" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/kernel", 3 | "version": "0.8.0", 4 | "description": "textstat kernel. Work browser and node.js", 5 | "keywords": [ 6 | "textstat" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/kernel/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 34 | "watch": "tsc --build --watch" 35 | }, 36 | "prettier": { 37 | "printWidth": 120, 38 | "tabWidth": 4 39 | }, 40 | "dependencies": { 41 | "@textlint/kernel": "^3.1.4" 42 | }, 43 | "devDependencies": { 44 | "@textlint/textlint-plugin-markdown": "^5.0.1", 45 | "@types/mocha": "^5.2.6", 46 | "@types/node": "^11.9.6", 47 | "cross-env": "^5.1.3", 48 | "mocha": "^6.0.2", 49 | "prettier": "^1.16.4", 50 | "ts-node": "^8.0.2", 51 | "ts-node-test-register": "^8.0.0", 52 | "typescript": "^3.3.3333" 53 | }, 54 | "publishConfig": { 55 | "access": "public" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/textstat/src/textstat.ts: -------------------------------------------------------------------------------- 1 | import * as fs from "fs"; 2 | import * as path from "path"; 3 | import { TextstatKernel } from "@textstat/kernel"; 4 | import { TextstatRulePreset } from "@textstat/rule-context"; 5 | import { createPreset } from "@textstat/textstat-rule-preset-standard"; 6 | import globby from "globby"; 7 | 8 | function createTextstatPresetToTextlintPreset(preset: TextstatRulePreset) { 9 | return Object.keys(preset.rules).map(key => { 10 | const rule = preset.rules[key]; 11 | return { 12 | ruleId: key, 13 | rule: rule, 14 | options: preset.rulesConfig[key] 15 | }; 16 | }); 17 | } 18 | 19 | export interface ReportOptions { 20 | locale: string; 21 | globPatterns: string[]; 22 | } 23 | 24 | export async function report(options: ReportOptions) { 25 | const fileList = await globby(options.globPatterns); 26 | const textstat = new TextstatKernel(); 27 | const promises = fileList.map((filePath: string) => { 28 | const text = fs.readFileSync(filePath, "utf-8"); 29 | return textstat.report(text, { 30 | filePath: filePath, 31 | ext: path.extname(filePath), 32 | rules: createTextstatPresetToTextlintPreset(createPreset()), 33 | plugins: [ 34 | { 35 | pluginId: "markdown", 36 | plugin: require("@textlint/textlint-plugin-markdown") 37 | } 38 | ], 39 | sharedDeps: { 40 | filePathList: fileList, 41 | locale: options.locale 42 | } 43 | }); 44 | }); 45 | return Promise.all(promises); 46 | } 47 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/test/snapshots/from-to-link/output.json: -------------------------------------------------------------------------------- 1 | { 2 | "messages": [ 3 | { 4 | "type": "lint", 5 | "ruleId": "textstat-rule-document-dependency", 6 | "message": "Dependency links in the document", 7 | "index": 0, 8 | "line": 1, 9 | "column": 1, 10 | "severity": 2, 11 | "data": { 12 | "message": "Dependency links in the document", 13 | "range": [ 14 | 0, 15 | 12 16 | ], 17 | "details": [ 18 | { 19 | "name": "To Links", 20 | "value": [ 21 | { 22 | "type": "document", 23 | "path": "/from-to-link/a.md" 24 | } 25 | ] 26 | }, 27 | { 28 | "name": "From Links", 29 | "value": [ 30 | { 31 | "type": "document", 32 | "path": "/from-to-link/a.md" 33 | }, 34 | { 35 | "type": "document", 36 | "path": "/from-to-link/b.md" 37 | } 38 | ] 39 | } 40 | ] 41 | } 42 | } 43 | ], 44 | "filePath": "/from-to-link/input.md" 45 | } -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-tester", 3 | "version": "0.8.0", 4 | "description": "Test framework for textstat rules.", 5 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-tester/", 6 | "bugs": { 7 | "url": "https://github.com/textlint/textstat/issues" 8 | }, 9 | "license": "MIT", 10 | "author": "azu", 11 | "files": [ 12 | "bin/", 13 | "lib/", 14 | "src/" 15 | ], 16 | "main": "lib/src/textstat-tester.js", 17 | "types": "lib/src/textstat-tester.d.ts", 18 | "directories": { 19 | "lib": "lib", 20 | "test": "test" 21 | }, 22 | "repository": { 23 | "type": "git", 24 | "url": "https://github.com/textlint/textstat.git" 25 | }, 26 | "scripts": { 27 | "build": "cross-env NODE_ENV=production tsc --build", 28 | "clean": "rimraf lib/", 29 | "prepublish": "npm run --if-present build", 30 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 31 | "watch": "tsc -p . --watch" 32 | }, 33 | "prettier": { 34 | "printWidth": 120, 35 | "singleQuote": false, 36 | "tabWidth": 4 37 | }, 38 | "dependencies": { 39 | "@textlint/textlint-plugin-markdown": "^5.1.4", 40 | "@textstat/kernel": "^0.8.0", 41 | "@textstat/rule-context": "^0.8.0" 42 | }, 43 | "devDependencies": { 44 | "@types/mocha": "^5.2.6", 45 | "@types/node": "^11.9.6", 46 | "cross-env": "^5.2.0", 47 | "mocha": "^6.0.2", 48 | "prettier": "^1.16.4", 49 | "rimraf": "^2.6.3", 50 | "ts-node": "^8.0.2", 51 | "ts-node-test-register": "^8.0.0", 52 | "typescript": "^3.3.3333" 53 | }, 54 | "publishConfig": { 55 | "access": "public" 56 | } 57 | } 58 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/README.md: -------------------------------------------------------------------------------- 1 | # @textstat/textstat 2 | 3 | textstat kernel. 4 | 5 | This kernel module is same position with [@textlint/kernel](https://github.com/textlint/textlint/tree/master/packages/%40textlint/kernel). 6 | 7 | ## Install 8 | 9 | Install with [npm](https://www.npmjs.com/): 10 | 11 | npm install @textstat/kernel 12 | 13 | ## Usage 14 | 15 | ```ts 16 | const kernel = new TextstatKernel(); 17 | const result = await kernel.report(`# Header 18 | 19 | This is example. 20 | `, { 21 | rules: [{ 22 | ruleId: "textstat-rule-example", 23 | rule: rule 24 | }], 25 | plugins: [{ 26 | pluginId: "markdown", 27 | plugin: require("@textlint/textlint-plugin-markdown") 28 | }], 29 | filterRules: [], 30 | sharedDeps: { 31 | filePathList: ["/path/to/example.md", "/path/to/example.a.md"] 32 | }, 33 | filePath: "/path/to/example.md", 34 | ext: ".md" 35 | }); 36 | ``` 37 | 38 | ## Changelog 39 | 40 | See [Releases page](https://github.com/textlint/textstat/releases). 41 | 42 | ## Running tests 43 | 44 | Install devDependencies and Run `npm test`: 45 | 46 | npm i -d && npm test 47 | 48 | ## Contributing 49 | 50 | Pull requests and stars are always welcome. 51 | 52 | For bugs and feature requests, [please create an issue](https://github.com/textlint/textstat/issues). 53 | 54 | 1. Fork it! 55 | 2. Create your feature branch: `git checkout -b my-new-feature` 56 | 3. Commit your changes: `git commit -am 'Add some feature'` 57 | 4. Push to the branch: `git push origin my-new-feature` 58 | 5. Submit a pull request :D 59 | 60 | ## Author 61 | 62 | - [github/azu](https://github.com/azu) 63 | - [twitter/azu_re](https://twitter.com/azu_re) 64 | 65 | ## License 66 | 67 | MIT © azu 68 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/public/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 12 | 13 | 22 | textstat-viewer 23 | 24 | 25 | 28 |
29 | 39 | 40 | 41 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-links/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-links", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-links/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0" 44 | }, 45 | "devDependencies": { 46 | "@textstat/textstat-tester": "^0.8.0", 47 | "@types/mocha": "^5.2.6", 48 | "@types/node": "^11.9.6", 49 | "cross-env": "^5.1.3", 50 | "mocha": "^6.0.2", 51 | "prettier": "^1.16.4", 52 | "ts-node": "^8.0.2", 53 | "ts-node-test-register": "^8.0.0", 54 | "typescript": "^3.3.3333" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-images/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-images", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-images/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0" 44 | }, 45 | "devDependencies": { 46 | "@textstat/textstat-tester": "^0.8.0", 47 | "@types/mocha": "^5.2.6", 48 | "@types/node": "^11.9.6", 49 | "cross-env": "^5.1.3", 50 | "mocha": "^6.0.2", 51 | "prettier": "^1.16.4", 52 | "ts-node": "^8.0.2", 53 | "ts-node-test-register": "^8.0.0", 54 | "typescript": "^3.3.3333" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-filesize/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-filesize", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-filesize/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0", 44 | "filesize": "^3.5.11" 45 | }, 46 | "devDependencies": { 47 | "@textstat/textstat-tester": "^0.8.0", 48 | "@types/mocha": "^5.2.6", 49 | "@types/node": "^11.9.6", 50 | "cross-env": "^5.1.3", 51 | "mocha": "^6.0.2", 52 | "prettier": "^1.16.4", 53 | "ts-node": "^8.0.2", 54 | "ts-node-test-register": "^8.0.0", 55 | "typescript": "^3.3.3333" 56 | }, 57 | "publishConfig": { 58 | "access": "public" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-characters/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-characters", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-characters/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0" 44 | }, 45 | "devDependencies": { 46 | "@textstat/textstat-tester": "^0.8.0", 47 | "@types/mocha": "^5.2.6", 48 | "@types/node": "^11.9.6", 49 | "cross-env": "^5.1.3", 50 | "mocha": "^6.0.2", 51 | "prettier": "^1.16.4", 52 | "ts-node": "^8.0.2", 53 | "ts-node-test-register": "^8.0.0", 54 | "typescript": "^3.3.3333" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-list-items/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-list-items", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-list-items/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0" 44 | }, 45 | "devDependencies": { 46 | "@textstat/textstat-tester": "^0.8.0", 47 | "@types/mocha": "^5.2.6", 48 | "@types/node": "^11.9.6", 49 | "cross-env": "^5.1.3", 50 | "mocha": "^6.0.2", 51 | "prettier": "^1.16.4", 52 | "ts-node": "^8.0.2", 53 | "ts-node-test-register": "^8.0.0", 54 | "typescript": "^3.3.3333" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-paragraphs/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-paragraphs", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-paragraphs/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0" 44 | }, 45 | "devDependencies": { 46 | "@textstat/textstat-tester": "^0.8.0", 47 | "@types/mocha": "^5.2.6", 48 | "@types/node": "^11.9.6", 49 | "cross-env": "^5.1.3", 50 | "mocha": "^6.0.2", 51 | "prettier": "^1.16.4", 52 | "ts-node": "^8.0.2", 53 | "ts-node-test-register": "^8.0.0", 54 | "typescript": "^3.3.3333" 55 | }, 56 | "publishConfig": { 57 | "access": "public" 58 | } 59 | } 60 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-view", 3 | "version": "0.8.0", 4 | "private": true, 5 | "scripts": { 6 | "build": "react-scripts build", 7 | "build:navi": "cross-env REACT_APP_NAVI=true navi-scripts build", 8 | "eject": "react-scripts eject", 9 | "start": "react-scripts start", 10 | "test": "react-scripts test", 11 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"" 12 | }, 13 | "prettier": { 14 | "printWidth": 120, 15 | "singleQuote": false, 16 | "tabWidth": 4 17 | }, 18 | "eslintConfig": { 19 | "extends": "react-app" 20 | }, 21 | "dependencies": { 22 | "@textstat/to-non-cyclic": "^0.8.0", 23 | "@types/classnames": "^2.2.6", 24 | "@types/jest": "23.3.10", 25 | "@types/node": "10.12.12", 26 | "@types/react": "16.7.13", 27 | "@types/react-dom": "16.0.11", 28 | "classnames": "^2.2.6", 29 | "common-path-prefix": "^1.0.0", 30 | "navi": "^0.8.0", 31 | "plotly.js": "^1.45.0", 32 | "react": "^16.6.3", 33 | "react-dom": "^16.6.3", 34 | "react-navi": "^0.8.4", 35 | "react-plotly.js": "^2.3.0", 36 | "react-scripts": "2.1.1", 37 | "typescript": "3.3.3333" 38 | }, 39 | "devDependencies": { 40 | "@types/react-plotly.js": "^2.2.2", 41 | "cross-env": "^5.2.0", 42 | "husky": "^1.3.1", 43 | "lint-staged": "^8.1.4", 44 | "navi-scripts": "^0.8.0", 45 | "prettier": "^1.16.4" 46 | }, 47 | "browserslist": [ 48 | ">0.2%", 49 | "not dead", 50 | "not ie <= 11", 51 | "not op_mini all" 52 | ], 53 | "husky": { 54 | "hooks": { 55 | "precommit": "lint-staged" 56 | } 57 | }, 58 | "lint-staged": { 59 | "*.{js,jsx,ts,tsx,css}": [ 60 | "prettier --write", 61 | "git add" 62 | ] 63 | } 64 | } 65 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-document-dependency/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-document-dependency", 3 | "version": "0.8.0", 4 | "description": "Report document dependencies.", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-document-dependency/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 34 | "watch": "tsc --build --watch" 35 | }, 36 | "prettier": { 37 | "printWidth": 120, 38 | "singleQuote": false, 39 | "tabWidth": 4 40 | }, 41 | "dependencies": { 42 | "@textstat/rule-context": "^0.8.0", 43 | "is-url": "^1.2.4", 44 | "unist-util-visit": "^1.4.0" 45 | }, 46 | "devDependencies": { 47 | "@textstat/textstat-tester": "^0.8.0", 48 | "@types/mocha": "^5.2.6", 49 | "@types/node": "^11.9.6", 50 | "cross-env": "^5.1.3", 51 | "mocha": "^6.0.2", 52 | "node-glob": "^1.2.0", 53 | "prettier": "^1.16.4", 54 | "ts-node": "^8.0.2", 55 | "ts-node-test-register": "^8.0.0", 56 | "typescript": "^3.3.3333" 57 | }, 58 | "publishConfig": { 59 | "access": "public" 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-number-of-sentences/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-number-of-sentences", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-number-of-sentences/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textstat/rule-context": "^0.8.0", 44 | "sentence-splitter": "^3.0.11" 45 | }, 46 | "devDependencies": { 47 | "@textstat/textstat-tester": "^0.8.0", 48 | "@types/mocha": "^5.2.6", 49 | "@types/node": "^11.9.6", 50 | "cross-env": "^5.1.3", 51 | "mocha": "^6.0.2", 52 | "prettier": "^1.16.4", 53 | "ts-node": "^8.0.2", 54 | "ts-node-test-register": "^8.0.0", 55 | "typescript": "^3.3.3333" 56 | }, 57 | "publishConfig": { 58 | "access": "public" 59 | } 60 | } 61 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/src/report-type.ts: -------------------------------------------------------------------------------- 1 | import { TextlintRuleOptions } from "@textlint/kernel"; 2 | import RuleContext from "@textlint/kernel/lib/kernel/src/core/rule-context"; 3 | import FilterRuleContext from "@textlint/kernel/lib/kernel/src/core/filter-rule-context"; 4 | import { TxtNode, TxtNodeType } from "@textlint/kernel/lib/ast-node-types/src"; 5 | import { LocaleTag, LocalizeMessages } from "./Localize"; 6 | 7 | export type TextstatRuleSharedDependencies = { 8 | // locale for message 9 | // Default: en 10 | locale?: LocaleTag; 11 | // target to stat 12 | filePathList: string[]; 13 | // parser 14 | parser: { 15 | parse(text: string, ext: string): TxtNode; 16 | }; 17 | }; 18 | 19 | /** 20 | * Meta type 21 | */ 22 | export type TextstatRuleMeta = { 23 | docs: { 24 | homepage?: string; 25 | description?: string; 26 | }; 27 | messages: LocalizeMessages; 28 | }; 29 | 30 | export type TextstatRuleReporter = ( 31 | context: Readonly, 32 | options: TextlintRuleOptions, 33 | deps: TextstatRuleSharedDependencies 34 | ) => { [P in TxtNodeType]?: (node: TxtNode) => void | Promise }; 35 | 36 | export interface TextstatKernelRule { 37 | ruleId: string; 38 | rule: { 39 | meta: TextstatRuleMeta; 40 | report: TextstatRuleReporter; 41 | }; 42 | options?: TextlintRuleOptions | boolean; 43 | } 44 | 45 | export type TextstatFilterRuleReporter = ( 46 | context: Readonly, 47 | options: TextlintRuleOptions, 48 | deps: TextstatRuleSharedDependencies 49 | ) => { [P in TxtNodeType]?: (node: TxtNode) => void | Promise }; 50 | 51 | export interface TextstatKernelFilterRule { 52 | ruleId: string; 53 | rule: { 54 | meta: TextstatRuleMeta; 55 | report: TextstatFilterRuleReporter; 56 | }; 57 | options?: TextlintRuleOptions | boolean; 58 | } 59 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-tateishi-level/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-tateish-level", 3 | "version": "0.8.0", 4 | "description": "Report file size", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-tateish-level/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/index.js", 20 | "types": "lib/src/index.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "prepublish": "npm run --if-present build", 32 | "test": "mocha \"test/**/*.ts\"", 33 | "updateSnspshot": "cross-env UPDATE_SNAPSHOT=1 mocha \"test/**/*.ts\"", 34 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 35 | "watch": "tsc --build --watch" 36 | }, 37 | "prettier": { 38 | "printWidth": 120, 39 | "singleQuote": false, 40 | "tabWidth": 4 41 | }, 42 | "dependencies": { 43 | "@textlint/ast-node-types": "^4.2.1", 44 | "@textstat/rule-context": "^0.8.0", 45 | "sentence-splitter": "^3.0.11", 46 | "textlint-rule-helper": "^2.0.1" 47 | }, 48 | "devDependencies": { 49 | "@textstat/textstat-tester": "^0.8.0", 50 | "@types/mocha": "^5.2.6", 51 | "@types/node": "^11.9.6", 52 | "cross-env": "^5.1.3", 53 | "mocha": "^6.0.2", 54 | "prettier": "^1.16.4", 55 | "ts-node": "^8.0.2", 56 | "ts-node-test-register": "^8.0.0", 57 | "typescript": "^3.3.3333" 58 | }, 59 | "publishConfig": { 60 | "access": "public" 61 | } 62 | } 63 | -------------------------------------------------------------------------------- /packages/textstat/src/formatter/textstat-formatter-csv.ts: -------------------------------------------------------------------------------- 1 | import uniq from "lodash.uniq"; 2 | import { Parser } from "json2csv"; 3 | import { TextstatResult } from "@textstat/kernel"; 4 | 5 | const commonPathPrefix = require("common-path-prefix"); 6 | 7 | export function collectDetails(result: TextstatResult, prefix: string) { 8 | const fieldNames: string[] = []; 9 | const unwindFields: string[] = []; 10 | const details: any[] = []; 11 | result.messages.forEach(message => { 12 | message.data.details.forEach(item => { 13 | fieldNames.push(item.name); 14 | if (Array.isArray(item.value)) { 15 | unwindFields.push(item.name); 16 | } 17 | details.push({ 18 | filePath: result.filePath, 19 | displayPath: result.filePath.replace(prefix, ""), 20 | ruleId: message.ruleId, 21 | message: message.message, 22 | [item.name]: item.value 23 | }); 24 | }); 25 | }); 26 | return { 27 | fieldNames, 28 | unwindFields, 29 | details 30 | }; 31 | } 32 | 33 | export function format(results: TextstatResult[]) { 34 | let fieldNames: string[] = ["filePath", "displayPath", "ruleId", "message"]; 35 | let unwindFields: string[] = []; 36 | let details: any[] = []; 37 | const allFilePathList = results.map(result => result.filePath); 38 | const prefix = commonPathPrefix(allFilePathList); 39 | results.forEach(result => { 40 | const info = collectDetails(result, prefix); 41 | fieldNames = uniq(fieldNames.concat(info.fieldNames)); 42 | unwindFields = uniq(unwindFields.concat(info.unwindFields)); 43 | details = details.concat(info.details); 44 | }); 45 | const parser = new Parser({ 46 | fields: fieldNames, 47 | unwind: unwindFields 48 | }); 49 | return parser.parse(details); 50 | } 51 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore 2 | 3 | # Logs 4 | logs 5 | *.log 6 | 7 | # Runtime data 8 | pids 9 | *.pid 10 | *.seed 11 | 12 | # Directory for instrumented libs generated by jscoverage/JSCover 13 | lib-cov 14 | 15 | # Coverage directory used by tools like istanbul 16 | coverage 17 | 18 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 19 | .grunt 20 | 21 | # node-waf configuration 22 | .lock-wscript 23 | 24 | # Compiled binary addons (http://nodejs.org/api/addons.html) 25 | build/Release 26 | 27 | # Dependency directory 28 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 29 | node_modules 30 | 31 | # Debug log from npm 32 | npm-debug.log 33 | 34 | 35 | ### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore 36 | 37 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 38 | 39 | *.iml 40 | 41 | ## Directory-based project format: 42 | .idea/ 43 | # if you remove the above rule, at least ignore the following: 44 | 45 | # User-specific stuff: 46 | # .idea/workspace.xml 47 | # .idea/tasks.xml 48 | # .idea/dictionaries 49 | 50 | # Sensitive or high-churn files: 51 | # .idea/dataSources.ids 52 | # .idea/dataSources.xml 53 | # .idea/sqlDataSources.xml 54 | # .idea/dynamic.xml 55 | # .idea/uiDesigner.xml 56 | 57 | # Gradle: 58 | # .idea/gradle.xml 59 | # .idea/libraries 60 | 61 | # Mongo Explorer plugin: 62 | # .idea/mongoSettings.xml 63 | 64 | ## File-based project format: 65 | *.ipr 66 | *.iws 67 | 68 | ## Plugin-specific files: 69 | 70 | # IntelliJ 71 | out/ 72 | 73 | # mpeltonen/sbt-idea plugin 74 | .idea_modules/ 75 | 76 | # JIRA plugin 77 | atlassian-ide-plugin.xml 78 | 79 | # Crashlytics plugin (for Android Studio and IntelliJ) 80 | com_crashlytics_export_strings.xml 81 | crashlytics.properties 82 | crashlytics-build.properties 83 | 84 | 85 | packages/*/lib 86 | packages/@textstat/*/lib 87 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Change Log 2 | 3 | All notable changes to this project will be documented in this file. 4 | See [Conventional Commits](https://conventionalcommits.org) for commit guidelines. 5 | 6 | # [0.8.0](https://github.com/textlint/textstat/compare/v0.7.1...v0.8.0) (2018-12-18) 7 | 8 | 9 | ### Bug Fixes 10 | 11 | * **view:** fix file name ([5d3b34d](https://github.com/textlint/textstat/commit/5d3b34d)) 12 | * **view:** fix name ([dc39e1c](https://github.com/textlint/textstat/commit/dc39e1c)) 13 | * **view:** simplify dependency condition ([5a8140a](https://github.com/textlint/textstat/commit/5a8140a)) 14 | 15 | 16 | ### Features 17 | 18 | * **view:** add FileSize view ([16345af](https://github.com/textlint/textstat/commit/16345af)) 19 | * **view:** add textstat-rule-number-of-characters ([e2e7e5f](https://github.com/textlint/textstat/commit/e2e7e5f)) 20 | * **view:** call unregister ([c401752](https://github.com/textlint/textstat/commit/c401752)) 21 | * **view:** reverse option ([51b3715](https://github.com/textlint/textstat/commit/51b3715)) 22 | * **view:** support gist? query parameter ([14fb8e7](https://github.com/textlint/textstat/commit/14fb8e7)) 23 | 24 | 25 | 26 | 27 | 28 | ## [0.7.1](https://github.com/textlint/textstat/compare/v0.7.0...v0.7.1) (2018-12-13) 29 | 30 | 31 | ### Bug Fixes 32 | 33 | * **textstat:** fix return value ([634efe3](https://github.com/textlint/textstat/commit/634efe3)) 34 | 35 | 36 | 37 | 38 | 39 | # [0.7.0](https://github.com/textlint/textstat/compare/v0.6.2...v0.7.0) (2018-12-13) 40 | 41 | 42 | ### Bug Fixes 43 | 44 | * **stat:** fix test ([c47c6bf](https://github.com/textlint/textstat/commit/c47c6bf)) 45 | * **view:** update title ([47bdf4c](https://github.com/textlint/textstat/commit/47bdf4c)) 46 | 47 | 48 | ### Features 49 | 50 | * **textstat:** add index to textstat ([dcb751a](https://github.com/textlint/textstat/commit/dcb751a)) 51 | 52 | 53 | 54 | 55 | 56 | ## [0.6.2](https://github.com/textlint/textstat/compare/v0.6.1...v0.6.2) (2018-12-13) 57 | 58 | **Note:** Version bump only for package textstat 59 | -------------------------------------------------------------------------------- /packages/textstat/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "textstat", 3 | "version": "0.8.0", 4 | "description": "textstat is statistic engine for text documents.", 5 | "keywords": [ 6 | "textlint", 7 | "textstat" 8 | ], 9 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/textstat/", 10 | "bugs": { 11 | "url": "https://github.com/textlint/textstat/issues" 12 | }, 13 | "license": "MIT", 14 | "author": "azu", 15 | "files": [ 16 | "bin/", 17 | "lib/", 18 | "src/" 19 | ], 20 | "main": "lib/src/index.js", 21 | "types": "lib/src/index.d.ts", 22 | "bin": { 23 | "textstat": "bin/cmd.js" 24 | }, 25 | "directories": { 26 | "lib": "lib", 27 | "test": "test" 28 | }, 29 | "repository": { 30 | "type": "git", 31 | "url": "https://github.com/textlint/textstat.git" 32 | }, 33 | "scripts": { 34 | "build": "cross-env NODE_ENV=production tsc -p .", 35 | "clean": "rimraf lib/", 36 | "prepublish": "npm run --if-present build", 37 | "test": "mocha \"test/**/*.ts\"", 38 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 39 | "watch": "tsc -p . --watch" 40 | }, 41 | "prettier": { 42 | "printWidth": 120, 43 | "singleQuote": false, 44 | "tabWidth": 4 45 | }, 46 | "dependencies": { 47 | "@textstat/kernel": "^0.8.0", 48 | "@textstat/rule-context": "^0.8.0", 49 | "@textstat/textstat-rule-preset-standard": "^0.8.0", 50 | "@types/globby": "^8.0.0", 51 | "@types/json2csv": "^4.2.0", 52 | "@types/lodash.uniq": "^4.5.0", 53 | "common-path-prefix": "^1.0.0", 54 | "globby": "^8.0.1", 55 | "json2csv": "^4.2.1", 56 | "lodash.uniq": "^4.5.0", 57 | "meow": "^5.0.0", 58 | "os-locale": "^3.0.1" 59 | }, 60 | "devDependencies": { 61 | "@types/mocha": "^5.2.6", 62 | "@types/node": "^11.9.6", 63 | "cross-env": "^5.2.0", 64 | "mocha": "^6.0.2", 65 | "prettier": "^1.16.4", 66 | "rimraf": "^2.6.3", 67 | "ts-node": "^8.0.2", 68 | "ts-node-test-register": "^8.0.0", 69 | "typescript": "^3.3.3333" 70 | } 71 | } 72 | -------------------------------------------------------------------------------- /packages/@textstat/kernel/test/TextstatKernel-test.ts: -------------------------------------------------------------------------------- 1 | import * as assert from "assert"; 2 | import { TextstatKernel } from "../src/TextstatKernel"; 3 | import * as rule from "./rule/textstat-rule-example"; 4 | 5 | describe("@textstat/kernel", function() { 6 | it("work", async () => { 7 | const kernel = new TextstatKernel(); 8 | const result = await kernel.report( 9 | `# Header 10 | 11 | This is example. 12 | `, 13 | { 14 | rules: [ 15 | { 16 | ruleId: "textstat-rule-example", 17 | rule: rule 18 | } 19 | ], 20 | plugins: [ 21 | { 22 | pluginId: "markdown", 23 | plugin: require("@textlint/textlint-plugin-markdown") 24 | } 25 | ], 26 | filterRules: [], 27 | sharedDeps: { 28 | filePathList: ["/path/to/example.md", "/path/to/example.a.md"] 29 | }, 30 | filePath: "/path/to/example.md", 31 | ext: ".md" 32 | } 33 | ); 34 | assert.deepStrictEqual(result, { 35 | messages: [ 36 | { 37 | type: "lint", 38 | ruleId: "textstat-rule-example", 39 | message: "Number of characters of the document", 40 | index: 0, 41 | line: 1, 42 | column: 1, 43 | severity: 2, 44 | fix: undefined, 45 | data: { 46 | details: [ 47 | { 48 | name: "Number of characters", 49 | value: 27 50 | } 51 | ], 52 | message: "Number of characters of the document", 53 | range: [0, 27] 54 | } 55 | } 56 | ], 57 | filePath: "/path/to/example.md" 58 | }); 59 | }); 60 | }); 61 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-rule-preset-standard/package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "@textstat/textstat-rule-preset-standard", 3 | "version": "0.8.0", 4 | "description": "Standard Presets.", 5 | "keywords": [ 6 | "textstatrule" 7 | ], 8 | "homepage": "https://github.com/textlint/textstat/tree/master/packages/@textstat/textstat-rule-preset-standard/", 9 | "bugs": { 10 | "url": "https://github.com/textlint/textstat/issues" 11 | }, 12 | "license": "MIT", 13 | "author": "azu", 14 | "files": [ 15 | "bin/", 16 | "lib/", 17 | "src/" 18 | ], 19 | "main": "lib/src/textstat-rule-preset-standard.js", 20 | "types": "lib/src/textstat-rule-preset-standard.d.ts", 21 | "directories": { 22 | "lib": "lib", 23 | "test": "test" 24 | }, 25 | "repository": { 26 | "type": "git", 27 | "url": "https://github.com/textlint/textstat.git" 28 | }, 29 | "scripts": { 30 | "build": "cross-env NODE_ENV=production tsc --build", 31 | "clean": "rimraf lib/", 32 | "prepublish": "npm run --if-present build", 33 | "prettier": "prettier --write \"**/*.{js,jsx,ts,tsx,css}\"", 34 | "watch": "tsc --build --watch" 35 | }, 36 | "prettier": { 37 | "printWidth": 120, 38 | "singleQuote": false, 39 | "tabWidth": 4 40 | }, 41 | "dependencies": { 42 | "@textstat/textstat-rule-document-dependency": "^0.8.0", 43 | "@textstat/textstat-rule-filesize": "^0.8.0", 44 | "@textstat/textstat-rule-number-of-characters": "^0.8.0", 45 | "@textstat/textstat-rule-number-of-images": "^0.8.0", 46 | "@textstat/textstat-rule-number-of-links": "^0.8.0", 47 | "@textstat/textstat-rule-number-of-list-items": "^0.8.0", 48 | "@textstat/textstat-rule-number-of-paragraphs": "^0.8.0", 49 | "@textstat/textstat-rule-number-of-sentences": "^0.8.0" 50 | }, 51 | "devDependencies": { 52 | "@types/mocha": "^5.2.6", 53 | "@types/node": "^11.9.6", 54 | "cross-env": "^5.2.0", 55 | "mocha": "^6.0.2", 56 | "prettier": "^1.16.4", 57 | "rimraf": "^2.6.3", 58 | "ts-node": "^8.0.2", 59 | "ts-node-test-register": "^8.0.0", 60 | "typescript": "^3.3.3333" 61 | }, 62 | "publishConfig": { 63 | "access": "public" 64 | } 65 | } 66 | -------------------------------------------------------------------------------- /packages/@textstat/to-non-cyclic/src/to-non-cyclic.ts: -------------------------------------------------------------------------------- 1 | export interface LinkNode { 2 | source: string; 3 | target: string; 4 | } 5 | 6 | export function traverseLinkNodes(originLinkNode: T, targetLinkNodes: T[], nextLinkNode?: T) { 7 | const dupMap = new Map(); 8 | targetLinkNodes.forEach(targetLinkNode => { 9 | if (targetLinkNode === nextLinkNode) { 10 | return; 11 | } 12 | if (targetLinkNode === originLinkNode) { 13 | return; 14 | } 15 | // ?'s target is origin's source 16 | if (nextLinkNode && nextLinkNode.target === targetLinkNode.source) { 17 | // Add [Cyclic] suffix to the target node 18 | if (originLinkNode.source === targetLinkNode.target) { 19 | const count = dupMap.get(originLinkNode.source) || 0; 20 | targetLinkNode.target = originLinkNode.source + "[Cyclic]" + "*".repeat(count + 1); 21 | dupMap.set(originLinkNode.source, count + 1); 22 | return; 23 | } 24 | } 25 | // Dig next 26 | // A -> B --> ? 27 | if (!nextLinkNode && originLinkNode.target === targetLinkNode.source) { 28 | // ? is origin node 29 | // we should modify the node name? 30 | return traverseLinkNodes(originLinkNode, targetLinkNodes, targetLinkNode); 31 | } 32 | }); 33 | } 34 | 35 | /** 36 | * Convert link node list to non-cyclic node list 37 | * If the node is cyclic, Add "[Cyclic]*" suffix to node's target 38 | * @param linkNodes 39 | */ 40 | export function toNonCyclic(linkNodes: T[]): T[] { 41 | // remove cyclic close 42 | // A -> B, B -> A 43 | const flatLinkNodes = linkNodes.filter((linkNode, index) => { 44 | const forwardLinks = linkNodes.slice(index + 1); 45 | const circularLink = forwardLinks.filter(forwardLink => { 46 | return linkNode.source === forwardLink.target && linkNode.target === forwardLink.source; 47 | }); 48 | return circularLink.length === 0; 49 | }); 50 | flatLinkNodes.forEach(linkNode => { 51 | traverseLinkNodes(linkNode, flatLinkNodes); 52 | }); 53 | return flatLinkNodes; 54 | } 55 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/README.md: -------------------------------------------------------------------------------- 1 | This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app). 2 | 3 | ## Available Scripts 4 | 5 | In the project directory, you can run: 6 | 7 | ### `npm start` 8 | 9 | Runs the app in the development mode.
10 | Open [http://localhost:3000](http://localhost:3000) to view it in the browser. 11 | 12 | The page will reload if you make edits.
13 | You will also see any lint errors in the console. 14 | 15 | ### `npm test` 16 | 17 | Launches the test runner in the interactive watch mode.
18 | See the section about [running tests](https://facebook.github.io/create-react-app/docs/running-tests) for more information. 19 | 20 | ### `npm run build` 21 | 22 | Builds the app for production to the `build` folder.
23 | It correctly bundles React in production mode and optimizes the build for the best performance. 24 | 25 | The build is minified and the filenames include the hashes.
26 | Your app is ready to be deployed! 27 | 28 | See the section about [deployment](https://facebook.github.io/create-react-app/docs/deployment) for more information. 29 | 30 | ### `npm run eject` 31 | 32 | **Note: this is a one-way operation. Once you `eject`, you can’t go back!** 33 | 34 | If you aren’t satisfied with the build tool and configuration choices, you can `eject` at any time. This command will remove the single build dependency from your project. 35 | 36 | Instead, it will copy all the configuration files and the transitive dependencies (Webpack, Babel, ESLint, etc) right into your project so you have full control over them. All of the commands except `eject` will still work, but they will point to the copied scripts so you can tweak them. At this point you’re on your own. 37 | 38 | You don’t have to ever use `eject`. The curated feature set is suitable for small and middle deployments, and you shouldn’t feel obligated to use this feature. However we understand that this tool wouldn’t be useful if you couldn’t customize it when you are ready for it. 39 | 40 | ## Learn More 41 | 42 | You can learn more in the [Create React App documentation](https://facebook.github.io/create-react-app/docs/getting-started). 43 | 44 | To learn React, check out the [React documentation](https://reactjs.org/). 45 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/components/NumberOfCharactersView/NumberOfCharactersView.tsx: -------------------------------------------------------------------------------- 1 | import * as React from "react"; 2 | import Plot from "react-plotly.js"; 3 | import { trimCommonPrefix } from "../../helper/trim-common-prefix"; 4 | 5 | export interface FileSizeViewProps { 6 | results: { 7 | filePath: string; 8 | messages: { 9 | ruleId: string; 10 | data: { 11 | details: { 12 | name: string; 13 | value: number; 14 | }[]; 15 | }; 16 | }[]; 17 | }[]; 18 | } 19 | 20 | const ruleId = "textstat-rule-number-of-characters"; 21 | 22 | export function NumberOfCharactersView(props: FileSizeViewProps) { 23 | const labels = trimCommonPrefix( 24 | props.results.map(result => { 25 | return result.filePath; 26 | }) 27 | ); 28 | const values: number[] = []; 29 | props.results.forEach(result => { 30 | return result.messages.forEach(message => { 31 | if (message.ruleId !== ruleId) { 32 | return; 33 | } 34 | message.data.details.forEach(detail => { 35 | values.push(detail.value); 36 | }); 37 | }); 38 | }); 39 | return ( 40 | 73 | ); 74 | } 75 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/.gitignore: -------------------------------------------------------------------------------- 1 | # See https://help.github.com/articles/ignoring-files/ for more about ignoring files. 2 | 3 | # dependencies 4 | /node_modules 5 | /.pnp 6 | .pnp.js 7 | 8 | # testing 9 | /coverage 10 | 11 | # production 12 | /build 13 | 14 | # misc 15 | .DS_Store 16 | .env.local 17 | .env.development.local 18 | .env.test.local 19 | .env.production.local 20 | 21 | npm-debug.log* 22 | yarn-debug.log* 23 | yarn-error.log* 24 | ### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Node.gitignore 25 | 26 | # Logs 27 | logs 28 | *.log 29 | 30 | # Runtime data 31 | pids 32 | *.pid 33 | *.seed 34 | 35 | # Directory for instrumented libs generated by jscoverage/JSCover 36 | lib-cov 37 | 38 | # Coverage directory used by tools like istanbul 39 | coverage 40 | 41 | # Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) 42 | .grunt 43 | 44 | # node-waf configuration 45 | .lock-wscript 46 | 47 | # Compiled binary addons (http://nodejs.org/api/addons.html) 48 | build/Release 49 | 50 | # Dependency directory 51 | # https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git- 52 | node_modules 53 | 54 | # Debug log from npm 55 | npm-debug.log 56 | 57 | 58 | ### https://raw.github.com/github/gitignore/608690d6b9a78c2a003affc792e49a84905b3118/Global/JetBrains.gitignore 59 | 60 | # Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm 61 | 62 | *.iml 63 | 64 | ## Directory-based project format: 65 | .idea/ 66 | # if you remove the above rule, at least ignore the following: 67 | 68 | # User-specific stuff: 69 | # .idea/workspace.xml 70 | # .idea/tasks.xml 71 | # .idea/dictionaries 72 | 73 | # Sensitive or high-churn files: 74 | # .idea/dataSources.ids 75 | # .idea/dataSources.xml 76 | # .idea/sqlDataSources.xml 77 | # .idea/dynamic.xml 78 | # .idea/uiDesigner.xml 79 | 80 | # Gradle: 81 | # .idea/gradle.xml 82 | # .idea/libraries 83 | 84 | # Mongo Explorer plugin: 85 | # .idea/mongoSettings.xml 86 | 87 | ## File-based project format: 88 | *.ipr 89 | *.iws 90 | 91 | ## Plugin-specific files: 92 | 93 | # IntelliJ 94 | out/ 95 | 96 | # mpeltonen/sbt-idea plugin 97 | .idea_modules/ 98 | 99 | # JIRA plugin 100 | atlassian-ide-plugin.xml 101 | 102 | # Crashlytics plugin (for Android Studio and IntelliJ) 103 | com_crashlytics_export_strings.xml 104 | crashlytics.properties 105 | crashlytics-build.properties 106 | 107 | 108 | /lib 109 | -------------------------------------------------------------------------------- /tools/node.js.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # https://github.com/simonwhitaker/gibo 4 | if !type gibo >/dev/null 2>&1; then 5 | brew install gibo 6 | fi 7 | if !type licgen >/dev/null 2>&1; then 8 | gem install license-generator 9 | fi 10 | if !type init-package-json >/dev/null 2>&1; then 11 | npm install init-package-json --global 12 | fi 13 | if !type pkg-to-readme >/dev/null 2>&1; then 14 | npm install pkg-to-readme --global 15 | fi 16 | 17 | function echo_message(){ 18 | echo "\033[31m=>\033[0m \033[036m$1\033[0m" 19 | } 20 | 21 | # http://stackoverflow.com/questions/2180270/check-if-current-directory-is-a-git-repository 22 | declare insideGitRepo="$(git rev-parse --is-inside-work-tree 2>/dev/null)" 23 | declare scriptDir=$(cd $(dirname ${BASH_SOURCE:-$0}); pwd) 24 | declare currentDir=$(pwd) 25 | declare currentDirName=$(basename "$(pwd)") 26 | if [ "$insideGitRepo" ]; then 27 | declare branchName=$(git rev-parse --abbrev-ref HEAD) 28 | declare relativePathFromRoot=$(git rev-parse --show-prefix) 29 | # 必須な変数 30 | declare rootDir=$(git rev-parse --show-toplevel) 31 | declare rootDirName=$(basename "${rootDir}") 32 | declare parentDirName=$(basename $(dirname "${rootDir}")) 33 | declare repo="${parentDirName}/${rootDirName}" 34 | # github.com/repo/tree/branch/path 35 | declare homepage="${parentDirName}/${rootDirName}/tree/master/${relativePathFromRoot}" 36 | else 37 | # 必須な変数 38 | declare rootDir=currentDir 39 | declare rootDirName=$(basename "${currentDir}") 40 | declare parentDirName=$(basename $(dirname "${currentDir}")) 41 | # user/name 42 | declare repo="${parentDirName}/${rootDirName}" 43 | # homepage - monorepoだと異なるので別変数 44 | declare homepage="${parentDirName}/${rootDirName}" 45 | fi 46 | 47 | if [ "$insideGitRepo" ]; then 48 | echo_message "Already exist .git - monorepo mode" 49 | else 50 | echo_message "Create .git" 51 | # init 52 | git init 53 | gibo Node JetBrains >> .gitignore 54 | echo "/lib" >> .gitignore 55 | # Travis CI 56 | cp ${scriptDir}/resources/node.travis.yml ./.travis.yml 57 | fi 58 | # License 59 | licgen MIT azu 60 | # create dir 61 | mkdir test 62 | mkdir lib 63 | mkdir src 64 | # create package.json 65 | cp ${scriptDir}/resources/package.json ./package.json 66 | 67 | echo "SCOPE: ${NPM_SCOPE}" 68 | if [[ -z "${NPM_SCOPE}" ]]; then 69 | npm init 70 | else 71 | npm init --scope="${NPM_SCOPE}" 72 | fi 73 | # main entry 74 | echo_message "Modify main entry point" 75 | npe repository.type "git" 76 | npe repository.url "https://github.com/${repo}.git" 77 | npe bugs.url "https://github.com/${repo}/issues" 78 | npe homepage "https://github.com/${homepage}" 79 | npe files "src/, lib/, bin/" 80 | npe main "lib/${currentDirName}.js" 81 | sort-package-json 82 | # git 83 | git add . 84 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # textstat 2 | 3 | textstat analyze text and summarize data. 4 | 5 | textstat is related project of [textlint](https://github.com/textlint/textlint "textlint"). 6 | 7 | ## Installation 8 | 9 | npm install @textstat/textstat 10 | 11 | ## Usage 12 | 13 | - [ ] Write usage instructions 14 | 15 | ## UseCase 16 | 17 | - Implement advice engine 18 | - context-dependent 19 | - Paragraph Writing advice engine 20 | - text mining 21 | - Counting 22 | - Sentence 23 | - Paragraph 24 | - Word 25 | - Image 26 | - List 27 | - Code 28 | - Length 29 | 30 | 31 | ### 分類 32 | 33 | Show result for each node 34 | 35 | - Document 36 | - Section 37 | - Paragraph 38 | - Sentence 39 | - Word? 40 | 41 | それぞれのViewで表現方法が異なる 42 | 43 | - [小説推敲補助ソフト「Novel Supporter」 - クロノス・クラウン -](https://crocro.com/pc/soft/novel_supporter/) 44 | - Documentはcompose可能 45 | - Sectionはサイドバーへ 46 | - Paragraphはドキュメント上へ 47 | - Inlineはドキュメント上へ 48 | 49 | ## その他 50 | 51 | > 照応 省略 解析、 52 | 53 | - 省略を発見する 54 | - 文章のつながりの滑らかを評価する 55 | - 範囲を強調表示する 56 | - 関連付け 57 | 58 | ## Abstract 59 | 60 | Process 61 | 62 | - Map **Data** to **Range** of the **Document**. 63 | 64 | View format 65 | 66 | - Show **Data** of **Range** of the **Document**. 67 | 68 | Output 69 | 70 | - HTML(Popup data) 71 | - Text(Group by **Range**) 72 | 73 | ## View Format 74 | 75 | - https://crocro.com/pc/soft/novel_supporter/manual/doc-tool-warn_text.html 76 | - range 77 | - color 78 | - underline 79 | - displayName 80 | - displayPosition: "after" 81 | 82 | ## Needs 83 | 84 | - TxtAST to MDAST to HAST to HTML 85 | - [syntax-tree/mdast-util-to-hast: Transform MDAST to HAST](https://github.com/syntax-tree/mdast-util-to-hast "syntax-tree/mdast-util-to-hast: Transform MDAST to HAST") 86 | - [syntax-tree/hast-util-to-html: Transform HAST to HTML](https://github.com/syntax-tree/hast-util-to-html "syntax-tree/hast-util-to-html: Transform HAST to HTML") 87 | - [render-markdown-with-position/markdown-to-html.js at master · azu/render-markdown-with-position](https://github.com/azu/render-markdown-with-position/blob/master/lib/markdown-to-html.js "render-markdown-with-position/markdown-to-html.js at master · azu/render-markdown-with-position") 88 | - With AST point 89 | 90 | ## Development 91 | 92 | yarn install 93 | yarn bootstrap 94 | 95 | ## Tests 96 | 97 | yarn test 98 | 99 | ## Architecture 100 | 101 | - Load `textstat-rule-*` 102 | - Process text by [@textlint/kernel](https://github.com/textlint/textlint/tree/master/packages/%40textlint/kernel "@textlint/kernel") 103 | - Format results 104 | - Output statistics 105 | 106 | ## Contributing 107 | 108 | 1. Fork it! 109 | 2. Create your feature branch: `git checkout -b my-new-feature` 110 | 3. Commit your changes: `git commit -am 'Add some feature'` 111 | 4. Push to the branch: `git push origin my-new-feature` 112 | 5. Submit a pull request :D 113 | 114 | ## License 115 | 116 | MIT 117 | -------------------------------------------------------------------------------- /packages/@textstat/rule-context/src/Localize.ts: -------------------------------------------------------------------------------- 1 | import template = require("lodash.template"); 2 | // template('hello {{ user }}!' 3 | const TEMPLATE_INTERPOLATE = /{{([\s\S]+?)}}/g; 4 | // TODO: add locale 5 | export type LocaleTag = 6 | | "en" 7 | | "cs" 8 | | "de" 9 | | "es" 10 | | "fr" 11 | | "it" 12 | | "ja" 13 | | "ko" 14 | | "pl" 15 | | "ru" 16 | | "tr" 17 | | "zh-CN" 18 | | "zh-TW" 19 | | string; 20 | 21 | type LocalizeMessageMulti = { [P in LocaleTag]?: string } & { en: string }; 22 | 23 | export type LocalizeMessages = { 24 | // must have "en" 25 | [index: string]: string | LocalizeMessageMulti; 26 | }; 27 | /** 28 | * Default locale that is also fallback locale. 29 | */ 30 | const DEFAULT_LOCAL = "en"; 31 | 32 | export class Localize { 33 | constructor(private messages: T, private locale: LocaleTag = DEFAULT_LOCAL) {} 34 | 35 | /** 36 | * Translate the `key` to text 37 | * If the `key` includes some variable, pass option and assign it to the variable. 38 | * @param key 39 | * @param options 40 | */ 41 | t = (key: keyof T, options?: object) => { 42 | if (!this.messages[key]) { 43 | throw new Error(`key:${key} is missing in messages.`); 44 | } 45 | const message: LocalizeMessageMulti | string = this.messages[key]; 46 | if (typeof message === "string") { 47 | return this.applyOption(message, options); 48 | } 49 | const locale = this.matchLocale(this.locale, message); 50 | const localizedMessage = message[locale]; 51 | if (!localizedMessage) { 52 | if (message[DEFAULT_LOCAL]) { 53 | throw new Error(`key:${key}.${this.locale} is missing in messages.`); 54 | } 55 | throw new Error(`key:${key}.${DEFAULT_LOCAL} should be defined in messages.`); 56 | } 57 | return this.applyOption(localizedMessage, options); 58 | }; 59 | 60 | private matchLocale = (locale: LocaleTag, locales: LocalizeMessageMulti) => { 61 | const localKeys = Object.keys(locales); 62 | const matchLocale = localKeys.find(key => { 63 | return key === locale; 64 | }); 65 | if (matchLocale) { 66 | return matchLocale; 67 | } 68 | const [lang] = locale.split("-"); 69 | if (!lang) { 70 | return DEFAULT_LOCAL; 71 | } 72 | // en-US => en 73 | const fallbackMatchLocal = localKeys.find(key => { 74 | return key === lang; 75 | }); 76 | if (fallbackMatchLocal) { 77 | return fallbackMatchLocal; 78 | } 79 | return DEFAULT_LOCAL; 80 | }; 81 | 82 | private applyOption = (message: string, options?: object): string => { 83 | if (!options) { 84 | return message; 85 | } 86 | return template(message, { 87 | interpolate: TEMPLATE_INTERPOLATE 88 | })(options); 89 | }; 90 | } 91 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-tester/src/textstat-tester.ts: -------------------------------------------------------------------------------- 1 | import { TextstatKernel } from "@textstat/kernel"; 2 | import { TextstatKernelRule } from "@textstat/rule-context"; 3 | 4 | import * as fs from "fs"; 5 | import * as path from "path"; 6 | import * as assert from "assert"; 7 | import { LocaleTag } from "@textstat/rule-context/lib/src/Localize"; 8 | 9 | export function runTest( 10 | snapshotDirectory: string, 11 | { 12 | rules, 13 | sharedDeps 14 | }: { 15 | rules: TextstatKernelRule[]; 16 | sharedDeps?: { 17 | locale?: LocaleTag; 18 | filePathList?: string[]; 19 | }; 20 | } 21 | ) { 22 | const textstat = new TextstatKernel(); 23 | fs.readdirSync(snapshotDirectory).map(caseName => { 24 | const normalizedTestName = caseName.replace(/-/g, " "); 25 | it(`Test ${normalizedTestName}`, async () => { 26 | const fixtureDir = path.join(snapshotDirectory, caseName); 27 | const actualFilePath = path.join(fixtureDir, "input.md"); 28 | const actualContent = fs.readFileSync(actualFilePath, "utf-8"); 29 | const defaultSharedDeps = { 30 | filePathList: [actualFilePath] 31 | }; 32 | const sharedDepsOwn = 33 | typeof sharedDeps === "object" 34 | ? { 35 | ...defaultSharedDeps, 36 | ...sharedDeps 37 | } 38 | : defaultSharedDeps; 39 | const actualResult = await textstat.report(actualContent, { 40 | filePath: actualFilePath, 41 | ext: path.extname(actualFilePath), 42 | rules: rules, 43 | plugins: [ 44 | { 45 | pluginId: "markdown", 46 | plugin: require("@textlint/textlint-plugin-markdown") 47 | } 48 | ], 49 | sharedDeps: sharedDepsOwn 50 | }); 51 | const cwdReplacer = (_key: string, value: string) => { 52 | if (typeof value === "string") { 53 | return value.replace(snapshotDirectory, "").replace(/\\/g, "/"); 54 | } 55 | return value; 56 | }; 57 | const expectedFilePath = path.join(fixtureDir, "output.json"); 58 | const existExpectedFile = fs.existsSync(expectedFilePath); 59 | // UPDATE_SNAPSHOT=1 npm test 60 | // Update snapshot 61 | if (process.env.UPDATE_SNAPSHOT || !existExpectedFile) { 62 | fs.writeFileSync(expectedFilePath, JSON.stringify(actualResult, cwdReplacer, 4)); 63 | return; 64 | } 65 | // Input === Output 66 | const expectedResult = JSON.parse(fs.readFileSync(expectedFilePath, "utf-8")); 67 | assert.deepStrictEqual( 68 | // remove undefined prop 69 | JSON.parse(JSON.stringify(actualResult, cwdReplacer)), 70 | expectedResult, 71 | ` 72 | ${fixtureDir} 73 | ${JSON.stringify(actualResult)} 74 | ` 75 | ); 76 | }); 77 | }); 78 | } 79 | -------------------------------------------------------------------------------- /packages/@textstat/textstat-view/src/App.tsx: -------------------------------------------------------------------------------- 1 | // App.js 2 | import * as React from "react"; 3 | import * as url from "url"; 4 | import { ChangeEvent } from "react"; 5 | import { NavLoading, NavProvider, NavRoute } from "react-navi"; 6 | import { BrowserNavigation } from "navi"; 7 | import { StatContext } from "./context/StatContext"; 8 | import { getStore, saveStore } from "./context/LocalStore"; 9 | import { AppMenu } from "./AppMenu"; 10 | import "./App.css"; 11 | import { fetchGistContent } from "./context/GistStore"; 12 | 13 | export interface AppProps { 14 | navigation: BrowserNavigation; 15 | } 16 | 17 | class App extends React.Component { 18 | state = getStore({ 19 | input: "[]", 20 | results: [] 21 | }); 22 | 23 | private onChangeTextarea = (event: ChangeEvent) => { 24 | const input = event.currentTarget.value; 25 | let results = this.state.results; 26 | try { 27 | results = JSON.parse(input); 28 | } catch (error) { 29 | // nope 30 | } 31 | const newState = { 32 | input: input, 33 | results: results 34 | }; 35 | this.setState(newState); 36 | saveStore(newState); 37 | }; 38 | 39 | componentDidMount(): void { 40 | const urlObject = url.parse(location.href, true); 41 | if (urlObject.query && typeof urlObject.query.gist === "string") { 42 | fetchGistContent(urlObject.query.gist) 43 | .then(content => { 44 | try { 45 | const state = JSON.parse(content); 46 | this.setState({ 47 | input: content, 48 | results: state 49 | }); 50 | } catch (error) { 51 | console.error("parse error ?gist", error); 52 | } 53 | }) 54 | .catch(error => { 55 | console.error("Gist Fetch Error", error); 56 | }); 57 | } 58 | } 59 | 60 | render() { 61 | return ( 62 | 63 |
64 |
65 |