-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild-word-list.js
38 lines (36 loc) · 973 Bytes
/
build-word-list.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
/**
* Quick Node script that writes a list of the words covered by the plugin to a
* JSON file on disk.
*/
'use strict';
var plugin = require('./grawlix-racism');
var packageInfo = require('./package.json');
var fs = require('fs');
var _ = require('underscore');
// get words
var words = _.pluck(_.filter(plugin.filters, function(filter) {
return (_.has(filter, 'pattern'));
}), 'word');
words.sort(function(a, b) {
return (a < b) ? -1 : 1;
});
// get json
var obj = {
words: words,
'plugin-name': 'grawlix-racism',
version: packageInfo.version
};
var json = JSON.stringify(obj, null, 4);
console.log(json);
console.log('total word count: %d', words.length);
// don't count plurals
var noPlurals = _.filter(words, function(word) {
return (
word === 'negress' ||
word.search(/s$/i) === -1
);
});
console.log('minus plurals: %d', noPlurals.length);
// save file
fs.writeFileSync('WORDS.json', json, { encoding: 'utf8' });
console.log('complete');