aboutsummaryrefslogtreecommitdiff
path: root/index.js
diff options
context:
space:
mode:
authorJohn MacFarlane <jgm@berkeley.edu>2016-12-09 22:22:48 +0100
committerJohn MacFarlane <jgm@berkeley.edu>2016-12-09 22:22:48 +0100
commit0a2d6af06db880bf4062d444bf8b7e2df6aacef2 (patch)
treec75c9e00192beab5bb743894512657d63f47240e /index.js
parent4e9b80ece8979c6dfd79a08672fa13c4d3104fd2 (diff)
Improved npm package: package.json and index.js.
Added .tests (JSON) and .version to index.js. Added version. Added license, description.
Diffstat (limited to 'index.js')
-rw-r--r--index.js28
1 files changed, 26 insertions, 2 deletions
diff --git a/index.js b/index.js
index 6068627..9c6b739 100644
--- a/index.js
+++ b/index.js
@@ -1,7 +1,31 @@
'use strict';
-const fs = require('fs');
-const path = require('path');
+var fs = require('fs');
+var path = require('path');
+var extractSpecTests = function(data) {
+ var examples = [];
+ var current_section = "";
+ var example_number = 0;
+ var tests = data
+ .replace(/\r\n?/g, "\n") // Normalize newlines for platform independence
+ .replace(/^<!-- END TESTS -->(.|[\n])*/m, '');
+
+ tests.replace(/^`{32} example\n([\s\S]*?)^\.\n([\s\S]*?)^`{32}$|^#{1,6} *(.*)$/gm,
+ function(_, markdownSubmatch, htmlSubmatch, sectionSubmatch){
+ if (sectionSubmatch) {
+ current_section = sectionSubmatch;
+ } else {
+ example_number++;
+ examples.push({markdown: markdownSubmatch,
+ html: htmlSubmatch,
+ section: current_section,
+ number: example_number});
+ }
+ });
+ return examples;
+};
exports.text = fs.readFileSync(path.join(__dirname, 'spec.txt'), 'utf8');
+exports.tests = extractSpecTests(exports.text);
+exports.version = exports.text.match(/^version: *([0-9.]*)/m)[1];