markdown-maker 1.9.2 → 1.10.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -12,7 +12,7 @@ jobs:
12
12
 
13
13
  strategy:
14
14
  matrix:
15
- node-version: [12.x, 14.x, 15.x]
15
+ node-version: [16.x, 18.x, 20.x]
16
16
  # See supported Node.js release schedule at https://nodejs.org/en/about/releases/
17
17
 
18
18
  steps:
@@ -0,0 +1 @@
1
+ export declare const argParser: any;
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.argParser = void 0;
7
+ var fs = require("fs"); /* for handling reading of files */
8
+ var path = require("path"); /* for handling file paths */
9
+ var Colors = require("colors.ts"); /* for adding colours to strings */
10
+ var parse_1 = __importDefault(require("./parse"));
11
+ var ws_1 = require("ws");
12
+ Colors.enable();
13
+ var ArgumentParser = require("argparse").ArgumentParser; /* for parsing clargs */
14
+ var version = require("../package.json").version; /* package version number */
15
+ var choki = require("chokidar");
16
+ exports.argParser = new ArgumentParser({
17
+ description: "Markdown bundler, with extra options. Extension file is loaded from ./extensions.js, if it exists",
18
+ prog: "mdparse",
19
+ });
20
+ var configFileName = ".mdmconfig.json";
21
+ //#region command line args
22
+ exports.argParser.add_argument("src", {
23
+ help: "file to be parsed. If this is a directory, it looks for entry point in the directory, see --entry",
24
+ });
25
+ exports.argParser.add_argument("--version", { action: "version", version: version });
26
+ exports.argParser.add_argument("-v", "--verbose", {
27
+ action: "store_true",
28
+ help: "enable verbose output",
29
+ });
30
+ exports.argParser.add_argument("-D", "--debug", {
31
+ action: "store_true",
32
+ help: "enable debugging information",
33
+ });
34
+ exports.argParser.add_argument("-o", "--output", {
35
+ help: "destination of bundle, by default is 'dist/bundle.md'",
36
+ default: "dist/bundle.md",
37
+ });
38
+ exports.argParser.add_argument("-d", "--max-depth", {
39
+ help: "maximum recursion depth, by default is 15",
40
+ default: 15,
41
+ type: "int",
42
+ });
43
+ exports.argParser.add_argument("-e", "--entry", {
44
+ help: "assign entry point in directory, by default is 'main.md'",
45
+ default: "main.md",
46
+ });
47
+ exports.argParser.add_argument("-w", "--watch", {
48
+ action: "store_true",
49
+ help: "recompile after a change in target target file or directory.",
50
+ });
51
+ exports.argParser.add_argument("-u", "--use-underscore", {
52
+ action: "store_true",
53
+ help: "set the parser to use '_' as seperator in ids for Table of Content. If the links in the table does not work, this is likely to be the issue.",
54
+ });
55
+ exports.argParser.add_argument("-t", "--toc-level", {
56
+ help: "the section level of the table of contents, by default is 3",
57
+ default: 3,
58
+ type: "int",
59
+ });
60
+ exports.argParser.add_argument("-H", "--html", {
61
+ action: "store_true",
62
+ help: "compile HTML from the parsed markdown",
63
+ });
64
+ exports.argParser.add_argument("--allow-undefined", "-A", {
65
+ action: "store_true",
66
+ help: "allow the use of the \"<thing>\" syntax, without raising an error when 'thing' is not a variable. Mostly useful when writing inline html tags, and other non-strictly markdown related uses",
67
+ });
68
+ //#endregion
69
+ function main() {
70
+ var clargs, fileargs;
71
+ var server;
72
+ /* Read config file or parse args from cmd-line */
73
+ if (fs.existsSync(configFileName)) {
74
+ var data = JSON.parse(fs.readFileSync(configFileName)).opts;
75
+ var args_1 = [];
76
+ Object.entries(data).forEach(function (_a) {
77
+ var key = _a[0], value = _a[1];
78
+ if (key != "src" && value !== false) {
79
+ args_1.push("--" + key);
80
+ }
81
+ if (typeof value != "boolean") {
82
+ args_1.push(value);
83
+ }
84
+ });
85
+ /* We skip [0] and [1], as it is the binary and source file, even when compiled*/
86
+ for (var i = 2; i < process.argv.length; i++)
87
+ args_1.push(process.argv[i]);
88
+ clargs = exports.argParser.parse_args(args_1);
89
+ }
90
+ else {
91
+ clargs = exports.argParser.parse_args();
92
+ }
93
+ /* if src is init, create config file and exit */
94
+ if (clargs.src == "init") {
95
+ var template = fs.readFileSync(path.join(__dirname, "..", "src", "templates", "configTemplate.json"));
96
+ fs.writeFileSync(configFileName, template);
97
+ fs.writeFileSync("main.md", "# Main\n");
98
+ return;
99
+ }
100
+ /* helper method for calling parser */
101
+ var compile = function (source, output, cb) {
102
+ /* load data from file, if it exists,
103
+ * otherwise, interpret as string */
104
+ var parser = new parse_1.default(source, clargs);
105
+ parser.to(output, function (file) {
106
+ console.log("Compiled ".concat(file).green);
107
+ if (cb)
108
+ cb();
109
+ });
110
+ return parser;
111
+ };
112
+ var internalCooldown = 1000;
113
+ function watcher(event, path) {
114
+ var now = Date.now();
115
+ if (!this.time)
116
+ this.time = now;
117
+ if (now - this.time < internalCooldown)
118
+ return;
119
+ console.log(path);
120
+ console.log("Detected change in ".concat(path, "..."));
121
+ try {
122
+ compile(clargs.src, clargs.output, function () {
123
+ /* after compile, send refresh command to clients */
124
+ server.clients.forEach(function (client) {
125
+ if (client.OPEN)
126
+ client.send("refresh");
127
+ });
128
+ });
129
+ }
130
+ catch (e) {
131
+ console.log(e.message);
132
+ }
133
+ this.time = now;
134
+ }
135
+ /* in case source is a directory, look for entry in directory */
136
+ if (fs.existsSync(clargs.src) && fs.lstatSync(clargs.src).isDirectory()) {
137
+ clargs.src = path.join(clargs.src, clargs.entry);
138
+ }
139
+ if (clargs.debug)
140
+ console.dir(clargs);
141
+ /* compile once */
142
+ if (!clargs.watch)
143
+ compile(clargs.src, clargs.output);
144
+ /* watch the folder and recompile on change */
145
+ else {
146
+ var srcDirName = path.dirname(clargs.src);
147
+ console.log("Watching ".concat(srcDirName, " for changes...").yellow);
148
+ server = new ws_1.WebSocketServer({ port: 7788 });
149
+ var _watcher = choki.watch(srcDirName).on("all", watcher);
150
+ try {
151
+ compile(clargs.src, clargs.output);
152
+ }
153
+ catch (e) {
154
+ console.log(e.message);
155
+ }
156
+ }
157
+ }
158
+ /* main entrypoint */
159
+ if (require.main === module)
160
+ main();
161
+ //# sourceMappingURL=cltool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"cltool.js","sourceRoot":"","sources":["../src/cltool.ts"],"names":[],"mappings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AED,IAAI,MAAM,CAAC,KAAK;QAAE,OAAO,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEtC,kBAAkB;IAClB,IAAI,CAAC,MAAM,CAAC,KAAK;QAAE,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;IACtD,8CAA8C;SACzC;QACD,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;QAC5C,OAAO,CAAC,GAAG,CAAC,mBAAY,UAAU,oBAAiB,CAAC,MAAM,CAAC,CAAC;QAC5D,MAAM,GAAG,IAAI,oBAAe,CAAC,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,CAAC;QAE7C,IAAM,QAAQ,GAAG,KAAK,CAAC,KAAK,CAAC,UAAU,CAAC,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAC5D,IAAI;YACA,OAAO,CAAC,MAAM,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;SACtC;QAAC,OAAO,CAAC,EAAE;YACR,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC;SAC1B;KACJ;AAEL,CAAC;AAED,qBAAqB;AACrB,IAAI,OAAO,CAAC,IAAI,KAAK,MAAM;IAAE,IAAI,EAAE,CAAC"}
@@ -0,0 +1,43 @@
1
+ import Parser from "./parse";
2
+ export declare class MDMError extends Error {
3
+ match: RegExpMatchArray;
4
+ constructor(message: string, match: RegExpMatchArray);
5
+ }
6
+ export declare const commands: {
7
+ preparse: Command[];
8
+ parse: Command[];
9
+ postparse: Command[];
10
+ };
11
+ export declare enum CommandType {
12
+ PREPARSE = 0,
13
+ PARSE = 1,
14
+ POSTPARSE = 2
15
+ }
16
+ export declare enum TargetType {
17
+ HTML = 0,
18
+ MARKDOWN = 1
19
+ }
20
+ export declare class Command {
21
+ validator: RegExp;
22
+ acter: (match: RegExpMatchArray, parser: Parser) => string | void;
23
+ type: CommandType;
24
+ constructor(validator: RegExp, acter: (match: RegExpMatchArray, parser: Parser) => string | void, type: CommandType);
25
+ act(match: any, parser: any): string | void;
26
+ }
27
+ export declare function load_extensions(parser: Parser): void;
28
+ /**
29
+ *
30
+ * @param regex The regex to match the command
31
+ * @param acter The function called when a match is found. Takes two arguments, `match` and `parser`. `match` is the result of the regex match, and `parser` is the parser instance. The function should return the replacement string.
32
+ * @param type When the command should be run. Can be `CommandType.PREPARSE`, `CommandType.PARSE`, or `CommandType.POSTPARSE`. Defaults to `CommandType.PARSE`.
33
+ */
34
+ export declare function new_command(regex: RegExp, acter: (match: RegExpMatchArray, parser: Parser) => string, type?: CommandType): void;
35
+ declare const _default: {
36
+ commands: {
37
+ preparse: Command[];
38
+ parse: Command[];
39
+ postparse: Command[];
40
+ };
41
+ load_extensions: typeof load_extensions;
42
+ };
43
+ export default _default;
@@ -0,0 +1,223 @@
1
+ "use strict";
2
+ var __extends = (this && this.__extends) || (function () {
3
+ var extendStatics = function (d, b) {
4
+ extendStatics = Object.setPrototypeOf ||
5
+ ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
+ function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
+ return extendStatics(d, b);
8
+ };
9
+ return function (d, b) {
10
+ if (typeof b !== "function" && b !== null)
11
+ throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
+ extendStatics(d, b);
13
+ function __() { this.constructor = d; }
14
+ d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
+ };
16
+ })();
17
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
18
+ if (k2 === undefined) k2 = k;
19
+ var desc = Object.getOwnPropertyDescriptor(m, k);
20
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
21
+ desc = { enumerable: true, get: function() { return m[k]; } };
22
+ }
23
+ Object.defineProperty(o, k2, desc);
24
+ }) : (function(o, m, k, k2) {
25
+ if (k2 === undefined) k2 = k;
26
+ o[k2] = m[k];
27
+ }));
28
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
29
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
30
+ }) : function(o, v) {
31
+ o["default"] = v;
32
+ });
33
+ var __importStar = (this && this.__importStar) || function (mod) {
34
+ if (mod && mod.__esModule) return mod;
35
+ var result = {};
36
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
37
+ __setModuleDefault(result, mod);
38
+ return result;
39
+ };
40
+ var __importDefault = (this && this.__importDefault) || function (mod) {
41
+ return (mod && mod.__esModule) ? mod : { "default": mod };
42
+ };
43
+ Object.defineProperty(exports, "__esModule", { value: true });
44
+ exports.new_command = exports.load_extensions = exports.Command = exports.TargetType = exports.CommandType = exports.commands = exports.MDMError = void 0;
45
+ var path = __importStar(require("path"));
46
+ var parse_1 = __importDefault(require("./parse"));
47
+ var fs = __importStar(require("fs"));
48
+ var templates_1 = __importStar(require("./templates"));
49
+ var require_runtime_1 = __importDefault(require("require-runtime"));
50
+ var MDMError = /** @class */ (function (_super) {
51
+ __extends(MDMError, _super);
52
+ function MDMError(message, match) {
53
+ var _this = _super.call(this, message) || this;
54
+ _this.name = "MDMError";
55
+ _this.match = match;
56
+ return _this;
57
+ }
58
+ return MDMError;
59
+ }(Error));
60
+ exports.MDMError = MDMError;
61
+ exports.commands = {
62
+ preparse: [],
63
+ parse: [],
64
+ postparse: [],
65
+ };
66
+ var CommandType;
67
+ (function (CommandType) {
68
+ CommandType[CommandType["PREPARSE"] = 0] = "PREPARSE";
69
+ CommandType[CommandType["PARSE"] = 1] = "PARSE";
70
+ CommandType[CommandType["POSTPARSE"] = 2] = "POSTPARSE";
71
+ })(CommandType = exports.CommandType || (exports.CommandType = {}));
72
+ var TargetType;
73
+ (function (TargetType) {
74
+ TargetType[TargetType["HTML"] = 0] = "HTML";
75
+ TargetType[TargetType["MARKDOWN"] = 1] = "MARKDOWN";
76
+ })(TargetType = exports.TargetType || (exports.TargetType = {}));
77
+ var Command = /** @class */ (function () {
78
+ function Command(validator, acter, type) {
79
+ this.type = type;
80
+ this.validator = validator;
81
+ this.acter = acter;
82
+ /* add this function to appropriate file */
83
+ switch (type) {
84
+ case CommandType.PARSE:
85
+ exports.commands.parse.push(this);
86
+ break;
87
+ case CommandType.PREPARSE:
88
+ exports.commands.preparse.push(this);
89
+ break;
90
+ case CommandType.POSTPARSE:
91
+ exports.commands.postparse.push(this);
92
+ break;
93
+ }
94
+ }
95
+ Command.prototype.act = function (match, parser) {
96
+ return this.acter(match, parser);
97
+ };
98
+ return Command;
99
+ }());
100
+ exports.Command = Command;
101
+ /* variable shorthand */
102
+ new Command(/(\s|^)<(.+)>/, function (match, parser) { return "".concat(match[1], "#mdvar<").concat(match[2], ">"); }, CommandType.PREPARSE);
103
+ /* mddef */
104
+ new Command(/#mddef< *(.+?) *= *(.+?) *>/ /* first .+ is lazy so as to not match following spaces */, function (match, parser) {
105
+ parser.opts.defs[match[1]] = match[2].replace("_", " ");
106
+ }, CommandType.PARSE);
107
+ /* mdvar */
108
+ new Command(/#mdvar<(.+?)>/, function (match, parser) {
109
+ var value = parser.opts.defs[match[1]];
110
+ if (!value && !parser.opts.allow_undefined)
111
+ throw new Error("Undefined variable: ".concat(match[1]));
112
+ return (value = value || "<".concat(match[1], ">"));
113
+ }, CommandType.PARSE);
114
+ /** mdinclude */
115
+ new Command(/#mdinclude<([\w.\/-]+)(?:[,\s]+([\w]+))?>/, function (match, parser) {
116
+ /* increase the current recursive depth */
117
+ parser.opts.depth++;
118
+ if (parser.opts.depth > parser.opts.max_depth) {
119
+ throw new Error("max depth exceeded!");
120
+ }
121
+ /* get the matching group */
122
+ var _ = match[0], name = match[1], condition = match[2];
123
+ /* implement conditional imports */
124
+ if (condition && !parser.opts.args.includes(condition))
125
+ return;
126
+ var fsstat = fs.lstatSync(path.join(parser.wd, name));
127
+ if (fsstat.isDirectory()) {
128
+ /* check if a file with the same name of the
129
+ * exists in the folder */
130
+ if (fs.existsSync(path.join(parser.wd, name, "".concat(name, ".md")))) {
131
+ name = path.join(name, "".concat(name, ".md"));
132
+ }
133
+ else {
134
+ throw new Error("No entry file found in folder \"".concat(name, "\". Looking for \"").concat(name, ".md\""));
135
+ }
136
+ }
137
+ var recursiveParser = new parse_1.default(path.join(parser.wd, name), parser.opts, {
138
+ parent: parser,
139
+ });
140
+ /* keep the options the same */
141
+ recursiveParser.opts = parser.opts;
142
+ recursiveParser.parent = parser;
143
+ var fileType = path.extname(recursiveParser.file);
144
+ var blob = fileType === ".md"
145
+ ? recursiveParser.get(parser.opts.targetType)
146
+ : recursiveParser.raw;
147
+ parser.opts.depth--;
148
+ return blob;
149
+ }, CommandType.PARSE);
150
+ /* mdlabel */
151
+ new Command(/#mdlabel<(\d+),\s?(.+)>/, function (match, parser) {
152
+ if (parser.opts.targetType !== TargetType.HTML)
153
+ return "";
154
+ var level = Number.parseInt(match[1]);
155
+ var title = match[2];
156
+ var link = parser.titleId(title);
157
+ parser.opts.secs.push({ level: level, title: title });
158
+ return "<span id=\"".concat(link, "\"></span>");
159
+ }, CommandType.PREPARSE);
160
+ /* mdref */
161
+ new Command(/#mdref<(.+)>/, function (match, parser) {
162
+ for (var i = 0; i < parser.opts.secs.length; i++) {
163
+ var title = parser.opts.secs[i].title;
164
+ if (title === match[1])
165
+ break;
166
+ if (i === parser.opts.secs.length - 1)
167
+ throw new Error("Reference to [".concat(match[1], "] could not be resolved!"));
168
+ }
169
+ match[1] = match[1].replace("_", " ");
170
+ var link = parser.titleId(match[1]);
171
+ if (parser.opts.targetType === TargetType.HTML)
172
+ return "<a href=\"#".concat(link, "\">").concat(match[1], "</a>");
173
+ else if (parser.opts.targetType === TargetType.MARKDOWN)
174
+ return "[".concat(match[1], "](#").concat(link, ")");
175
+ }, CommandType.PARSE);
176
+ /* mdtemplate */
177
+ new Command(/#mdtemplate<(\w+?)>/, function (match, parser) {
178
+ var template = match[1];
179
+ var replacement = templates_1.default[template];
180
+ if (replacement !== undefined) {
181
+ return replacement;
182
+ }
183
+ else {
184
+ throw new MDMError("Template \"".concat(template, "\" not found!"), match);
185
+ }
186
+ }, CommandType.PARSE);
187
+ new Command(/#mdmaketoc(?:<>)?/, function (match, parser) { return parser.gen_toc(); }, CommandType.POSTPARSE);
188
+ var loaded_extentions = [];
189
+ function load_extension(parser, file) {
190
+ if (loaded_extentions.includes(file))
191
+ return;
192
+ if (fs.existsSync(file)) {
193
+ var extensions = (0, require_runtime_1.default)(file);
194
+ loaded_extentions.push(file);
195
+ extensions.main(templates_1.new_template, new_command);
196
+ if (parser.opts.verbose)
197
+ console.log("Loaded extensions from ".concat(file).yellow);
198
+ }
199
+ else if (parser.opts.debug) {
200
+ console.log("No extensions found at ".concat(file).red);
201
+ }
202
+ }
203
+ function load_extensions(parser) {
204
+ /* global extention */
205
+ var global_extensions_path = path.join(__dirname, "extensions.js");
206
+ load_extension(parser, global_extensions_path);
207
+ /* project extention */
208
+ var project_extensions_path = path.join(parser.wd_full, "extensions.js");
209
+ load_extension(parser, project_extensions_path);
210
+ }
211
+ exports.load_extensions = load_extensions;
212
+ /**
213
+ *
214
+ * @param regex The regex to match the command
215
+ * @param acter The function called when a match is found. Takes two arguments, `match` and `parser`. `match` is the result of the regex match, and `parser` is the parser instance. The function should return the replacement string.
216
+ * @param type When the command should be run. Can be `CommandType.PREPARSE`, `CommandType.PARSE`, or `CommandType.POSTPARSE`. Defaults to `CommandType.PARSE`.
217
+ */
218
+ function new_command(regex, acter, type) {
219
+ new Command(regex, acter, type || CommandType.PARSE);
220
+ }
221
+ exports.new_command = new_command;
222
+ exports.default = { commands: exports.commands, load_extensions: load_extensions };
223
+ //# sourceMappingURL=commands.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"commands.js","sourceRoot":"","sources":["../src/commands.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;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AAe,EAAE,QAAQ,kBAAA,EAAE,eAAe,iBAAA,EAAE,CAAC"}
@@ -0,0 +1,65 @@
1
+ import { Command } from "./commands";
2
+ declare enum TargetType {
3
+ HTML = 0,
4
+ MARKDOWN = 1
5
+ }
6
+ declare class Parser {
7
+ file: string;
8
+ parent?: Parser;
9
+ line_num: number;
10
+ wd: string;
11
+ wd_full: string;
12
+ blobs: {
13
+ [key: number]: string | undefined;
14
+ };
15
+ opts: {
16
+ defs: {
17
+ [key: string]: string;
18
+ };
19
+ secs: {
20
+ level: number;
21
+ title: string;
22
+ }[];
23
+ args: string[];
24
+ depth: number;
25
+ verbose: boolean;
26
+ debug: boolean;
27
+ max_depth: number;
28
+ use_underscore: boolean;
29
+ toc_level: number;
30
+ allow_undefined: boolean;
31
+ html: boolean;
32
+ watch: boolean;
33
+ targetType: TargetType | undefined;
34
+ only_warn: boolean;
35
+ parent?: Parser;
36
+ isFileCallback: (s: string) => false | string;
37
+ };
38
+ raw: string;
39
+ static TOKEN: string;
40
+ constructor(filename: any, clargs: any, opts?: {
41
+ parent?: Parser;
42
+ isFileCallback?: (s: string) => false | string;
43
+ });
44
+ /**
45
+ * parse wrapper for handling
46
+ * preprocessing, parsing and postprocess
47
+ **/
48
+ parse(): any;
49
+ mainparse(blob: string): string;
50
+ preprocess(blob: string): string;
51
+ postprocess(blob: string): string;
52
+ parse_commands(blob: string, commands: Command[]): string;
53
+ parse_all_commands(blob: string, commands: {
54
+ [key: string]: Command[];
55
+ }): string;
56
+ titleId(title: string): string;
57
+ gen_toc(): string;
58
+ line_num_from_index(index: number): number;
59
+ remove_double_blank_lines(blob: any): any;
60
+ to(bundleName: string, callback: (fileName: string) => void): void;
61
+ html(): any;
62
+ get(targetType?: TargetType, callback?: (blob: string) => void): string;
63
+ }
64
+ export declare function splice(str: string, startIndex: number, width: number, newSubStr: string): string;
65
+ export default Parser;