forked from get-alex/alex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
101 lines (86 loc) · 2.08 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
/**
* @author Titus Wormer
* @copyright 2015 Titus Wormer
* @license MIT
* @module alex
* @fileoverview
* alex checks your (or someone else’s) writing for possible
* inconsiderate wording.
*/
'use strict';
/* eslint-env commonjs */
/*
* Dependencies.
*/
var VFile = require('vfile');
var remark = require('remark');
var retext = require('retext');
var control = require('remark-message-control');
var english = require('retext-english');
var equality = require('retext-equality');
var profanities = require('retext-profanities');
var remark2retext = require('remark-retext');
var sort = require('vfile-sort');
/*
* Processor.
*/
var text = retext().use(english).use(equality).use(profanities);
/**
* alex’s core.
*
* @param {string|VFile} value - Content.
* @param {Processor} processor - retext or remark.
* @return {VFile} - Result.
*/
function core(value, processor) {
var file = new VFile(value);
processor.parse(file);
processor.run(file);
sort(file);
return file;
}
/**
* alex.
*
* Read markdown as input, converts to natural language,
* then detect violations.
*
* @example
* alex('We’ve confirmed his identity.').messages;
* // [ { [1:17-1:20: `his` may be insensitive, use `their`, `theirs` instead]
* // name: '1:17-1:20',
* // file: '',
* // reason: '`his` may be insensitive, use `their`, `theirs` instead',
* // line: 1,
* // column: 17,
* // fatal: false } ]
*
* @param {string|VFile} value - Content.
* @param {Array.<string>?} allow - Allowed rules.
* @return {VFile} - Result.
*/
function alex(value, allow) {
return core(value, remark().use(remark2retext, text).use(control, {
'name': 'alex',
'disable': allow,
'source': [
'retext-equality',
'retext-profanities'
]
}));
}
/**
* alex, without the markdown.
*
* @param {string|VFile} value - Content.
* @return {VFile} - Result.
*/
function noMarkdown(value) {
return core(value, text);
}
/*
* Expose.
*/
alex.text = noMarkdown;
alex.markdown = alex;
module.exports = alex;