Skip to content

Commit 8ebc610

Browse files
Merge pull request #24 from plaid/davidchambers/sanctuary-scripts
[email protected]
2 parents 79145ae + e89d191 commit 8ebc610

File tree

5 files changed

+98
-90
lines changed

5 files changed

+98
-90
lines changed

.eslintrc.json

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
{
22
"root": true,
33
"extends": ["./node_modules/sanctuary-style/eslint-es3.json"],
4-
"env": {"node": true}
4+
"env": {"node": true},
5+
"overrides": [
6+
{
7+
"files": ["README.md"],
8+
"rules": {
9+
"no-unused-vars": ["error", {"varsIgnorePattern": "^map$"}]
10+
}
11+
}
12+
]
513
}

README.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ in the form `<heading-prefix> <name> :: <type>`.
1414
//. of type `b` using the provided function of type `a -> b`.
1515
//.
1616
//. ```javascript
17-
//. > map(String)([1, 2, 3, 4, 5])
17+
//. > map (String) ([1, 2, 3, 4, 5])
1818
//. ['1', '2', '3', '4', '5']
1919
//. ```
2020
function map(f) {
2121
return function(xs) {
2222
var output = [];
2323
for (var idx = 0; idx < xs.length; idx += 1) {
24-
output.push(f(xs[idx]));
24+
output.push (f (xs[idx]));
2525
}
2626
return output;
2727
};
@@ -87,7 +87,7 @@ Here's a complete example:
8787
of type `b` using the provided function of type `a -> b`.
8888

8989
```javascript
90-
> map(String)([1, 2, 3, 4, 5])
90+
> map (String) ([1, 2, 3, 4, 5])
9191
['1', '2', '3', '4', '5']
9292
```
9393

@@ -96,7 +96,7 @@ Here's a complete example:
9696
Returns the list of elements which satisfy the provided predicate.
9797

9898
```javascript
99-
> filter(function(n) { return n % 2 === 0; })([1, 2, 3, 4, 5])
99+
> filter (function(n) { return n % 2 === 0; }) ([1, 2, 3, 4, 5])
100100
[2, 4]
101101
```
102102

bin/transcribe

Lines changed: 79 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -2,141 +2,141 @@
22

33
'use strict';
44

5-
var fs = require('fs');
5+
var fs = require ('fs');
66

7-
var program = require('commander');
8-
var R = require('ramda');
7+
var program = require ('commander');
8+
var R = require ('ramda');
99

10-
var pkg = require('../package.json');
10+
var pkg = require ('../package.json');
1111

1212

1313
//. esc :: String -> String
14-
var esc = R.pipe(R.replace(/&/g, '&amp;'),
15-
R.replace(/</g, '&lt;'),
16-
R.replace(/"/g, '&quot;'));
14+
var esc = R.pipe (R.replace (/&/g, '&amp;'),
15+
R.replace (/</g, '&lt;'),
16+
R.replace (/"/g, '&quot;'));
1717

1818

1919
//. nbsp :: String -> String
20-
var nbsp = R.replace(/[ ]/g, '\u00A0');
20+
var nbsp = R.replace (/[ ]/g, '\u00A0');
2121

2222

2323
//. controlWrapping :: String -> String
2424
var controlWrapping =
25-
R.pipe(R.split(' :: '),
26-
R.map(R.split(' => ')),
27-
R.map(R.map(R.split(/([(][^()]+[)])/))),
28-
R.map(R.map(R.append(''))),
29-
R.map(R.map(R.splitEvery(2))),
30-
R.map(R.map(R.map(R.over(R.lensIndex(1), nbsp)))),
31-
R.map(R.map(R.unnest)),
32-
R.map(R.map(R.map(R.split(' -> ')))),
33-
R.map(R.map(R.map(R.map(nbsp)))),
34-
R.map(R.map(R.map(R.join(' -> ')))),
35-
R.map(R.map(R.join(''))),
36-
R.map(R.join(' => ')),
37-
R.join(' :: '),
38-
R.replace(/->/g, '-\u2060>'));
25+
R.pipe (R.split (' :: '),
26+
R.map (R.split (' => ')),
27+
R.map (R.map (R.split (/([(][^()]+[)])/))),
28+
R.map (R.map (R.append (''))),
29+
R.map (R.map (R.splitEvery (2))),
30+
R.map (R.map (R.map (R.over (R.lensIndex (1), nbsp)))),
31+
R.map (R.map (R.unnest)),
32+
R.map (R.map (R.map (R.split (' -> ')))),
33+
R.map (R.map (R.map (R.map (nbsp)))),
34+
R.map (R.map (R.map (R.join (' -> ')))),
35+
R.map (R.map (R.join (''))),
36+
R.map (R.join (' => ')),
37+
R.join (' :: '),
38+
R.replace (/->/g, '-\u2060>'));
3939

4040

4141
//. formatSignature :: Options -> String -> Number -> String -> String
42-
var formatSignature = R.curry(function(options, filename, line, signature) {
43-
return '######'.slice(0, options.headingLevel) + ' ' +
44-
'<a name="' + esc(signature.split(' :: ')[0]) + '"' +
45-
' href="' + esc(options.url.replace('{filename}', filename)
46-
.replace('{line}', line)) + '">' +
47-
'`' + controlWrapping(signature) + '`' +
42+
var formatSignature = R.curry (function(options, filename, line, signature) {
43+
return '######'.slice (0, options.headingLevel) + ' ' +
44+
'<a name="' + esc ((signature.split (' :: '))[0]) + '"' +
45+
' href="' + esc (options.url.replace ('{filename}', filename)
46+
.replace ('{line}', line)) + '">' +
47+
'`' + controlWrapping (signature) + '`' +
4848
'</a>\n';
4949
});
5050

5151

5252
//. parseLine :: Options -> String -> Number -> String -> String
53-
var parseLine = R.curry(function(options, filename, line, value) {
54-
return R.pipe(
55-
R.replace(/^\s+/, ''),
56-
R.cond([[R.pipe(R.indexOf(options.headingPrefix), R.equals(0)),
57-
R.pipe(R.drop(R.length(options.headingPrefix)),
58-
R.replace(/^[ ]/, ''),
59-
formatSignature(options, filename, line))],
60-
[R.pipe(R.indexOf(options.prefix), R.equals(0)),
61-
R.pipe(R.drop(R.length(options.prefix)),
62-
R.replace(/^[ ]/, ''),
63-
R.concat(R.__, '\n'))],
64-
[R.T,
65-
R.always('\n')]])
66-
)(value);
53+
var parseLine = R.curry (function(options, filename, line, value) {
54+
return R.pipe (
55+
R.replace (/^\s+/, ''),
56+
R.cond ([[R.pipe (R.indexOf (options.headingPrefix), R.equals (0)),
57+
R.pipe (R.drop (R.length (options.headingPrefix)),
58+
R.replace (/^[ ]/, ''),
59+
formatSignature (options, filename, line))],
60+
[R.pipe (R.indexOf (options.prefix), R.equals (0)),
61+
R.pipe (R.drop (R.length (options.prefix)),
62+
R.replace (/^[ ]/, ''),
63+
R.concat (R.__, '\n'))],
64+
[R.T,
65+
R.always ('\n')]])
66+
) (value);
6767
});
6868

6969

7070
//. parseFile :: Options -> String -> String
71-
var parseFile = R.curry(function(options, filename) {
72-
return R.pipe(
71+
var parseFile = R.curry (function(options, filename) {
72+
return R.pipe (
7373
fs.readFileSync,
7474
String,
75-
R.match(/^.*$/gm),
76-
R.lift(R.zip)(R.pipe(R.length, R.inc, R.range(1)), R.identity),
77-
R.map(R.apply(parseLine(options, filename))),
78-
R.join('')
79-
)(filename);
75+
R.match (/^.*$/gm),
76+
R.lift (R.zip) (R.pipe (R.length, R.inc, R.range (1)), R.identity),
77+
R.map (R.apply (parseLine (options, filename))),
78+
R.join ('')
79+
) (filename);
8080
});
8181

8282

8383
//. transcribe :: Options -> [String] -> String
84-
var transcribe = R.curry(function(options, filenames) {
85-
return R.pipe(
86-
R.map(parseFile(options)),
87-
R.join('\n\n'),
88-
R.replace(/\n{3,}/g, '\n\n'),
89-
R.replace(/^\n+/, ''),
90-
R.replace(/\n+$/, '\n')
91-
)(filenames);
84+
var transcribe = R.curry (function(options, filenames) {
85+
return R.pipe (
86+
R.map (parseFile (options)),
87+
R.join ('\n\n'),
88+
R.replace (/\n{3,}/g, '\n\n'),
89+
R.replace (/^\n+/, ''),
90+
R.replace (/\n+$/, '\n')
91+
) (filenames);
9292
});
9393

9494

9595
program
96-
.version(pkg.version)
97-
.usage('[options] <file ...>')
98-
.description(pkg.description)
99-
.option('--heading-level <num>', 'heading level in range [1, 6] (default: 3)')
100-
.option('--heading-prefix <str>', 'prefix for heading lines (default: "//#")')
101-
.option('--insert-into <str>', 'name of a file into which Transcribe will' +
102-
' insert generated output')
103-
.option('--prefix <str>', 'prefix for non-heading lines (default: "//.")')
104-
.option('--url <str>', 'source URL with {filename} and {line} placeholders')
105-
.parse(process.argv);
96+
.version (pkg.version)
97+
.usage ('[options] <file ...>')
98+
.description (pkg.description)
99+
.option ('--heading-level <num>', 'heading level in range [1, 6] (default: 3)')
100+
.option ('--heading-prefix <str>', 'prefix for heading lines (default: "//#")')
101+
.option ('--insert-into <str>',
102+
'name of a file into which Transcribe will insert generated output')
103+
.option ('--prefix <str>', 'prefix for non-heading lines (default: "//.")')
104+
.option ('--url <str>', 'source URL with {filename} and {line} placeholders')
105+
.parse (process.argv);
106106

107107
var valid = true;
108108

109-
if (!(program.headingLevel == null || /^[1-6]$/.test(program.headingLevel))) {
110-
process.stderr.write('Invalid --heading-level\n');
109+
if (!(program.headingLevel == null || /^[1-6]$/.test (program.headingLevel))) {
110+
process.stderr.write ('Invalid --heading-level\n');
111111
valid = false;
112112
}
113113

114114
if (program.url == null) {
115-
process.stderr.write('No --url template specified\n');
115+
process.stderr.write ('No --url template specified\n');
116116
valid = false;
117117
}
118118

119119
if (!valid) {
120-
process.exit(1);
120+
process.exit (1);
121121
}
122122

123123
//. options :: { headingLevel, headingPrefix, insertInto, prefix, url }
124124
var options = {
125-
headingLevel: Number(R.defaultTo('3', program.headingLevel)),
126-
headingPrefix: R.defaultTo('//#', program.headingPrefix),
127-
insertInto: R.defaultTo(null, program.insertInto),
128-
prefix: R.defaultTo('//.', program.prefix),
125+
headingLevel: Number (R.defaultTo ('3', program.headingLevel)),
126+
headingPrefix: R.defaultTo ('//#', program.headingPrefix),
127+
insertInto: R.defaultTo (null, program.insertInto),
128+
prefix: R.defaultTo ('//.', program.prefix),
129129
url: program.url
130130
};
131131

132-
var output = transcribe(options, program.args);
132+
var output = transcribe (options, program.args);
133133
if (options.insertInto == null) {
134-
process.stdout.write(output);
134+
process.stdout.write (output);
135135
} else {
136136
// Read the file, insert the output, and write to the file again
137-
fs.writeFileSync(options.insertInto, R.replace(
137+
fs.writeFileSync (options.insertInto, R.replace (
138138
/(<!--transcribe-->)[\s\S]*?(<!--[/]transcribe-->)/,
139139
'$1\n\n' + output + '\n$2',
140-
fs.readFileSync(options.insertInto, {encoding: 'utf8'})
140+
fs.readFileSync (options.insertInto, {encoding: 'utf8'})
141141
));
142142
}

examples/fp.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,14 @@
66
//. of type `b` using the provided function of type `a -> b`.
77
//.
88
//. ```javascript
9-
//. > map(String)([1, 2, 3, 4, 5])
9+
//. > map (String) ([1, 2, 3, 4, 5])
1010
//. ['1', '2', '3', '4', '5']
1111
//. ```
1212
function map(f) {
1313
return function(xs) {
1414
var output = [];
1515
for (var idx = 0; idx < xs.length; idx += 1) {
16-
output.push(f(xs[idx]));
16+
output.push (f (xs[idx]));
1717
}
1818
return output;
1919
};
@@ -25,15 +25,15 @@ exports.map = map;
2525
//. Returns the list of elements which satisfy the provided predicate.
2626
//.
2727
//. ```javascript
28-
//. > filter(function(n) { return n % 2 === 0; })([1, 2, 3, 4, 5])
28+
//. > filter (function(n) { return n % 2 === 0; }) ([1, 2, 3, 4, 5])
2929
//. [2, 4]
3030
//. ```
3131
function filter(pred) {
3232
return function(xs) {
3333
var output = [];
3434
for (var idx = 0; idx < xs.length; idx += 1) {
35-
if (pred(xs[idx])) {
36-
output.push(xs[idx]);
35+
if (pred (xs[idx])) {
36+
output.push (xs[idx]);
3737
}
3838
}
3939
return output;

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
"ramda": "0.19.x"
2222
},
2323
"devDependencies": {
24-
"sanctuary-scripts": "1.3.x"
24+
"sanctuary-scripts": "2.0.x"
2525
},
2626
"scripts": {
2727
"doctest": "sanctuary-doctest",

0 commit comments

Comments
 (0)