From 0a2d6af06db880bf4062d444bf8b7e2df6aacef2 Mon Sep 17 00:00:00 2001 From: John MacFarlane Date: Fri, 9 Dec 2016 22:22:48 +0100 Subject: Improved npm package: package.json and index.js. Added .tests (JSON) and .version to index.js. Added version. Added license, description. --- index.js | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) (limited to 'index.js') 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(/^(.|[\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]; -- cgit v1.2.3