@gmb/bitmark-parser-generator 1.4.8 → 1.4.9
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/browser/bitmark-parser-generator.min.js +1 -1
- package/dist/browser/bundle-report.html +2 -2
- package/dist/cjs/BitmarkParserGenerator.js +6 -3
- package/dist/cjs/BitmarkParserGenerator.js.map +1 -1
- package/dist/cjs/ast/BaseBuilder.js +6 -5
- package/dist/cjs/ast/BaseBuilder.js.map +1 -1
- package/dist/cjs/ast/Builder.js +2 -1
- package/dist/cjs/ast/Builder.js.map +1 -1
- package/dist/cjs/ast/ResourceBuilder.js +2 -1
- package/dist/cjs/ast/ResourceBuilder.js.map +1 -1
- package/dist/cjs/breakscaping/Breakscape.js +240 -0
- package/dist/cjs/breakscaping/Breakscape.js.map +1 -0
- package/dist/cjs/generated/build-info.js +1 -1
- package/dist/cjs/generated/parser/bitmark/bitmark-peggy-parser.js +193 -73
- package/dist/cjs/generated/parser/bitmark/bitmark-peggy-parser.js.map +1 -1
- package/dist/cjs/generated/parser/text/text-peggy-parser.js +9 -9
- package/dist/cjs/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/cjs/generator/json/JsonGenerator.js +136 -126
- package/dist/cjs/generator/json/JsonGenerator.js.map +1 -1
- package/dist/cjs/generator/text/TextGenerator.js +13 -28
- package/dist/cjs/generator/text/TextGenerator.js.map +1 -1
- package/dist/cjs/index.js.map +1 -1
- package/dist/cjs/model/ast/BreakscapedString.js +3 -0
- package/dist/cjs/model/ast/BreakscapedString.js.map +1 -0
- package/dist/cjs/model/ast/StardardString.js +3 -0
- package/dist/cjs/model/ast/StardardString.js.map +1 -0
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js +8 -7
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +17 -16
- package/dist/cjs/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js +2 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/PartnerChainContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/cjs/parser/json/JsonParser.js +98 -99
- package/dist/cjs/parser/json/JsonParser.js.map +1 -1
- package/dist/esm/BitmarkParserGenerator.js +7 -4
- package/dist/esm/BitmarkParserGenerator.js.map +1 -1
- package/dist/esm/ast/BaseBuilder.js +6 -5
- package/dist/esm/ast/BaseBuilder.js.map +1 -1
- package/dist/esm/ast/Builder.js +2 -1
- package/dist/esm/ast/Builder.js.map +1 -1
- package/dist/esm/ast/ResourceBuilder.js +2 -1
- package/dist/esm/ast/ResourceBuilder.js.map +1 -1
- package/dist/esm/breakscaping/Breakscape.js +237 -0
- package/dist/esm/breakscaping/Breakscape.js.map +1 -0
- package/dist/esm/generated/build-info.js +1 -1
- package/dist/esm/generated/parser/bitmark/bitmark-peggy-parser.js +193 -73
- package/dist/esm/generated/parser/bitmark/bitmark-peggy-parser.js.map +1 -1
- package/dist/esm/generated/parser/text/text-peggy-parser.js +9 -8
- package/dist/esm/generated/parser/text/text-peggy-parser.js.map +1 -1
- package/dist/esm/generator/json/JsonGenerator.js +136 -126
- package/dist/esm/generator/json/JsonGenerator.js.map +1 -1
- package/dist/esm/generator/text/TextGenerator.js +13 -26
- package/dist/esm/generator/text/TextGenerator.js.map +1 -1
- package/dist/esm/index.js.map +1 -1
- package/dist/esm/model/ast/BreakscapedString.js +2 -0
- package/dist/esm/model/ast/BreakscapedString.js.map +1 -0
- package/dist/esm/model/ast/StardardString.js +2 -0
- package/dist/esm/model/ast/StardardString.js.map +1 -0
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js +8 -7
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserTypes.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/BitmarkPegParserValidator.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js +17 -16
- package/dist/esm/parser/bitmark/peg/contentProcessors/CardContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js +2 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js +2 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/PartnerChainContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.js.map +1 -1
- package/dist/esm/parser/json/JsonParser.js +98 -99
- package/dist/esm/parser/json/JsonParser.js.map +1 -1
- package/dist/types/BitmarkParserGenerator.d.ts.map +1 -1
- package/dist/types/ast/BaseBuilder.d.ts +4 -3
- package/dist/types/ast/BaseBuilder.d.ts.map +1 -1
- package/dist/types/ast/Builder.d.ts +157 -156
- package/dist/types/ast/Builder.d.ts.map +1 -1
- package/dist/types/ast/ResourceBuilder.d.ts +111 -110
- package/dist/types/ast/ResourceBuilder.d.ts.map +1 -1
- package/dist/types/breakscaping/Breakscape.d.ts +49 -0
- package/dist/types/breakscaping/Breakscape.d.ts.map +1 -0
- package/dist/types/generated/parser/bitmark/bitmark-peggy-parser.d.ts.map +1 -1
- package/dist/types/generated/parser/text/text-peggy-parser.d.ts +0 -1
- package/dist/types/generated/parser/text/text-peggy-parser.d.ts.map +1 -1
- package/dist/types/generator/json/JsonGenerator.d.ts +8 -7
- package/dist/types/generator/json/JsonGenerator.d.ts.map +1 -1
- package/dist/types/generator/text/TextGenerator.d.ts +11 -12
- package/dist/types/generator/text/TextGenerator.d.ts.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/model/ast/BreakscapedString.d.ts +4 -0
- package/dist/types/model/ast/BreakscapedString.d.ts.map +1 -0
- package/dist/types/model/ast/Nodes.d.ts +97 -96
- package/dist/types/model/ast/Nodes.d.ts.map +1 -1
- package/dist/types/model/ast/StardardString.d.ts +4 -0
- package/dist/types/model/ast/StardardString.d.ts.map +1 -0
- package/dist/types/model/json/BitJson.d.ts +1 -1
- package/dist/types/parser/bitmark/peg/BitmarkPegParserProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts +36 -35
- package/dist/types/parser/bitmark/peg/BitmarkPegParserTypes.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts +4 -3
- package/dist/types/parser/bitmark/peg/BitmarkPegParserValidator.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/BookChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/CardContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ClozeTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/DefaultTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ExampleTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ImageSourceChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ItemLeadTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/MarkChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/MarkConfigChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/MarkTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/PartnerChainContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ReferenceTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/ResourceContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts +2 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/TitleTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/bitmark/peg/contentProcessors/TrueFalseTagContentProcessor.d.ts.map +1 -1
- package/dist/types/parser/json/JsonParser.d.ts +9 -0
- package/dist/types/parser/json/JsonParser.d.ts.map +1 -1
- package/package.json +1 -1
|
@@ -0,0 +1,240 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.Breakscape = void 0;
|
|
4
|
+
const StringUtils_1 = require("../utils/StringUtils");
|
|
5
|
+
/**
|
|
6
|
+
* Utility class for breakscaping strings.
|
|
7
|
+
*
|
|
8
|
+
* Breakscaping is the process of escaping certain character sequences in a string so that they are not interpreted as
|
|
9
|
+
* special sequences by the parser.
|
|
10
|
+
*
|
|
11
|
+
* This is different from escaping in that when escaping, single characters tend to be escaped, rather than sequences
|
|
12
|
+
* being broken (split) by a special charater.
|
|
13
|
+
*
|
|
14
|
+
* The special character is ^
|
|
15
|
+
* To include the special character in a text, use ^^ (once), ^^^ (twice), etc.
|
|
16
|
+
*
|
|
17
|
+
* The following sequences can be breakscaped:
|
|
18
|
+
* - inline: == ==> =^=
|
|
19
|
+
* - comment: || ==> |^|
|
|
20
|
+
* - remark: :: ==> :^:
|
|
21
|
+
* - title block: (SOL)[##]#(space) ==> (SOL)[##]#^(space)
|
|
22
|
+
* - new block: (SOL)|(WS EOL) ==> (SOL)|^(WS EOL)
|
|
23
|
+
* - code block: (SOL)|code(:type) ==> (SOL)|^code(:type)
|
|
24
|
+
* - image block: (SOL)|image:(url) ==> (SOL)|^image:(url)
|
|
25
|
+
* - bullet list: (SOL)•(space) ==> (SOL)•^(space)
|
|
26
|
+
* - ordered list: (SOL)•1(space) ==> (SOL)•^1(space)
|
|
27
|
+
* - tag list +: (SOL)•+(space) ==> (SOL)•^+(space)
|
|
28
|
+
* - tag list -: (SOL)•-(space) ==> (SOL)•^-(space)
|
|
29
|
+
* - bold: ** ==> *^*
|
|
30
|
+
* - light: `` ==> `^`
|
|
31
|
+
* - italic: __ ==> _^_
|
|
32
|
+
* - highlight: !! ==> !^!
|
|
33
|
+
* - start of bit: [. ==> [^.
|
|
34
|
+
* - start of property: [@ ==> [^@
|
|
35
|
+
* - start of title: [# ==> [^#
|
|
36
|
+
* - start of anchor: [▼ ==> [^▼
|
|
37
|
+
* - start of reference: [► ==> [^►
|
|
38
|
+
* - start of item/lead: [% ==> [^%
|
|
39
|
+
* - start of instruction: [! ==> [^!
|
|
40
|
+
* - start of hint: [? ==> [^?
|
|
41
|
+
* - start of true statement: [+ ==> [^+
|
|
42
|
+
* - start of false statement: [- ==> [^-
|
|
43
|
+
* - start of sample solution: [$ ==> [^$
|
|
44
|
+
* - start of gap: [_ ==> [^_
|
|
45
|
+
* - start of mark: [= ==> [^=
|
|
46
|
+
* - start of resource: [& ==> [^&
|
|
47
|
+
* - end of tag: ] ==> ^]
|
|
48
|
+
*
|
|
49
|
+
*
|
|
50
|
+
* The following are breakscaped with ^ in between. Just add more ^s to increase the number of ^ string:
|
|
51
|
+
* - inline: =^= ==> =^^=
|
|
52
|
+
* - comment: |^| ==> |^^|
|
|
53
|
+
* - remark: :^: ==> :^^:
|
|
54
|
+
* - title block: (SOL)[##]#^(space) ==> (SOL)[##]#^^(space)
|
|
55
|
+
* - new block: (SOL)|^(WS EOL) ==> (SOL)|^^(WS EOL)
|
|
56
|
+
* - code block: (SOL)|^code(:type) ==> (SOL)|^^code(:type)
|
|
57
|
+
* - image block: (SOL)|^image:(url) ==> (SOL)|^^image:(url)
|
|
58
|
+
* - bullet list: (SOL)•^(space) ==> (SOL)•^^(space)
|
|
59
|
+
* - ordered list: (SOL)•^1(space) ==> (SOL)•^^1(space)
|
|
60
|
+
* - tag list +: (SOL)•^+(space) ==> (SOL)•^^+(space)
|
|
61
|
+
* - tag list -: (SOL)•^-(space) ==> (SOL)•^^-(space)
|
|
62
|
+
* - bold: *^* ==> *^^*
|
|
63
|
+
* - light: `^` ==> `^^`
|
|
64
|
+
* - italic: _^_ ==> _^^_
|
|
65
|
+
* - highlight: !^! ==> !^^!
|
|
66
|
+
* - start of bit: [^. ==> [^^.
|
|
67
|
+
* - start of property: [^@ ==> [^^@
|
|
68
|
+
* - start of title: [^# ==> [^^#
|
|
69
|
+
* - start of anchor: [^▼ ==> [^^▼
|
|
70
|
+
* - start of reference: [^► ==> [^^►
|
|
71
|
+
* - start of item/lead: [^% ==> [^^%
|
|
72
|
+
* - start of instruction: [^! ==> [^^!
|
|
73
|
+
* - start of hint: [^? ==> [^^?
|
|
74
|
+
* - start of true statement: [^+ ==> [^^+
|
|
75
|
+
* - start of false statement: [^- ==> [^^-
|
|
76
|
+
* - start of sample solution: [^$ ==> [^^$
|
|
77
|
+
* - start of gap: [^_ ==> [^^_
|
|
78
|
+
* - start of mark: [^= ==> [^^=
|
|
79
|
+
* - start of resource: [^& ==> [^^&
|
|
80
|
+
* - end of tag: ^] ==> ^^]
|
|
81
|
+
*/
|
|
82
|
+
//
|
|
83
|
+
// Breakscaping
|
|
84
|
+
//
|
|
85
|
+
const REGEX_MARKS = /([*`_!|:=])([\^]*)\1/;
|
|
86
|
+
const REGEX_BLOCKS = /^(\|)([\^]*)(code[\s]*|code:|image:|[\s]*$)/;
|
|
87
|
+
const REGEX_TITLE_BLOCKS = /^([#]{1,3})([\^]*)([^\S\r\n]+)/;
|
|
88
|
+
const REGEX_LIST_BLOCKS = /^(•)([\^]*)(1|\+|-|)([^\S\r\n]+)/;
|
|
89
|
+
const REGEX_START_OF_TAG = /(\[)([\^]*)([.@#▼►%!?+\-$_=&])/;
|
|
90
|
+
const REGEX_END_OF_TAG = /([\^]*)(])/;
|
|
91
|
+
const BREAKSCAPE_REGEX_SOURCE = `${REGEX_MARKS.source}|${REGEX_BLOCKS.source}|${REGEX_TITLE_BLOCKS.source}|${REGEX_LIST_BLOCKS.source}|${REGEX_START_OF_TAG.source}|${REGEX_END_OF_TAG.source}`;
|
|
92
|
+
const UNBREAKSCAPE_REGEX_SOURCE = BREAKSCAPE_REGEX_SOURCE.replace(/(\(\[\\\^\]\*\))/g, '\\^$1'); // Add ^ into the regex
|
|
93
|
+
// Regex groups in BODY (bitmark++):
|
|
94
|
+
// 1: start of MARK
|
|
95
|
+
// 2: ^ in MARK
|
|
96
|
+
// 3: start of BLOCK
|
|
97
|
+
// 4: ^ in BLOCK
|
|
98
|
+
// 5: end of BLOCK
|
|
99
|
+
// 6: start of TITLE_BLOCK
|
|
100
|
+
// 7: ^ in TITLE_BLOCK
|
|
101
|
+
// 8: end of TITLE_BLOCK
|
|
102
|
+
// 9: start of LIST_BLOCK
|
|
103
|
+
// 10: ^ in LIST_BLOCK
|
|
104
|
+
// 11: end of LIST_BLOCK part 1
|
|
105
|
+
// 12: end of LIST_BLOCK part 2
|
|
106
|
+
// 13: start of START_OF_TAG block
|
|
107
|
+
// 14: ^ in START_OF_TAG block
|
|
108
|
+
// 15: end of START_OF_TAG block
|
|
109
|
+
// 16: ^ in END_OF_TAG block
|
|
110
|
+
// 17: end of END_OF_TAG block
|
|
111
|
+
const BREAKSCAPE_REGEX = new RegExp(BREAKSCAPE_REGEX_SOURCE, 'gm');
|
|
112
|
+
const BREAKSCAPE_REGEX_REPLACER = '$1$3$6$9$13^$2$1$4$5$7$8$10$11$12$14$15$16$17';
|
|
113
|
+
const UNBREAKSCAPE_REGEX = new RegExp(UNBREAKSCAPE_REGEX_SOURCE, 'gm');
|
|
114
|
+
const UNBREAKSCAPE_REGEX_REPLACER = BREAKSCAPE_REGEX_REPLACER.replace(/\^/g, ''); // Remove ^ from the regex replacer
|
|
115
|
+
// Regex explanation:
|
|
116
|
+
// - match a single | or • or # character at the start of a line and capture in group 1
|
|
117
|
+
// This will capture all new block characters within the code text.
|
|
118
|
+
// Replace with group 1, ^
|
|
119
|
+
const BREAKSCAPE_CODE_REGEX = new RegExp('^(\\||•|#)', 'gm');
|
|
120
|
+
const BREAKSCAPE_CODE_REGEX_REPLACER = '$1^';
|
|
121
|
+
class Breakscape {
|
|
122
|
+
constructor() {
|
|
123
|
+
this.EMPTY_STRING = '';
|
|
124
|
+
}
|
|
125
|
+
/**
|
|
126
|
+
* Breakscape a string or an array of strings.
|
|
127
|
+
* If the input is an array, a new array will be returned.
|
|
128
|
+
*
|
|
129
|
+
* @param val input value
|
|
130
|
+
* @param options options for breakscaping
|
|
131
|
+
* @param modifyArray
|
|
132
|
+
* @returns the input value with any strings breakscaped.
|
|
133
|
+
*/
|
|
134
|
+
breakscape(val, options) {
|
|
135
|
+
if (val == null)
|
|
136
|
+
return val;
|
|
137
|
+
const opts = Object.assign({}, options);
|
|
138
|
+
const breakscapeStr = (str) => {
|
|
139
|
+
if (!str)
|
|
140
|
+
return str;
|
|
141
|
+
str = str.replace(BREAKSCAPE_REGEX, BREAKSCAPE_REGEX_REPLACER);
|
|
142
|
+
return str;
|
|
143
|
+
};
|
|
144
|
+
if (Array.isArray(val)) {
|
|
145
|
+
const newVal = opts.modifyArray ? val : [val.length];
|
|
146
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
147
|
+
const v = val[i];
|
|
148
|
+
if (StringUtils_1.StringUtils.isString(v)) {
|
|
149
|
+
newVal[i] = breakscapeStr(v);
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
val = newVal;
|
|
153
|
+
}
|
|
154
|
+
else if (StringUtils_1.StringUtils.isString(val)) {
|
|
155
|
+
val = breakscapeStr(val);
|
|
156
|
+
}
|
|
157
|
+
return val;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Unbreakscape a string or an array of strings.
|
|
161
|
+
* If the input is an array, a new array will be returned.
|
|
162
|
+
*
|
|
163
|
+
* @param val input value
|
|
164
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
165
|
+
* @returns the input value with any strings unbreakscaped.
|
|
166
|
+
*/
|
|
167
|
+
unbreakscape(val, options) {
|
|
168
|
+
if (val == null)
|
|
169
|
+
return val;
|
|
170
|
+
const opts = Object.assign({}, options);
|
|
171
|
+
const unbreakscapeStr = (str) => {
|
|
172
|
+
if (!str)
|
|
173
|
+
return str;
|
|
174
|
+
str = str.replace(UNBREAKSCAPE_REGEX, UNBREAKSCAPE_REGEX_REPLACER);
|
|
175
|
+
return str;
|
|
176
|
+
};
|
|
177
|
+
if (Array.isArray(val)) {
|
|
178
|
+
const newVal = opts.modifyArray ? val : [];
|
|
179
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
180
|
+
const v = val[i];
|
|
181
|
+
if (StringUtils_1.StringUtils.isString(v)) {
|
|
182
|
+
newVal[i] = unbreakscapeStr(v);
|
|
183
|
+
}
|
|
184
|
+
else {
|
|
185
|
+
newVal[i] = v;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
val = newVal;
|
|
189
|
+
}
|
|
190
|
+
else if (StringUtils_1.StringUtils.isString(val)) {
|
|
191
|
+
val = unbreakscapeStr(val);
|
|
192
|
+
}
|
|
193
|
+
return val;
|
|
194
|
+
}
|
|
195
|
+
/**
|
|
196
|
+
* Breakscape a code string or an array of code strings.
|
|
197
|
+
* If the input is an array, a new array will be returned.
|
|
198
|
+
*
|
|
199
|
+
* @param val input value
|
|
200
|
+
* @param modifyArray if true, the original array will be modified rather than a copy being made
|
|
201
|
+
* @returns the input value with any strings breakscaped
|
|
202
|
+
*/
|
|
203
|
+
breakscapeCode(val, options) {
|
|
204
|
+
if (val == null)
|
|
205
|
+
return val;
|
|
206
|
+
const opts = Object.assign({}, options);
|
|
207
|
+
const breakscapeStr = (str) => {
|
|
208
|
+
if (!str)
|
|
209
|
+
return str;
|
|
210
|
+
return str.replace(BREAKSCAPE_CODE_REGEX, BREAKSCAPE_CODE_REGEX_REPLACER);
|
|
211
|
+
};
|
|
212
|
+
if (Array.isArray(val)) {
|
|
213
|
+
const newVal = opts.modifyArray ? val : [val.length];
|
|
214
|
+
for (let i = 0, len = val.length; i < len; i++) {
|
|
215
|
+
const v = val[i];
|
|
216
|
+
if (StringUtils_1.StringUtils.isString(v)) {
|
|
217
|
+
val[i] = breakscapeStr(v);
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
val = newVal;
|
|
221
|
+
}
|
|
222
|
+
else if (StringUtils_1.StringUtils.isString(val)) {
|
|
223
|
+
val = breakscapeStr(val);
|
|
224
|
+
}
|
|
225
|
+
return val;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Concatenate two breakscaped strings.
|
|
229
|
+
*
|
|
230
|
+
* @param s1 first string
|
|
231
|
+
* @param s2 second string
|
|
232
|
+
* @returns the concatenated string
|
|
233
|
+
*/
|
|
234
|
+
concatenate(s1, s2) {
|
|
235
|
+
return (s1 + s2);
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const instance = new Breakscape();
|
|
239
|
+
exports.Breakscape = instance;
|
|
240
|
+
//# sourceMappingURL=Breakscape.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Breakscape.js","sourceRoot":"","sources":["../../../src/breakscaping/Breakscape.ts"],"names":[],"mappings":";;;AACA,sDAAmD;AAEn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@ exports.buildInfo = void 0;
|
|
|
5
5
|
/* eslint-disable */
|
|
6
6
|
exports.buildInfo = {
|
|
7
7
|
"name": "@gmb/bitmark-parser-generator",
|
|
8
|
-
"version": "1.4.
|
|
8
|
+
"version": "1.4.9",
|
|
9
9
|
"author": "Get More Brain Ltd",
|
|
10
10
|
"license": "ISC",
|
|
11
11
|
"description": "A bitmark parser and generator using Peggy.js"
|