8
8
9
9
10
10
var fs = require ( "fs" ) ;
11
- var doclistPath = '/Users/sperberx/dev/essential-javascript-links/' ;
12
- var doclistName = 'README' ;
11
+ var doclistPath = '/Users/sperberx/dev/essential-javascript-links/misc/ ' ;
12
+ var doclistName = 'README-short1 ' ;
13
13
var doclistAddon = '-new' ;
14
14
var doclistExtension = '.md' ;
15
15
@@ -34,7 +34,7 @@ var aposVe = /'ve\b/g; // I've
34
34
var oAposR = / O ' R / g; // O'Reilly
35
35
var spaceQuot = / " \b / g; // open quote (eg, precedes a 'word boundary')
36
36
var quotSpace = / \b " / g; // close quote (eg, is preceded by a 'word boundary')
37
- var spaceDashSpace = / - / g;
37
+ var spaceDashSpace = / - / g; // em dash
38
38
// not yet defined: single quotes within double quotes
39
39
// var spaceApos = / '/
40
40
// var aposSpace = /' /
@@ -52,6 +52,21 @@ var spaceLdq = ' “';
52
52
var rdqSpace = '”' ;
53
53
var spaceEmDashSpace = " — " ;
54
54
55
+ var replacements = [
56
+ { searchFor : / ' d \b / g, replaceWith : "’d" } , // I'd
57
+ { searchFor : / ' l l \b / g, replaceWith : "’ll" } , // you'll
58
+ { searchFor : / ' m \b / g, replaceWith : "’m" } , // I'm
59
+ { searchFor : / ' r e \b / g, replaceWith : "’re" } , // you're
60
+ { searchFor : / ' s \b / g, replaceWith : "’s" } , // it's
61
+ { searchFor : / ' t \b / g, replaceWith : "’t" } , // don't
62
+ { searchFor : / ' v e \b / g, replaceWith : "’ve" } , // I've
63
+ { searchFor : / O ' R / g, replaceWith : "O’R" } , // O'Reilly
64
+ { searchFor : / " , / g, replaceWith : ',”' } , // comma outside quote mark
65
+ { searchFor : / " \. / g, replaceWith : '.”' } , // period outside quote mark (transpose only)
66
+ { searchFor : / " \b / g, replaceWith : '“' } , // open quote (eg, precedes a 'word boundary')
67
+ { searchFor : / \b " / g, replaceWith : '”' } , // close quote (eg, is preceded by a 'word boundary') needs to be set to follow punctuation as well
68
+ { searchFor : / - / g, replaceWith : " — " } // em dash
69
+ ] ;
55
70
56
71
/* store components of path */
57
72
var pathAndFile = doclistPath + doclistName + doclistExtension ; // /Users/sperberx/dev/essential-javascript-links/README.md
@@ -62,25 +77,22 @@ var aFile = fs.readFile(pathAndFile, 'utf8', function (err,data) {
62
77
return console . log ( err ) ;
63
78
}
64
79
65
- // This seems really awkward to me, but it's working
80
+ // for each object in the replacements array, go through the document and make the replacement
66
81
function cleanUp ( someFile ) {
67
- var removes = [ aposD , aposLl , aposM , aposRe , aposS , aposT , aposVe , oAposR , spaceQuot , quotSpace , spaceDashSpace ] ;
68
- var replaceWiths = [ rsqD , rsqLl , rsqM , rsqRe , rsqS , rsqT , rsqVe , OrsqR , spaceLdq , rdqSpace , spaceEmDashSpace ] ;
69
-
70
- for ( var counter = 0 ; counter < removes . length ; counter ++ ) {
71
- someFile = someFile . replace ( removes [ counter ] , replaceWiths [ counter ] ) ;
72
- }
82
+ replacements . forEach ( function ( replacement ) {
83
+ someFile = someFile . replace ( replacement . searchFor , replacement . replaceWith ) ;
84
+ } )
73
85
return someFile ;
74
86
}
75
87
var result = cleanUp ( data ) ;
76
88
77
- // console.log(result);
89
+ console . log ( result ) ;
78
90
console . log ( 'got result back' ) ;
79
91
80
- fs . writeFile ( pathAndFileNew , result , function ( err ) {
81
- if ( err ) throw err ;
82
- console . log ( 'It\'s saved!' ) ;
83
- } ) ;
92
+ // fs.writeFile(pathAndFileNew, result, function (err) {
93
+ // if (err) throw err;
94
+ // console.log('It\'s saved!');
95
+ // });
84
96
85
97
} ) ;
86
98
0 commit comments