bare-script 2.2.12 → 2.2.14
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/lib/bareDoc.js +39 -26
- package/lib/library.js +21 -17
- package/package.json +1 -1
package/lib/bareDoc.js
CHANGED
|
@@ -121,34 +121,46 @@ export function parseBareDoc(files) {
|
|
|
121
121
|
func = {'name': textTrim};
|
|
122
122
|
funcs[textTrim] = func;
|
|
123
123
|
}
|
|
124
|
-
} else {
|
|
125
|
-
// arg keyword?
|
|
126
|
-
const matchArg = line.match(rArg);
|
|
127
|
-
if (matchArg !== null) {
|
|
128
|
-
const {name, text} = matchArg.groups;
|
|
129
|
-
const textTrim = text.trim();
|
|
130
|
-
|
|
131
|
-
// Keyword used outside of function?
|
|
132
|
-
if (func === null) {
|
|
133
|
-
errors.push(`${file}:${ixLine + 1}: Function argument "${name}" outside function`);
|
|
134
|
-
continue;
|
|
135
|
-
}
|
|
136
124
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
// arg keyword?
|
|
129
|
+
const matchArg = line.match(rArg);
|
|
130
|
+
if (matchArg !== null) {
|
|
131
|
+
const {name, text} = matchArg.groups;
|
|
132
|
+
const textTrim = text.trim();
|
|
133
|
+
|
|
134
|
+
// Keyword used outside of function?
|
|
135
|
+
if (func === null) {
|
|
136
|
+
errors.push(`${file}:${ixLine + 1}: Function argument "${name}" outside function`);
|
|
137
|
+
continue;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
// Add the function arg documentation line - don't add leading blank lines
|
|
141
|
+
let args = func.args ?? null;
|
|
142
|
+
let arg = (args !== null ? args.find((argFind) => argFind.name === name) : null) ?? null;
|
|
143
|
+
if (arg !== null || textTrim !== '') {
|
|
144
|
+
if (args === null) {
|
|
145
|
+
args = [];
|
|
146
|
+
func.args = args;
|
|
150
147
|
}
|
|
148
|
+
if (arg === null) {
|
|
149
|
+
arg = {'name': name, 'doc': []};
|
|
150
|
+
args.push(arg);
|
|
151
|
+
}
|
|
152
|
+
arg.doc.push(text);
|
|
151
153
|
}
|
|
154
|
+
|
|
155
|
+
continue;
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
// Unknown documentation comment?
|
|
159
|
+
const matchUnknown = line.match(rUnknown);
|
|
160
|
+
if (matchUnknown !== null) {
|
|
161
|
+
const {unknown} = matchUnknown.groups;
|
|
162
|
+
errors.push(`${file}:${ixLine + 1}: Invalid documentation comment "${unknown}"`);
|
|
163
|
+
continue;
|
|
152
164
|
}
|
|
153
165
|
}
|
|
154
166
|
}
|
|
@@ -185,5 +197,6 @@ export function parseBareDoc(files) {
|
|
|
185
197
|
|
|
186
198
|
// Library documentation regular expressions
|
|
187
199
|
const rKey = /^\s*(?:\/\/|#)\s*\$(?<key>function|group|doc|return):\s?(?<text>.*)$/;
|
|
188
|
-
const rArg = /^\s*(?:\/\/|#)\s*\$arg\s+(?<name>[A-Za-z_][A-Za-z0-9_]*):\s?(?<text>.*)$/;
|
|
200
|
+
const rArg = /^\s*(?:\/\/|#)\s*\$arg\s+(?<name>[A-Za-z_][A-Za-z0-9_]*(?:\.\.\.)?):\s?(?<text>.*)$/;
|
|
201
|
+
const rUnknown = /^\s*(?:\/\/|#)\s*\$(?<unknown>[^:]+):/;
|
|
189
202
|
const rSplit = /\r?\n/;
|
package/lib/library.js
CHANGED
|
@@ -89,9 +89,9 @@ export const scriptFunctions = {
|
|
|
89
89
|
// $function: arrayNew
|
|
90
90
|
// $group: Array
|
|
91
91
|
// $doc: Create a new array
|
|
92
|
-
// $arg
|
|
92
|
+
// $arg values...: The new array's values
|
|
93
93
|
// $return: The new array
|
|
94
|
-
'arrayNew': (
|
|
94
|
+
'arrayNew': (values) => values,
|
|
95
95
|
|
|
96
96
|
// $function: arrayNewSize
|
|
97
97
|
// $group: Array
|
|
@@ -112,7 +112,7 @@ export const scriptFunctions = {
|
|
|
112
112
|
// $group: Array
|
|
113
113
|
// $doc: Add one or more values to the end of the array
|
|
114
114
|
// $arg array: The array
|
|
115
|
-
// $arg values
|
|
115
|
+
// $arg values...: The values to add to the end of the array
|
|
116
116
|
// $return: The array
|
|
117
117
|
'arrayPush': ([array, ...values]) => {
|
|
118
118
|
if (Array.isArray(array)) {
|
|
@@ -213,7 +213,7 @@ export const scriptFunctions = {
|
|
|
213
213
|
// $function: dataParseCSV
|
|
214
214
|
// $group: Data
|
|
215
215
|
// $doc: Parse CSV text to a data array
|
|
216
|
-
// $arg text
|
|
216
|
+
// $arg text...: The CSV text
|
|
217
217
|
// $return: The data array
|
|
218
218
|
'dataParseCSV': (text) => {
|
|
219
219
|
const data = parseCSV(text);
|
|
@@ -278,9 +278,13 @@ export const scriptFunctions = {
|
|
|
278
278
|
'datetimeISOFormat': ([datetime, isDate = false]) => {
|
|
279
279
|
let result = null;
|
|
280
280
|
if (datetime instanceof Date) {
|
|
281
|
-
result = datetime.toISOString();
|
|
282
281
|
if (isDate) {
|
|
283
|
-
|
|
282
|
+
const year = datetime.getFullYear();
|
|
283
|
+
const month = datetime.getMonth() + 1;
|
|
284
|
+
const day = datetime.getDate();
|
|
285
|
+
result = `${year}-${month < 10 ? '0' : ''}${month}-${day < 10 ? '0' : ''}${day}`;
|
|
286
|
+
} else {
|
|
287
|
+
result = datetime.toISOString();
|
|
284
288
|
}
|
|
285
289
|
}
|
|
286
290
|
return result;
|
|
@@ -477,15 +481,15 @@ export const scriptFunctions = {
|
|
|
477
481
|
|
|
478
482
|
// $function: mathMax
|
|
479
483
|
// $group: Math
|
|
480
|
-
// $doc: Compute the maximum value
|
|
481
|
-
// $arg values
|
|
484
|
+
// $doc: Compute the maximum value
|
|
485
|
+
// $arg values...: The values
|
|
482
486
|
// $return: The maximum value
|
|
483
487
|
'mathMax': (values) => Math.max(...values),
|
|
484
488
|
|
|
485
489
|
// $function: mathMin
|
|
486
490
|
// $group: Math
|
|
487
|
-
// $doc: Compute the minimum value
|
|
488
|
-
// $arg values
|
|
491
|
+
// $doc: Compute the minimum value
|
|
492
|
+
// $arg values...: The values
|
|
489
493
|
// $return: The minimum value
|
|
490
494
|
'mathMin': (values) => Math.min(...values),
|
|
491
495
|
|
|
@@ -644,7 +648,7 @@ export const scriptFunctions = {
|
|
|
644
648
|
// $function: objectNew
|
|
645
649
|
// $group: Object
|
|
646
650
|
// $doc: Create a new object
|
|
647
|
-
// $arg keyValues
|
|
651
|
+
// $arg keyValues...: The object's initial key and value pairs
|
|
648
652
|
// $return: The new object
|
|
649
653
|
'objectNew': (keyValues) => {
|
|
650
654
|
const object = {};
|
|
@@ -725,8 +729,8 @@ export const scriptFunctions = {
|
|
|
725
729
|
// $function: schemaParse
|
|
726
730
|
// $group: Schema
|
|
727
731
|
// $doc: Parse the [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/) text
|
|
728
|
-
// $arg lines
|
|
729
|
-
// $arg lines
|
|
732
|
+
// $arg lines...: The [Schema Markdown](https://craigahobbs.github.io/schema-markdown-js/language/)
|
|
733
|
+
// $arg lines...: text lines (may contain nested arrays of un-split lines)
|
|
730
734
|
// $return: The schema's [type model](https://craigahobbs.github.io/schema-markdown-doc/doc/#var.vName='Types')
|
|
731
735
|
'schemaParse': (lines) => parseSchemaMarkdown(lines),
|
|
732
736
|
|
|
@@ -785,9 +789,9 @@ export const scriptFunctions = {
|
|
|
785
789
|
|
|
786
790
|
// $function: stringFromCharCode
|
|
787
791
|
// $group: String
|
|
788
|
-
// $doc: Create a string from
|
|
789
|
-
// $arg charCodes
|
|
790
|
-
// $return: The
|
|
792
|
+
// $doc: Create a string of characters from character codes
|
|
793
|
+
// $arg charCodes...: The character codes
|
|
794
|
+
// $return: The string of characters
|
|
791
795
|
'stringFromCharCode': (charCodes) => String.fromCharCode(...charCodes),
|
|
792
796
|
|
|
793
797
|
// $function: stringIndexOf
|
|
@@ -987,7 +991,7 @@ export const scriptFunctions = {
|
|
|
987
991
|
// $doc: Return a new function which behaves like "func" called with "args".
|
|
988
992
|
// $doc: If additional arguments are passed to the returned function, they are appended to "args".
|
|
989
993
|
// $arg func: The function
|
|
990
|
-
// $arg args
|
|
994
|
+
// $arg args...: The function arguments
|
|
991
995
|
// $return: The new function called with "args"
|
|
992
996
|
'systemPartial': ([func, ...args]) => (argsExtra, options) => func([...args, ...argsExtra], options),
|
|
993
997
|
|