Commit 54755e3 1 parent ea48d44 commit 54755e3 Copy full SHA for 54755e3
File tree 1 file changed +16
-1
lines changed
1 file changed +16
-1
lines changed Original file line number Diff line number Diff line change 5
5
const { execSync } = require ( `child_process` )
6
6
const fs = require ( `fs` )
7
7
8
+ // Strip the string
9
+ function trim ( str ) {
10
+ // `*` is used to negate words, so negated words should be put with the original word
11
+ // e.g. npm, *NPM
12
+ return str . replace ( / ^ \* / , `` )
13
+ }
14
+
15
+ function compareWords ( a , b ) {
16
+ // The empty string should go at the end
17
+ if ( a === `` ) return 1
18
+ if ( b === `` ) return - 1
19
+ // Compare the two words
20
+ return trim ( a ) . localeCompare ( trim ( b ) )
21
+ }
22
+
8
23
// Get our current list of words
9
24
const words = new Set ( fs . readFileSync ( `./dictionary.txt` , `utf-8` ) . split ( `\n` ) )
10
25
@@ -34,7 +49,7 @@ for (const match of matches) {
34
49
35
50
const wordList = [ ...words ]
36
51
// Sort in alphabetical order for convenience
37
- wordList . sort ( ( a , b ) => a . localeCompare ( b ) )
52
+ wordList . sort ( compareWords )
38
53
39
54
// Write back to the dictionary file
40
55
fs . writeFileSync ( `./dictionary.txt` , wordList . join ( `\n` ) )
You can’t perform that action at this time.
0 commit comments